Get item "ilogic event rules"

Get item "ilogic event rules"

NeoLitik
Enthusiast Enthusiast
297 Views
3 Replies
Message 1 of 4

Get item "ilogic event rules"

NeoLitik
Enthusiast
Enthusiast

Hi there.

 

I have created an ilogic script that allows me to add a rule and activate the trigger necessary to update the rule when a parameter changes.

This script works very well on my recent projects (inventor 2020).

However, I have a problem with parts (.ipt) from the inventor 2013 version.

I have an error when retrieving "ilogiceventrules".

the error :

 

"

Error in rule: test, in document: XXX.ipt

Invalid class string (Exception from HRESULT: 0x800401F3 (CO_E_CLASSSTRING))

"

 

However, it seems to me that my code is correct and that it foresees each case and that since I have "catch/try" I should not have any error.
(here is only the part that interests us)

 

Thank you in advance to take time to answer me and understand my error.

Regards.

 

' Add the rule in event trigger

'variable declaration
Dim customPropSets As PropertySets
Dim customPropSet As PropertySet

doc = ThisApplication.ActiveDocument

customPropSets = oDoc.PropertySets

'Get the item (depending of internal name)
	Try
		customPropSet = oDoc.PropertySets.Item("iLogicEventsRules")
	Catch
		If customPropSet Is Nothing Then
			customPropSet = oDoc.PropertySets.Item("_iLogicEventsRules")
		End If
	Catch
		If customPropSet.InternalName <> "{2C540830-0723-455E-A8E2-891722EB4C3E}" Then
			Call customPropSet.Delete
			customPropSet = oDoc.PropertySets.Add("iLogicEventsRules", "{2C540830-0723-455E-A8E2-891722EB4C3E}")
		End If
	Catch 
		If customPropSet Is Nothing Then
			customPropSet = oDoc.PropertySets.Add("iLogicEventsRules", "{2C540830-0723-455E-A8E2-891722EB4C3E}")
		End If
	Catch
		If customPropSet Is Nothing Then
			MessageBox.Show("Unable to create the Event Triggers property for this file!","Event Triggers Not Set")
			Err.Raise(1)
			Exit Sub
		End If
	End Try
0 Likes
298 Views
3 Replies
Replies (3)
Message 2 of 4

WCrihfield
Mentor
Mentor

Hi @NeoLitik.  I don't know how much you may already know about the hidden iProperty set used for the Event Triggers settings of the local document, so I will try to help as best I can.  First of all, it was hidden by Autodesk, and they warn against relying on any resources that they have hidden, because they may change in any way, without notice, because they were designed for Autodesk's internal use.  That being said, we have known about it since around 2013 and you can search within this forum to read more about that if you want.  However, I have also created a few contribution posts about it too that you may find helpful (Link1, Link2, Link3).  Basically that property set will not exist yet in a document until you have either added a rule to the Event Triggers manually before, or have created it by code before.  Once it has been created, it can then still only be found by either its 'Name' or its 'InternalName' directly, and it won't show up in the PropertySets.Count or in a loop of PropertySets (unless you 'un-hide it').  But you don't necessarily need to un-hide it before you can work with it, as long as you can find it or create it.  Once you have that PropertySet object, it will work like any other PropertySet object.

 

Also, the Try...Catch...End Try block is not exactly fool proof either.  If the Try statement and every Catch statement fails, it will still throw an error and stop your rule/code.  And sometimes if you have multiple Catch statements that are too similar, it won't like that either, because they would have failed for the same reasons.  I did notice that one of your Catch statements is trying to check the InternalName of the PropertySet, but that would be impossible, because it has not been assigned to that variable yet.  The statements within previous Catch statements will not carry down into later Catch statements.  Generally speaking, there are three possibilities to deal with within the Try...Catch block (1: it does not exist yet ; 2: it is still hidden ; 3:  it has been 'un-hidden').  I would simply try to find it by its 'hidden name', then by its 'un-hidden name with the that block, then after End Try, you could check if your variable has been given a value yet.  If it has not been, then create it.  If it has been, then if you still want to 'un-hide' it before proceeding, then check its name(s), then delete & re-create if needed, then move on.  Try to keep things as simple as possible, then it will all be easier to debug and understand later if needed.

Wesley Crihfield

EESignature

(Not an Autodesk Employee)

0 Likes
Message 3 of 4

NeoLitik
Enthusiast
Enthusiast

Thank you @WCrihfield for your complete and quick answer.


I am indeed a neophyte in these fields. And although I understand the problem of this hidden property in broad terms, I am a bit lost with the details.

I created a "hello world" rule and indeed, as soon as I manually add it to an event trigger, my rule calling "ilogic event rule" works.

I tried to automate this with the help of your great article :
"How To: "Unhide" the "Hidden" Event Triggers iProperties PropertySet using an iLogic rule"

However I have the same error.
Although I understand the idea in broad terms, I think I'm still missing something.

Now, if I understand correctly: since this document never had a rule placed in its event triggers, this set of iProperties does not exist and must be created by code (since I have to process a bunch of parts, I'm not going to do it by hand hehe!)
And therefore, hiding/unhiding the event trigger won't work until I do this.

Am I right ?

As a reminder: the code I'm trying to get to work on these old .ipt's just adds an internal ilogic rule to the event trigger.


thank you
best regards

0 Likes
Message 4 of 4

WCrihfield
Mentor
Mentor

I just looked up another very similar post I helped out with back in August about adding a rule to the Event Triggers dialog by code.  The solution code I posted there (in message 11 of a post simply labeled "Event Triggers") may be a bit more advanced and polished than the solution I have on my contribution post.  That code had not yet introduced the little extra bit of code that attempts to check if the rule is 'local' or 'external', and does not try to add the "file://" text to the start of the rule name of external rules yet, so it should work just fine for local rules.  However, the bit of code near the beginning, where it wants you to specify a rule name could be changed, if needed, to better suit your needs.  We could use something like an InputBox that would pop-up and ask you to type in a rule name, or it could simply search within the currently active document for any local rules, then present you with a list of the rule names to choose from, or it could open some other specific document, then get a specifically named rule within it to work with...there are many ways it could be changed, but I would need to know how you intend to use it.

 

You said you want to use this rule on a bunch of older .ipt part files to add a local rule within them to their local Event Triggers in that part, but you did not say what event(s) you want the rule put under or what the rule's name is or how you intend to specify the rule's name or how you plan on using this rule on those parts.  Do you intend to open each part manually, then run this rule?  Are all of these parts in a single folder and you would like for this rule to process all the part files in that folder (with maybe some exceptions)?  Do you want that when you run the rule, it opens a file dialog to let you select a part file to target, then shows you the list of its local rules to choose one?  Some other process in mind?  If so, just let me know, and I'll see what I can do for you, if I have time.

Wesley Crihfield

EESignature

(Not an Autodesk Employee)

0 Likes