| | | Gut zu wissen: Hilfreiche Tipps und Tricks aus der Praxis prägnant, und auf den Punkt gebracht für Autodesk Produkte |
Autor
|
Thema: UnitsOfMeasure? (1107 mal gelesen)
|
Melanie Mitglied
Beiträge: 30 Registriert: 14.10.2002
|
erstellt am: 12. Sep. 2003 11:09 <-- editieren / zitieren --> Unities abgeben:
Hallo, ich habe Probleme beim Auslesen der Blechdicke. Die Einheit stimmt in Inventor (cm) nicht überein mit der ausgelesenen Einheit (mm). Kann mir da jemand weiter helfen? Habe auch den Code mitgeliefert. Der Pfeil markiert die Stelle, wo ich das Problem entdeckt habe.
Code:
Public Function GetSheetMetalThickness() As Double GetSheetMetalThickness = 0 On Error GoTo ERRORHANDLER If (oInventor Is Nothing) Then Exit Function End If ' Make sure the active document is a part document If Not (oInventor.ActiveDocument.Type = kPartDocumentObject) Then Exit Function End If ' Set a reference to the sheet metal document. Dim oPartDoc As PartDocument Set oPartDoc = oInventor.ActiveDocument ' Make sure the document is a sheet metal document. If oPartDoc.SubType <> "{9C464203-9BAE-11D3-8BAD-0060B0CE6BB4}" Then SetSheetMetalThickness = Value Exit Function End If ' Get the sheet metal component definition. Because this is a part document whose ' sub type is sheet metal, the document will return a SheetMetalComponentDefinition ' instead of a PartComponentDefinition. Dim oSheetMetalCompDef As SheetMetalComponentDefinition Set oSheetMetalCompDef = oPartDoc.ComponentDefinition ' Get a reference to the parameter controlling the thickness. You can't always ' rely on the name because the name will change in different languages and the user ' can edit the name in the Parameters dialog. Dim oThicknessParam As Parameter Set oThicknessParam = oSheetMetalCompDef.ActiveSheetMetalStyle.Thickness ' get the value of the parameter. Dim UnitsOfMeasure As UnitsOfMeasure Set UnitsOfMeasure = oPartDoc.UnitsOfMeasure Dim ValueStr As String ' Display the Name Debug.Print " Name:" & oThicknessParam.Name ' Display the Value Debug.Print " Value: " & oThicknessParam.Value ' Display the units ---> Debug.Print " Units: " & oThicknessParam.Units ' Falsch! ValueStr = oThicknessParam.Value & " " & oThicknessParam.Units GetSheetMetalThickness = UnitsOfMeasure.GetValueFromExpression(ValueStr, kMillimeterLengthUnits) Exit Function ERRORHANDLER: Err.Clear GetSheetMetalThickness = 0 End Function
gruß Melanie Eine Antwort auf diesen Beitrag verfassen (mit Zitat/Zitat des Beitrags) IP |
daywa1k3r Moderator Softwareentwickler
Beiträge: 3497 Registriert: 01.08.2002 Alienware m17x, Win7, Inventor2012
|
erstellt am: 12. Sep. 2003 11:33 <-- editieren / zitieren --> Unities abgeben: Nur für Melanie
Hi, naja, er rechnet beim Blech wahrscheinlich in "mm". Die Eigenschaft Units ist aber Read/Write, so kannst du sie auf "cm" setzen, falls du ein Problem damit hast. ------------------ Grüße daywa1k3r Eine Antwort auf diesen Beitrag verfassen (mit Zitat/Zitat des Beitrags) IP |
Melanie Mitglied
Beiträge: 30 Registriert: 14.10.2002
|
erstellt am: 12. Sep. 2003 14:00 <-- editieren / zitieren --> Unities abgeben:
hi daywa1k3r, Fehler gefunden! Es klappt, falls es dich interessiert hier die Lösung: [Code] Public Function GetSheetMetalThickness(ByVal oDocument As Variant) As String GetSheetMetalThickness = "" On Error GoTo ERRORHANDLER If (oDocument Is Nothing) Then Exit Function End If ' Set a reference to the sheet metal document. Dim oPartDoc As PartDocument Set oPartDoc = oDocument ' Make sure the document is a sheet metal document. If oPartDoc.SubType <> "{9C464203-9BAE-11D3-8BAD-0060B0CE6BB4}" Then Exit Function End If ' Get the sheet metal component definition. Because this is a part document whose ' sub type is sheet metal, the document will return a SheetMetalComponentDefinition ' instead of a PartComponentDefinition. Dim oSheetMetalCompDef As SheetMetalComponentDefinition Set oSheetMetalCompDef = oPartDoc.ComponentDefinition ' Get a reference to the parameter controlling the thickness. You can't always ' rely on the name because the name will change in different languages and the user ' can edit the name in the Parameters dialog. Dim oThicknessParam As Parameter Set oThicknessParam = oSheetMetalCompDef.ActiveSheetMetalStyle.Thickness ' get the value of the parameter. Dim UnitsOfMeasure As UnitsOfMeasure Set UnitsOfMeasure = oPartDoc.UnitsOfMeasure Dim ValueStr As String ' Display the Name Debug.Print " Name:" & oThicknessParam.Name ' Display the Value Debug.Print " Value: " & oThicknessParam.Value ' Display the units ' Debug.Print " Units: " & oThicknessParam.Units ' Falsch! Debug.Print " Units: " & UnitsOfMeasure.GetStringFromType(kDatabaseLengthUnits) ValueStr = oThicknessParam.Value & " " & UnitsOfMeasure.GetStringFromType(kDatabaseLengthUnits) GetSheetMetalThickness = UnitsOfMeasure.GetStringFromValue(oThicknessParam.Value, kMillimeterLengthUnits) Exit Function ERRORHANDLER: Debug.Print Err.Description Err.Clear GetSheetMetalThickness = "" End Function [\Code] schönes Wochenende Melanie Eine Antwort auf diesen Beitrag verfassen (mit Zitat/Zitat des Beitrags) IP |
| Anzeige.:
Anzeige: (Infos zum Werbeplatz >>)
|