I work with metric and imperial all the time and it's not really been an issue. However I need to temporarily convert a parameter to run through a calculator. I read the documentation:
https://help.autodesk.com/view/INVNTOR/2022/ENU/?guid=UnitsOfMeasure_ConvertUnits
and I still can't get it. I wrote this:
Hex_AF = UnitsOfMeasure.ConvertUnits(Hex_AF, "in", "mm") As Double
and it says:
Error on Line 1 : 'UnitsOfMeasure' is not declared. It may be inaccessible due to its protection level.
Error on Line 1 : End of statement expected.
I feel like a followed it exactly, where am I going wrong?
Thanks,
Harvey
Solved! Go to Solution.
Solved by Andrii_Humeniuk. Go to Solution.
Solved by A.Acheson. Go to Solution.
The units of measure object isn't accessed correctly. If you scroll to the bottom of the help page you can see all the documents you can access it from and even the application. So declare the application/ document and then declare the unit of measure object.
Accessed From
Application.UnitsOfMeasure, ApprenticeServerDocument.UnitsOfMeasure, ApprenticeServerDrawingDocument.UnitsOfMeasure, AssemblyDocument.UnitsOfMeasure, Document.UnitsOfMeasure, DrawingDocument.UnitsOfMeasure, InventorServer.UnitsOfMeasure, InventorServerObject.UnitsOfMeasure, PartDocument.UnitsOfMeasure, PresentationDocument.UnitsOfMeasure
Something like
Dim uom As UnitsOfMeasure = ThisApplication.UnitsOfMeasure
Dim Hex_AF As Double = uom.ConvertUnits(Hex_AF, "in", "mm")
Hi @harvey_craig2RCUH .
Mr. @A.Acheson has overtaken me, but I will still present my option for converting the units of measurement of the parameter:
Dim oPDoc As PartDocument = TryCast(ThisDoc.Document, PartDocument)
If oPDoc Is Nothing Then Exit Sub
Dim oUsParams As UserParameters = oPDoc.ComponentDefinition.Parameters.UserParameters
Dim oParam As UserParameter = oUsParams("Hex_AF")
If oParam.Units = "in" Then
oParam.Units = "mm"
oParam.Expression = oPDoc.UnitsOfMeasure.ConvertUnits(oParam.Value, "cm", "mm")
Else
oParam.Units = "in"
oParam.Expression = oPDoc.UnitsOfMeasure.ConvertUnits(oParam.Value, "cm", "in")
End If
oPDoc.Update()
Andrii Humeniuk - CAD Coordinator, Autodesk Certified Instructor
LinkedIn | My free Inventor Addin | My Repositories
Did you find this reply helpful ? If so please use the Accept as Solution/Like.
Can't find what you're looking for? Ask the community or share your knowledge.