Announcements
Due to scheduled maintenance, the Autodesk Community will be inaccessible from 10:00PM PDT on Oct 16th for approximately 1 hour. We appreciate your patience during this time.
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: 

Comparing parameter value before and after

7 REPLIES 7
SOLVED
Reply
Message 1 of 8
James115
444 Views, 7 Replies

Comparing parameter value before and after

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).

James115_0-1703193258146.png

 

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!

 

7 REPLIES 7
Message 2 of 8
Preston_Reed
in reply to: James115

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 
Message 3 of 8
James115
in reply to: Preston_Reed

@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:

  1. In the example of Y = 5 * X, would this line be used to define the actual value of Y? Or to define a test result?
    ' Generic
    math
    = Result

    ' Filled in example
    Y = 5 * ParameterX
  2. I'm stuck on how to capture the "OriginalValue" when the user changes X, since Y will change only after that.
  3. I could make User Parameter "TestX" and have users enter that value in the form:
    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.

Message 4 of 8
Preston_Reed
in reply to: James115

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

Message 5 of 8

Hi @James115

 

I don't think there is really a very good way to do this with iLogic other than:

  • storing the previous value in a user parameter or iproperty, at the end of the rule so we have it next time around
  • or deconstructing the math to reset the value

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

Curtis_Waguespack_0-1703706195285.png

 

 

I hope this helps.
Best of luck to you in all of your Inventor pursuits,
Curtis
http://inventortrenches.blogspot.com

 

  

 

Message 6 of 8

@Preston_Reed ,  Just a quick FYI... as written the example you posted doesn't ever set InputX

 

 

Message 7 of 8

Oops, you are right, thanks for catching that!

Message 8 of 8
James115
in reply to: James115

@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.

Post to forums  

Autodesk Design & Make Report