Hi,
Simplified example here, but I have a Form to allow users to change the value of User Parameter X. The form shows read-only User Parameter Y and Z. The value of Y is calculated as 5 * Parameter X. In case the user enters a value for X and clicks Apply and that leads to Y being higher than Z, I would like to revert the value that the user entered to the previous value for X (so the last value before Y exceeds Z).
What I tried is reading the values with i.e.:
iLogicForm.Show("Test").GetField("X").Value
or .Forms
But that gives errors like:
'Values' is not a member of 'Autodesk.iLogic.Interfaces.FormReturnValue'
"It may be inaccesible due to its protection level"
Another way would be fine too, this is just what I thought of, thanks in advance!
Solved! Go to Solution.
Solved by Curtis_Waguespack. Go to Solution.
Solved by Preston_Reed. Go to Solution.
If i understand, if the value entered then results in other values that exceed limits then you want to revert the values back to what they were before.
I would just use the user parameters. Run what you have so far in terms of the math and update the model, then in the next routine check the value of the user parameter and if its not ok then replace the parameters. Something like:
Sub main Math Check RuleParametersOutput() iLogicVb.DocumentUpdate() End Sub Sub Math ' Do your math here ( you can just use another user parameter here too to keep track of the result) math = Result ' Save the previous entry if you want to go back to it ' Can use another user parameter ParameterX = OriginalValue ' Update model RuleParametersOutput() iLogicVb.DocumentUpdate() End Sub Sub Check If Result > Limit Then ParameterOriginal = ParameterX End If End Sub
@Preston_Reed Thanks for helping, not sure if the solution below is what you meant, but I would prefer not to create too many User Parameters. I'm new to iLogic/coding. Some questions:
' Generic
math = Result
' Filled in example
Y = 5 * ParameterX
Result = TestX * 5 If Result > Z Then TestX = X Else X = TestX End If
But since Y is not only dependent on X, but also on A, B etc. I would have double the parameters (TestX, TestA, TestB)
So I prefer using Dim instead of User Parameters to capture the before value for instance that would be okay.
Hey @James115 , i made some changes and this should do what your looking for.
Sub main Rule RuleParametersOutput() iLogicVb.DocumentUpdate() End Sub Sub Rule ''' Math ' Declare variables Dim InputX As Double Dim Y As Double Dim Z As Double Dim OriginalX As Double Dim OriginalY As Double Dim OriginalZ As Double ' Save initial values ' You are going to need a Parameter X,Y & Z in order to use the form ' Do this first to caputer the values of the parameter, aka the previous values OriginalX = ParameterX OriginalY = ParameterY OriginalZ = ParameterZ ' Do math here Y = 5 * InputX Z = 2 * InputX ' Apply values to the parameters Parameter("ParameterX") = InputX Parameter("ParameterY") = Y Parameter("ParameterZ") = Z ' Update model RuleParametersOutput() iLogicVb.DocumentUpdate() ''' Check If Y > Z Then Parameter("ParameterX") = OriginalX Parameter("ParameterY") = OriginalY Parameter("ParameterZ") = OriginalZ Else ' Do nothing End If End Sub
No worries about just starting iLogic, I am still pretty new to it but this forum and the Autodesk University stuff is where i learned everything, they are great resources
Hi @James115,
I don't think there is really a very good way to do this with iLogic other than:
Deconstructing the math:
So for instance if Y = X * 5 then we would use Parameter Y / 5 to get the previous X value as shown in this example.
See 2024 example attached.
InputX = ParameterX 'calc new value Y = 5 * InputX If Y > Parameter("ParameterZ") Then 'calc previous value previousX = Parameter("ParameterY") / 5 MsgBox("Y > Z" & ", setting X back to " & previousX _ & vbLf & InputX & " x 5" & " = " & Y, , "iLogic") 'set back to previous value Parameter("ParameterX") = previousX Else Parameter("ParameterX") = InputX Parameter("ParameterY") = Y End If
I hope this helps.
Best of luck to you in all of your Inventor pursuits,
Curtis
http://inventortrenches.blogspot.com
@Preston_Reed thanks it works!
@Curtis_Waguespack I tried deconstructing it, but for my case it'll be hard to adapt the code in the future so decided not to. For simple math it seems like a good solution too.
Can't find what you're looking for? Ask the community or share your knowledge.