- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
Hi everyone,
I've created an external rule that creates a local rule based on Luke Davenport's blog:
It works sometimes but most of the time I get the “Object reference not set to an instance of an object” message and the rule is not created.
I can’t find a constant pattern to help me figure out why sometimes it works and sometimes not. I tried part files, assembly files, vaulted, unvaulted, old files, recent files, etc.
We are using Inventor 2018 with Vault Workgroup 2018
The purpose of this rule (in case other solutions could be applied):
In our templates, I've insert some new parameters that are driven by an external rule but they need an immediate response from this rule every time they are modified (I tried Event Triggers, not good for that). In my templates, I've created a local rule with a dummy parameter that calls for the external rule to run everytime my "finish_list" parameter is modified. This works well but when we want to update an old part or assembly with the new template's standards (with our update external rule) I also have to create a local rule on those old parts.
Here's my code:
SyntaxEditor Code Snippet
' External rule to create a local rule Dim RuleName As String = "Paint_Action" Dim RuleText As String = "'Rule to add a color to the finish when painted" & vbCrLf & _ "Paint_Dummy = finish_list" & vbCrLf & _ "iLogicVb.RunExternalRule(""Paint_Options"")" Dim oDoc As Document = ThisApplication.ActiveEditDocument Dim RuleAlreadyExists As Boolean = False ' Define the iLogic addin Dim iLogicAddIn As ApplicationAddIn = ThisApplication.ApplicationAddIns.ItemById("{3bdd8d79-2179-4b11-8a5a-257b1c0263ac}") ' Get the iLogic automation object Dim iLogic As Object = iLogicAddIn.Automation ' Get the list of iLogic rules in the current Inventor document Dim RuleList As Object = iLogic.Rules(oDoc) ' Loop through all rules in document For Each R As Object In RuleList If R.Name = RuleName Then ' A rule with the same name already exists... RuleAlreadyExists = True Exit For End If Next If RuleAlreadyExists Then Dim ReplaceRule As MsgBoxResult = MsgBox("A rule called '" & RuleName & "' already exists - replace it?", 36, "Excitech iLogic") If ReplaceRule = vbYes Then ' Delete the existing rule iLogic.DeleteRule(oDoc, RuleName) ' Add the new rule iLogic.AddRule(oDoc, RuleName, RuleText) Else MsgBox("Operation cancelled...", 64, "Excitech iLogic") Exit Sub End If Else ' No existing rule to delete - simply add the new rule iLogic.AddRule(oDoc, RuleName, RuleText) End If ' End of iLogic rule
Any help on this would be very appreciated.
Thank you!
Solved! Go to Solution.