iLogic Script to check if part in drawing has external rule

iLogic Script to check if part in drawing has external rule

pball
Mentor Mentor
1,087 Views
5 Replies
Message 1 of 6

iLogic Script to check if part in drawing has external rule

pball
Mentor
Mentor

I have an iLogic script in my drawing that was checking for a local iLogic rule inside of the part and it would do something if the rule was not found. I have since moved the part iLogic rule to be external and that check no longer works. I've come across a post with info from the dev team that there is no api to look for external rules. So I figure there should be some work around possible.

 

I was thinking about checking for triggers since the part still has those even with the rule being external. I've looked through the iLogic injector @MegaJerk made and found a thread of his and both reference .PropertySets.Item("iLogicEventsRules"). I've dug around in a file that has ilogic triggers and I can't see or access that property set at all. When I try to run thisapplication.activedocument.PropertySets.Item("iLogicEventsRules") I get an activex can't create object error.

 

Is there some trick to accessing the iLogic trigger information?

Check out my style edits for the Autodesk forums
pball's Autodesk Forum Style
0 Likes
Accepted solutions (2)
1,088 Views
5 Replies
Replies (5)
Message 2 of 6

frederic.vandenplas
Collaborator
Collaborator

Hi,

 

Maybe not a neat solution but If you try to run the external rule, an error will occur, if you capture the error, you can proceed with

the rest of your code.

 

Try
iLogicVb.RunExternalRule("c:\test.vb")
Catch
MsgBox("The external rule cannot be found")
End Try

 

If you think this answer fullfilled your needs, improved your knowledge or leads to a solution,
please feel free to "kudos"
0 Likes
Message 3 of 6

MegaJerk
Collaborator
Collaborator
Accepted solution

As described here, depending on when a given file was created (or at least which version of Inventor it was created with) the PropertySet for Event Triggers might be hidden. 

Instead of using the PropertySet name "iLogicEventsRules" or "_iLogicEventsRules", search for the GUID "{2C540830-0723-455E-A8E2-891722EB4C3E}"

 

I hope that this gets you started in the right direction. 

----

 



If my solution worked or helped you out, please don't forget to hit the kudos button 🙂
iLogicCode Injector: goo.gl/uTT1IB

GitHub
0 Likes
Message 4 of 6

pball
Mentor
Mentor

That seems to find the external rule whether or not the part in the drawing is using it or not. So that will not work for what I'm doing.

 

I need to explicitly check if the part inside a drawing has an active external rule, not if an external rule exists.

 

The only method I know will work would be to have a one line internal rule that calls an external rule. That way I can use some code that lists internal rules in a component to see if it exists in a part. The reason I'm reluctant to do that is all the parts created with the external rule already won't be updated properly.

Check out my style edits for the Autodesk forums
pball's Autodesk Forum Style
0 Likes
Message 5 of 6

pball
Mentor
Mentor

Thanks for that info MegaJerk, that is exactly what I needed. Below is the code I came up with to check if a part/assembly inside of a drawing has an external rule setup to trigger.

 

Dim docFile As Document
If ThisDoc.ModelDocument IsNot Nothing Then
	docFile = ThisDoc.ModelDocument
Else
	Return
End If

'Check if part has iLogic rule named Material, if not this will update Matrl iProp even if Matrl already exists
Dim MatFound = False
Dim iLogicE As propertyset
iLogicE = docFile.PropertySets.Item("{2C540830-0723-455E-A8E2-891722EB4C3E}")

For i As Integer = 1 To ilogicE.count
	If (InStr(ilogicE.item(i).Value,"Material_Part")) Or (InStr(iLogicE.item(i).Value,"Material_Assembly")) Then MatFound = True
Next

MsgBox("Does part/assembly have a matching external iLogic rule. " & MatFound)
Check out my style edits for the Autodesk forums
pball's Autodesk Forum Style
0 Likes
Message 6 of 6

pball
Mentor
Mentor
Accepted solution

I really dislike the short edit allotted on this forum.

 

Updated code. Added the try/catch since I just found out parts that have never had iLogic rules apparently do not have that property set.

 

 

Dim docFile As Document
If ThisDoc.ModelDocument IsNot Nothing Then
	docFile = ThisDoc.ModelDocument
Else
	Return
End If

'Check if part has external iLogic rule named Material_Part or Material_Assembly
Dim iLogicFound = False
Dim iLogicE As propertyset

Try
	iLogicE = docFile.PropertySets.Item("{2C540830-0723-455E-A8E2-891722EB4C3E}")
	For i As Integer = 1 To ilogicE.count
		If (InStr(ilogicE.item(i).Value,"Material_Part")) Or (InStr(iLogicE.item(i).Value,"Material_Assembly")) Then iLogicFound = True
	Next
Catch
	'No iLogic I guess
End Try

MsgBox("Does part/assembly have a matching external iLogic rule. " & iLogicFound)

 

Check out my style edits for the Autodesk forums
pball's Autodesk Forum Style
0 Likes