Community
Inventor Programming - iLogic, Macros, AddIns & Apprentice
Inventor iLogic, Macros, AddIns & Apprentice Forum. Share your knowledge, ask questions, and explore popular Inventor topics related to programming, creating add-ins, macros, working with the API or creating iLogic tools.
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Converting individual units

2 REPLIES 2
SOLVED
Reply
Message 1 of 3
harvey_craig2RCUH
707 Views, 2 Replies

Converting individual units

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

2 REPLIES 2
Message 2 of 3

Hi @harvey_craig2RCUH 

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.UnitsOfMeasureApprenticeServerDocument.UnitsOfMeasureApprenticeServerDrawingDocument.UnitsOfMeasureAssemblyDocument.UnitsOfMeasureDocument.UnitsOfMeasureDrawingDocument.UnitsOfMeasureInventorServer.UnitsOfMeasureInventorServerObject.UnitsOfMeasurePartDocument.UnitsOfMeasurePresentationDocument.UnitsOfMeasure

 

Something like

Dim uom As UnitsOfMeasure = ThisApplication.UnitsOfMeasure
Dim Hex_AF
As Double = uom.ConvertUnits(Hex_AF, "in", "mm")
If this solved a problem, please click (accept) as solution.‌‌‌‌
Or if this helped you, please, click (like)‌‌
Regards
Alan
Message 3 of 3

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.

EESignature

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

Autodesk Design & Make Report