Ilogic rules, creating triggers

Ilogic rules, creating triggers

Thetigerpirro
Advocate Advocate
6,186 Views
51 Replies
Message 1 of 52

Ilogic rules, creating triggers

Thetigerpirro
Advocate
Advocate

Hi, I have a external rule that I would like to add a trigger to itself (or interna rule) once triggered. I can't seem to find a good way to do this, so suggenstions are appreciated.

 

 

Have a nice day.

0 Likes
6,187 Views
51 Replies
Replies (51)
Message 41 of 52

FRFR1426
Collaborator
Collaborator

Instead of creating a temporary rule, you can use the following code to add the document interest to the document :

 

Dim oDoc = ThisDoc.Document

If Not oDoc.DocumentInterests.HasInterest("{3BDD8D79-2179-4B11-8A5A-257B1C0263AC}") Then
	oDoc.DocumentInterests.Add("{3BDD8D79-2179-4B11-8A5A-257B1C0263AC}", "iLogic", DocumentInterestTypeEnum.kInterested, 20090512, "")
	MessageBox.Show("You have to close and then open the document again to activate the triggers.", "Installation of triggers", MessageBoxButtons.OK, MessageBoxIcon.Warning)
End If

 

Unfortunately, according to my tests, you have to close and open the document again to activate the newly installed trigger.

Maxence DELANNOY
Manager
Add-ins development for Autodesk software products
http://wiip.fr
0 Likes
Message 42 of 52

mslosar
Advisor
Advisor

Thanks to all who've discussed this topic so far.  It helped me get a version of this working for project i'm working on. However, i've run into an oddity i'm wondering if someone can explain.

 

I'm using the basic rule structure shown above and it works fine on it's own.  I"m parsing a BOM Structure and running it on part objects. The script adds a rule to the files Before Save option. This is the code that is calling it:

 

Dim myDoc As Document = ThisApplication.Documents.Open(oDoc1.FullFilename, True)				
				iLogicVb.Automation.RunExternalRule(myDoc, "RBlankTriggerSet")
				myDoc.Save2(False)
				myDoc.Close(True)	

The problem is, if that first Open line is set to False (so it does not show the system pulling up each part), the rule (which is inserted in Before Save, does not execute.  It gets added and it's saved as part of the file, but it does not run.  If it is set to True, it does execute.  This isn't a deal breaker, per se, but it would be nice to not subject the user to that as it takes a good deal longer to run that way.

 

Is there a way to get this to run silently? Or is noisily the only option?

0 Likes
Message 43 of 52

MjDeck
Autodesk
Autodesk

@mslosar , can you post your external rule RBlankTriggerSet? Please attach it as a text file.


Mike Deck
Software Developer
Autodesk, Inc.

0 Likes
Message 44 of 52

mslosar
Advisor
Advisor

Here it is

0 Likes
Message 45 of 52

MjDeck
Autodesk
Autodesk

Thanks. Can you describe your workflow in more detail? You might not need the Open and Close statements. It looks like you're getting the FullFileName from a Document object (oDoc1). That document is already open.
Are you running Inventor 2022 or 2023?
Do your parts contain more than one Model State?
Are you iterating over the rows of a BOMView to get the documents?


Mike Deck
Software Developer
Autodesk, Inc.

0 Likes
Message 46 of 52

mslosar
Advisor
Advisor

We're completely switching ERPs and internal systems which calls for saving things in a whole new way. This script is part of the change over.

 

The workflow in this case is opening an existing assembly and running a different script which crawls through the model data tab and adding a series of iproperties, parameters, updating part numbers, and then executing this trigger rule on all part files to add a script into the BeforeDocSave trigger.  Everything works except that script needs to actually execute to store a value in the file it is attached to.  I can manually run the script fine. But the only way it works in the overall process is for each part to get manually called up on the screen at which point save actually invokes the BeforeDocSave trigger.  When it's run silently, the trigger never gets called.

0 Likes
Message 47 of 52

MjDeck
Autodesk
Autodesk

Thanks for the details.
Are you running on Inventor 2022 or 2023?
Do your parts contain more than one Model State?
It might be possible to simplify the script that goes over the BOM.
On this line:

Dim myDoc As Document = ThisApplication.Documents.Open(oDoc1.FullFilename, True)	

Do you already have a Document in the oDoc1 variable? If so, why open it again?


Mike Deck
Software Developer
Autodesk, Inc.

0 Likes
Message 48 of 52

MjDeck
Autodesk
Autodesk

Have you looked at global event triggers? You can set an event to run on all parts. That way, you don't have to add an event trigger to each individual part.


Mike Deck
Software Developer
Autodesk, Inc.

0 Likes
Message 49 of 52

mslosar
Advisor
Advisor

This particular trigger needs to run at the part level as it needs to always run on save and we can't guarantee the part will always be in the same parent assembly. Also, this is 2021.  Going to 2023 this fall (fingers crossed they do it that quickly 🙂 )

0 Likes
Message 50 of 52

mslosar
Advisor
Advisor

Could have something to do with the fact it's roughly 200 lines about where i have that called 🙂  Kind of an 'out of sight, out of mind thing'.  I can give that a try and see what happens.  Perhaps something to do with a double open is part of the problem.  I'll let you know what it does when i get the chance to try it.

 

Thank you!

0 Likes
Message 51 of 52

MjDeck
Autodesk
Autodesk

In the Event Triggers dialog, there's a Parts tab.

Events under that tab run at the part level, in all parts. You can set a rule to run on save in that tab. It will run in all parts, no matter what assembly they're in.
If you're planning on adding this trigger to each and every part, it would be easier to do it from the Parts tab instead.


Mike Deck
Software Developer
Autodesk, Inc.

0 Likes
Message 52 of 52

jacques.posthumus
Explorer
Explorer

 

 Hi Curtis , 
I enjoy your work. Attached is the code for User Parameter Change that seems to be missing from all the lists. Useful to Update Forms instantly when you change Parameters!

 
 
 
 
 
 

 

'   CheckList Box Name:                     : Property Name :                 : Property ID
'   ----------------------------------------------------------------------------------------
'   After Open Document (P;A;D)             : AfterDocOpen                    : 400
'   Close(Document) (P;A;D)                 : DocClose                        : 500
'   Before Save Document (P;A;D)            : BeforeDocSave                   : 700
'   After Save Document (P;A;D)             : AfterDocSave                    : 800
'   Any Model Parameter Change (P;A)        : AfterAnyParamChange             : 1000
'   Part Geometry Change (P)                : PartBodyChanged                 : 1200
'   Material Change (P)                     : AfterMaterialChange             : 1400
'   iProperty(Change) (P;A;D)               : AfterAnyiPropertyChange         : 1600
'   Drawing View Change (D)                 : AfterDrawingViewsUpdate         : 1800
'   Feature Suppression Change (P)          : AfterFeatureSuppressionChange   : 2000
'   Component Suppression Change (A)        : AfterComponentSuppressionChange : 2200
'   iPart / iAssembly Change Component (A)  : AfterComponentReplace           : 2400
'   New Document (P;A;D)                    : AfterDocNew                     : 2600
'   Model State Activated (P;A)             : ModelStateActivated             : 2800
'   Any User Parameter Change (P;A;D)       : AfterAnyUserParamChange         : 3000

' (P) Part Files, (A) Assembly Files & (D) Drawing Files

 

 

0 Likes