I'm running into more headaches with managing Parameter values thru iLogic, Autodesk suggested I post this to the Forums since they didn't really have a solution on this they thought someone in the community might.
I'm attempting to use a Parameter to store a user input value, with the U/M in FT (to match the supplied value from an Engineers worksheet). The test value used here is 40.00520833 ft [40'-0 1/16"] with an expected final result value saved to the Parameter as 40.00521 ft.
I want iLogic to take that Parameter value, round it to the nearest 1/16th inch, utilize that value within the iLogic for other tasks, and finally save the modified number back in FT to the Parameter rounded to 5 digits to properly hand off through a BOM Export for use with other existing downstream automation processes that require this format.
So mathematically the process is to take the Parameter value, convert to inches, round to the nearest 16th, convert back to FT and round to 5 places for final storage.
I've created Parameter named "Length", applied this logic, and get several unexpected results. Test code and results I've performed thus far are:
Parameter("Length") = Round(Round(Round(Length * 12 * 16) / 16 / 12 * 100000) / 100000, 5)
MsgBox(Length)
'Parameter("Length") = Round(Round(Length * 12 * 16) / 16 / 12, 5) 'This option loses the fractional result
'Dim oLength As Double = Parameter("Length") 'this variant results in the same as line 1 above
'oLength = Round(Round(oLength / 1 ft * 12 * 16) / 16 / 12 * 1 ft, 5)
'MsgBox(oLength)
'Parameter("Length") = oLength
I've added a text box to display the value of the parameter while utilized within iLogic. Expecting that value to be the formatted result in FT, I am instead receiving the value in inches whether I access the Parameter or use a Variable approach. I don't know if the display isn't keeping pace with the speed of the iLogic routine or if in fact the number is not as expected and any routines I add to utilize the value will be the incorrect U/M and thus give me headaches when processing that value through any additional code for model utilization.
The final result of saving the converted value is also not as expected as the rounding method appears to be completely ignored. The value being stored in the Equation field goes to the nth decimal place instead of the desired 5 decimal places. Additionally, the "Driving Rule" field is blank where it typically shows the rule that is manipulating the value.
Anyone have any suggestions on how to achieve my goals here? Test file attached.
Currently using Inv 2023.4.2
Solved! Go to Solution.
I'm running into more headaches with managing Parameter values thru iLogic, Autodesk suggested I post this to the Forums since they didn't really have a solution on this they thought someone in the community might.
I'm attempting to use a Parameter to store a user input value, with the U/M in FT (to match the supplied value from an Engineers worksheet). The test value used here is 40.00520833 ft [40'-0 1/16"] with an expected final result value saved to the Parameter as 40.00521 ft.
I want iLogic to take that Parameter value, round it to the nearest 1/16th inch, utilize that value within the iLogic for other tasks, and finally save the modified number back in FT to the Parameter rounded to 5 digits to properly hand off through a BOM Export for use with other existing downstream automation processes that require this format.
So mathematically the process is to take the Parameter value, convert to inches, round to the nearest 16th, convert back to FT and round to 5 places for final storage.
I've created Parameter named "Length", applied this logic, and get several unexpected results. Test code and results I've performed thus far are:
Parameter("Length") = Round(Round(Round(Length * 12 * 16) / 16 / 12 * 100000) / 100000, 5)
MsgBox(Length)
'Parameter("Length") = Round(Round(Length * 12 * 16) / 16 / 12, 5) 'This option loses the fractional result
'Dim oLength As Double = Parameter("Length") 'this variant results in the same as line 1 above
'oLength = Round(Round(oLength / 1 ft * 12 * 16) / 16 / 12 * 1 ft, 5)
'MsgBox(oLength)
'Parameter("Length") = oLength
I've added a text box to display the value of the parameter while utilized within iLogic. Expecting that value to be the formatted result in FT, I am instead receiving the value in inches whether I access the Parameter or use a Variable approach. I don't know if the display isn't keeping pace with the speed of the iLogic routine or if in fact the number is not as expected and any routines I add to utilize the value will be the incorrect U/M and thus give me headaches when processing that value through any additional code for model utilization.
The final result of saving the converted value is also not as expected as the rounding method appears to be completely ignored. The value being stored in the Equation field goes to the nth decimal place instead of the desired 5 decimal places. Additionally, the "Driving Rule" field is blank where it typically shows the rule that is manipulating the value.
Anyone have any suggestions on how to achieve my goals here? Test file attached.
Currently using Inv 2023.4.2
Solved! Go to Solution.
Solved by ryan.rittenhouse. Go to Solution.
When you are getting/setting a length parameter in iLogic, Inventor assumes you are using the default length unit of the document*. If your document is set to inches, it'll be inches. Same w/ feet, meters, etc. For what you are trying to do, you could get around it by creating the parameter as a unitless type (maybe name it LengthInFeet) and then your operation works the way you want it to. Hope this helps!
*If you drill down to the parameter object and pull the Value, it will always be in centimeters
When you are getting/setting a length parameter in iLogic, Inventor assumes you are using the default length unit of the document*. If your document is set to inches, it'll be inches. Same w/ feet, meters, etc. For what you are trying to do, you could get around it by creating the parameter as a unitless type (maybe name it LengthInFeet) and then your operation works the way you want it to. Hope this helps!
*If you drill down to the parameter object and pull the Value, it will always be in centimeters
I may be missing your point but aren't you trying to make all this a lot more complex than it should be? I would say you already have your parameter in ft, create another parameter in in and set that to be equal to the first parameter, no need to specifically round it to the nearest 1/16th because the value is exact, but you could if you'd like to make sure. And for the BOM you could just set the custom property format of your first parameter to be rounded to 5 decimals. I don't know what the other tasks are that you want to do in iLogic, but for this part I don't think you even need it at all.
I may be missing your point but aren't you trying to make all this a lot more complex than it should be? I would say you already have your parameter in ft, create another parameter in in and set that to be equal to the first parameter, no need to specifically round it to the nearest 1/16th because the value is exact, but you could if you'd like to make sure. And for the BOM you could just set the custom property format of your first parameter to be rounded to 5 decimals. I don't know what the other tasks are that you want to do in iLogic, but for this part I don't think you even need it at all.
@llorden4, I think the issue might be that you are trying to round the parameter and set the parameter at the same time. I think if you get the value from the parameter and store it in a variable, then what you have works.
In the example below, I set the value to be unrounded just for testing, and then get that value and hand it to a parameter using a variable called olen, then pull that into the line that is setting the parameter value and rounding it.
Parameter("Length") = 40.0052083333333333333333333333 'hand the value to a variable olen = Parameter("Length") Parameter("Length") = Round(Round(Round(olen * 12 * 16) / 16 / 12 * 100000) / 100000, 5) MsgBox(Length)
@llorden4, I think the issue might be that you are trying to round the parameter and set the parameter at the same time. I think if you get the value from the parameter and store it in a variable, then what you have works.
In the example below, I set the value to be unrounded just for testing, and then get that value and hand it to a parameter using a variable called olen, then pull that into the line that is setting the parameter value and rounding it.
Parameter("Length") = 40.0052083333333333333333333333 'hand the value to a variable olen = Parameter("Length") Parameter("Length") = Round(Round(Round(olen * 12 * 16) / 16 / 12 * 100000) / 100000, 5) MsgBox(Length)
olen maybe in cm.
ilogic do conversion behind the code.
Raw numbers are all cm.
Use Logger.Info() to check the numbers.
Tested, return unit is document units (in). Not parameter unit (ft). Or internal unit (cm).
Sub Main()
Dim Length As Double
Length = CDec(Parameter("Length"))
Logger.Info(Parameter("Length").ToString)
Logger.Info(Length.ToString)
Parameter("Length") = Length + 1
Length = CDec(Parameter("Length"))
Logger.Info(Parameter("Length").ToString)
Logger.Info(Length.ToString)
End Sub
So do all calculation in document unit (in). Return it in document unit (in).
Do not do any conversion.
olen maybe in cm.
ilogic do conversion behind the code.
Raw numbers are all cm.
Use Logger.Info() to check the numbers.
Tested, return unit is document units (in). Not parameter unit (ft). Or internal unit (cm).
Sub Main()
Dim Length As Double
Length = CDec(Parameter("Length"))
Logger.Info(Parameter("Length").ToString)
Logger.Info(Length.ToString)
Parameter("Length") = Length + 1
Length = CDec(Parameter("Length"))
Logger.Info(Parameter("Length").ToString)
Logger.Info(Length.ToString)
End Sub
So do all calculation in document unit (in). Return it in document unit (in).
Do not do any conversion.
@ryan.rittenhouse I would swear your take on this was wrong based on my experience with handling parameters before, but you're spot on. I was under the impression that iLogic ignored the U/M of the Parameter and simply pulled the number without any conversion... this exercise has cured that error in opinion of operations; so thank you for that critical tip.
With that understanding, both these workflows work without issue (with the document U/M set to inches)...
Parameter("Length") = Round(Round(Length * 16 ul) / 16 in / 12 ul, 5) * 1 ft
Dim oLength As Double = Parameter("Length")
Logger.Info("Initial value = " & oLength.ToString)
oLength = Round(Round(oLength * 16 ul) / 16 in / 12 ul, 5) * 1 ft
Logger.Info("Adjusted value = " & oLength.ToString)
Parameter("Length") = oLength
@ryan.rittenhouse I would swear your take on this was wrong based on my experience with handling parameters before, but you're spot on. I was under the impression that iLogic ignored the U/M of the Parameter and simply pulled the number without any conversion... this exercise has cured that error in opinion of operations; so thank you for that critical tip.
With that understanding, both these workflows work without issue (with the document U/M set to inches)...
Parameter("Length") = Round(Round(Length * 16 ul) / 16 in / 12 ul, 5) * 1 ft
Dim oLength As Double = Parameter("Length")
Logger.Info("Initial value = " & oLength.ToString)
oLength = Round(Round(oLength * 16 ul) / 16 in / 12 ul, 5) * 1 ft
Logger.Info("Adjusted value = " & oLength.ToString)
Parameter("Length") = oLength
Can't find what you're looking for? Ask the community or share your knowledge.