How to write-out parameters in correct units in iLogic:

How to write-out parameters in correct units in iLogic:

JamesNordgren
Advocate Advocate
836 Views
1 Reply
Message 1 of 2

How to write-out parameters in correct units in iLogic:

JamesNordgren
Advocate
Advocate

Hi all,

I have this little iLogic snippet that writes out the name and value of all parameters in active document.

doc = ThisDoc.Document
params = doc.ComponentDefinition.Parameters
names = New List(Of String)
values = New List(Of String)
For Each param In params
	If Len(param.Name)>4 Then
		names.Add(param.Name)
		values.Add(param.Value.ToString)
	Else
	End If
Next
MultiValue.List("ParamsList") = names
MultiValue.List("ParamsValues") = values

GoExcel.CellValues("COVER.DEFAULT.PARAMS.xlsx", "Sheet1", "A2", "A400") = MultiValue.List("ParamsList")
GoExcel.CellValues("COVER.DEFAULT.PARAMS.xlsx", "Sheet1", "B2", "B400") = MultiValue.List("ParamsValues")
GoExcel.Save
GoExcel.Close

 The problem is it ignores the parameter's units and assumes cm for length and rad for angular.

I need another nested IF - Then that says:

 

IF param.Values.'UnitType' is "in"  THEN

     param.Value = param.Value/2.54

Else If   param.Values.'UnitType' is "deg"  THEN

     param.Value = param.Value*360/2/3.14159

End If

 

I just do not know the syntax or proper method.

 

Any suggestions?  My bet is someone already has it canned and ready to go Smiley Happy

Thanks

0 Likes
Accepted solutions (1)
837 Views
1 Reply
Reply (1)
Message 2 of 2

ekinsb
Alumni
Alumni
Accepted solution

The API provides a lot of help when dealing with values in various units through the UnitsOfMeasure object.  Below is a snippet of code that shows using it.  It's getting the UnitsOfMeasure object from the document so that it's aware of the unit settings of the document.  It then uses the GetStringFromValue method where the first argument is the value and the second describes the units of the value.  In this case, for the first one I'm telling it to use whatever the default length units are for the document and the second one is the same but for angle units.  The return from GetStringFromValue is a String, which I'm just printing out in this sample.

 

Dim uom As UnitsOfMeasure
Set uom = doc.UnitsOfMeasure
    
Debug.Print uom.GetStringFromValue(5, kDefaultDisplayLengthUnits)
Debug.Print uom.GetStringFromValue(3.14, kDefaultDisplayAngleUnits)

 


Brian Ekins
Inventor and Fusion 360 API Expert
Mod the Machine blog
0 Likes