Problem: I have a lot of old files with several references to external iLogic rules which give errors when they are saved:
iLogic Event-Driven Rule
RunRule: Cannot find a rule with the name: "External Part Rule".
I believe this is being called by an event trigger rather than being a rule residing in the document. Megajerk made a program which injects iLogic rules and will add Event Triggers for those rules in multiple files. It looks nice, but what I want to do is delete specific rules from the event triggers, so I am only able to use some of his code. Below is what I have, but for some reason it is not working. it could be a change in Inventor 2014 or I could be missing something. I do not know. If anyone sees where the problem is coming in, I would appreciate the help.
''This is part of a larger routine, so only the needed bits here Public Sub Main() Dim oDoc As Document = ThisApplication.ActiveDocument iLogicCleanup(oDoc) End Sub ''This is for cleaning out troublesome iLogic rules Sub iLogicCleanup(oDoc) Dim oiLogicPropSet As PropertySet 'Try to set our property set from Megajerk's code. Errors immediately. Try oiLogicPropSet = oDoc.PropertySets.Item("iLogicEventsRules") 'Never makes it past here and I can find no other documentation on this Property Set If oiLogicPropSet.InternalName <> "{2C540830-0723-455E-A8E2-891722EB4C3E}" Then oiLogicPropSet.Delete() oDoc.PropertySets.Add("iLogicEventsRules", "{2C540830-0723-455E-A8E2-891722EB4C3E}") End If Catch Try oDoc.PropertySets.Add("iLogicEventsRules", "{2C540830-0723-455E-A8E2-891722EB4C3E}") Catch MsgBox("Unable to create iLogic Even Triggers property for this file.", vbOKOnly, "Event Triggers Error.") Exit Sub End Try End Try If oiLogicPropSet.Count > 0 Then For Each oiLogicProp In oiLogicPropSet If oiLogicPropSet.Item(oiLogicProp).Value = "External Part Rule" Then oiLogicPropSet.Item(oiLogicProp).Delete End If Next End If End Sub
Solved! Go to Solution.
Solved by wood.isbell. Go to Solution.
Hi,
Just checked and you get that error when an existing rule is trying to call an external rule directly:
Error in rule: Rule0, in document: Part1.ipt RunRule: Cannot find a rule with the name: "TempExternalRule".
If it was trigered by an event, you'd get this:
iLogic Event-Driven Rule RunExternalRule: Cannot find an external rule file named: "C:\Users\Administrator\Documents\Inventor\MyProject\TempExternalRule".
So you would need to modify the code in the project.
Cheers,
Adam,
Thank you for the response. The bit that is throwing me off is that I am getting a mix of those two errors. I have these old files from various templates that all came before my time here, and they have a variety of iLogic problems including the one you mention with a rule referencing a missing external rule. This one is a bit different, because it does not reference an internal rule or the filename and it says "iLogic Event-Driven Rule" like the other.
Now I am wondering if there is a way that some of our files have been corrupted to have an Event Trigger that is pointing at an internal rule which is no longer present. I would not have thought that was possible, though. I know that if you delete an internal rule, it removes the triggers for it.
Hopefully I will find a way to affect the Event Triggers programatically because it is difficult to find the file causing this particular error. If I do manage to find it when I have time to clean again I will report back.
Hi,
You're right. It sounds like you have an event referencing an internal rule that does not exist.
Could it be that some of those documents were modified with some tool like the one mentioned here (this seems to be about the opposite though, i.e. inserting extra code, and not removing) and a rule got removed without it being removed from the event as well?
http://forums.autodesk.com/t5/Inventor-Customization/iLogic-Form-Injector/td-p/3550486
Cheers,
It is entirely possible. As far as I know, the only method that has been used to remove any iLogic is using rules which I have written, but they do not produce this result. A rule deleted with my code will automatically remove any associated Event Triggers. Hopefully I will have time in the near future to track down the file in question so that I can perform further tests on it since currently I have only an assembly with numerous components. I have a sneaking suspicion that the error may reside in an iPart Factory Member rather than any Part or sub-Assembly. If this is the case, I may only have a problem in the children which could be fixed by forcing the parent to update them. I am completely unsure how to go about confirming this, and the only reasoning I have is that I have seen in the past where I would get similar (possibly the same) error when saving children after the parent had been fixed. The only way I know to fix this is to modify geometry in the parent which will force a complete rewrite of the child rather than just a modification.
Thank you for your response. If I come up with anything more on this, I will post back. Also, any more help with ideas are appreciated.
My last guess was correct, and my thanks to Adam for the help getting there. I finally tracked down a file that contains this problem, and it is generated member of an iPart factory. There are no Event Triggers or iLogic rules in the parent, and with the link intact in the child member, you cannot see the Event Triggers through the normal interface. If you break the link to the parent so that you can edit the Event Triggers, one shows up that has no iLogic rule associated with it. Obviously this is not a solution, as this requires the link be broken.
I could delete the generated members and recreate them, but no update of the parent will remove the error. It may be possible to create a rule in the parent with the same name, regenerate the child member, and then delete the rule from the parent and regenerate again. I may try this, but it is still not an ultimate solution. My goal is to programmatically attack assemblies with a number of rules to clean up various flaws, and I want to get rid of these broken Event Triggers at the same time.
If anyone comes up with some guidance on this, I would appreciate it, and I will continue to work on it as it hits me in the face.
When thinking of possible causes of this, two come to mind. One is the possibility that someone deleted all iLogic rules in an assembly, and somehow this functionality of Inventor is imperfect when handling iPart factory members, or the code that I have written to destroy iLogic rules (with specific names) in all of the subcomponents of an assembly or part has this flaw when encountering an iPart factory member. The latter is probably not difficulty to prevent in the future, only requiring me to leave such members out of the mix. Either way, the problem exists now, and I am eager to find a solution.
'capture current document Dim oiLDoc As ThisApplication.ActiveDocument 'load up ilogic automation Dim oiLogicAuto As Object = iLogicVb.Automation 'get container for all of the ilogic rules Dim oRules As Object = oiLogicAuto.rules(oiLDoc) 'variable for the events rules Dim oiLPropSet As PropertySet 'set up a counter Dim iPropCount As Integer 'if there are no rules, then there is no need for event triggers 'if there are no even rules, no need to go further 'if not a part, I'm not interested If oRules Is Nothing And oiLDoc.PropertySets.PropertySetExists("iLogicEventsRules") And oiLDoc.DocumentType = 12290 Then 'set our property set since we know it exists now oiLPropSet = oiLDoc.PropertySets.Item("iLogicEventsRules") 'only iPart Members seem to be plagued with orphaned triggers 'if there aren't any triggers, then we're done If oiLDoc.ComponentDefinition.IsiPartMember And oiLPropSet.Count > 0 Then 'iterate through the triggers and delete each For iPropCount = 1 To oiLPropSet.Count oiLPropSet.Item(iPropCount).Delete Next iPropCount End If End If
The above works. It took a while, but finally got it together.
Ill getting below error while run the run. I just copy paste your ilogic code.