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: 

Do after user parameter change

6 REPLIES 6
Reply
Message 1 of 7
mk92
430 Views, 6 Replies

Do after user parameter change

Hello,

 

is there any method to check if a user parameter is changed?

 

Like:

If AnyUserParameter changed then

...

End If

 

Or:

 

If UserParameter X changed then

...

End If

Tags (2)
6 REPLIES 6
Message 2 of 7
LukeDavenport
in reply to: mk92

 

Are you using iLogic?

 

Several ways of getting code to run if a user parameter changes:

 

1) Set event trigger for Any Model Parameter Change, and reference the User parameter in a model parameter. This is a 'brute force' method and will obviously run every time any model param changes.

 

2) If the user parameter is explicitly referred to in the iLogic rule (and it therefore appears in blue text) then as long as the Options tab in the iLogic rule 'Don't run Automatically' is NOT ticked the rule will run whenever that specific parameter changes.

 

3) If you want a different method then you can create a 'memory' user parameter, e.g. Length_Memory and then use it as follows:

 

' Check if Length parameter has changed

If Not Length = Length_Memory Then

 

      ' Do Something

 

End If

 

' Set memory parameter again

Length_Memory = Length

 

Does this help?

Luke

 

 

Message 3 of 7
mk92
in reply to: LukeDavenport

Yes i work with iLogic.

 

The third part works fine.

 

 

' Check if Length parameter has changed

If Not Length = Length_Memory Then

 

      ' Do Something

 

End If

 

' Set memory parameter again

Length_Memory = Length

 

But i have 4 parameters to check and any of it start the same if-loop. Is there a way to do that without typing it 4 times?

 

Like:

 

If Not Length_* (* stands for any parameter with nearly the same name like Length_1, Length_2....)

    'Do something

....

Message 4 of 7
LukeDavenport
in reply to: mk92

Well this might be the simplest way of doing it.

If Not Length = LengthMemory OrElse Not Width = WidthMemory OrElse Not
Height = HeightMemory

End If

Other than that you could use a smarter method by:

1) Create a memory parameter for each one: i.e. LengthMemory etc
2) Tick the important parameters as 'Key'

Use this rule (I haven't tested this properly - use at your own risk)...

' Define stuffDim oKeyParamColl As ObjectCollection =
ThisApplication.TransientObjects.CreateObjectCollection Dim oParam As
Inventor.ParameterDim Run As Boolean = False
' Run through all key parameters, checking value against matching
'memory' parameterFor Each oParam In
ThisApplication.ActiveEditDocument.ComponentDefinition.Parameters
If oParam.IsKey Then
' Add the key parameter to the object collection
oKeyParamColl.Add(oParam.Name)
Try
If Not Parameter(oParam.Name) = Parameter(oParam.Name & "Memory") Then
If Not Run Then

MsgBox("RUNNING MAIN CODE.......",,"")
' Put your main code here.................
Run = True
End If
End If
Catch
MsgBox("You need to create a parameter called " &
oParam.Name & "Memory - exiting iLogic rule...",,"")
Exit For
End Try
End IfNext
' Reset all 'memory' parameters to current correct values...For Each
KeyParam As String In oKeyParamColl
Parameter(KeyParam & "Memory") = Parameter(KeyParam)Next
InventorVb.DocumentUpdate()
Message 5 of 7
mk92
in reply to: LukeDavenport

I used this:

If Not Length = LengthMemory OrElse Not Width = WidthMemory OrElse Not
Height = HeightMemory

 

      Mode = 1


End If

 

Length = LengthMemory

Width = WidthMemory

Height = HeightMemory

 

 

But when i change one of the parameters nothing happens. Is there a mistake? I use this method because i want to keep it as simple as possible.

Message 6 of 7
mk92
in reply to: LukeDavenport

And i got an other problem. With:

 

Parameter.Quiet = True
Pos_1 = Parameter("Position_1")

 

If Not Pos_1 = Pos_Memory_1 Then
   Mode = 1
End If


Pos_Memory_1 = Pos_1

 

 

I need the first two lines because the parameter is not existing all the time. But i need to check it for changes. Then the the parameter Mode =1 and an If Loop begins again! The If Loop updates the Model so you can see the position change!

Message 7 of 7
LukeDavenport
in reply to: mk92

MK92, you have got the statements at the end the wrong way round. It should read:

 

LengthMemory = Length

WidthMemory = Width

HeightMemory = Height

 

And for your second question - you should start a new post for this.

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

Post to forums  

Autodesk Design & Make Report