Message 1 of 2
Overriding existing rule to parts in assy
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
I have spliced together some ilogic code to override an existing internal rule for all parts in an assembly. The rule
it is overriding works fine. When I run this rule in an assembly it seems to work for the first part then I get an error.
"Object reference not set to an instance of an object."
"System.NullReferenceException: Object reference not set to an instance of an object.
at ThisRule.Addbomdescription()
at ThisRule.Main()
at Autodesk.iLogic.Exec.AppDomExec.ExecRuleInAssembly(Assembly assem)
at iLogic.RuleEvalContainer.ExecRuleEval(String execRule)"
The parts are derived from a main sketch part that is not in the assembly. could this be hanging it up?
I have also tried running a bit of code to just run the external rule with no luck.
Here is the "code" any ideas I would greatly appreciate it.
Public Sub Addbomdescription() ' Get the open top-level assembly. Dim asmDoc As AssemblyDocument = ThisApplication.ActiveDocument ' Get a list of all documents referenced by this assembly. ' This property will return everything at all levels. Dim refDocs As DocumentsEnumerator = asmDoc.AllReferencedDocuments Dim oRuleName As String = "BOM DESCRIPTION" Dim oTxtFileName As String = "C:\Work\CAD Stds\Inventor\Crush iLogic\BOM RULES\BOM DESCRIPTION FEET.txt" Dim oRuleText As String = IO.File.ReadAllText(oTxtFileName) Dim oDoc As Document = ThisApplication.ActiveEditDocument Dim oRuleExists As Boolean = False Dim iLogicAuto = iLogicVb.Automation iLogicAuto.RulesEnabled = True iLogicAuto.RulesOnEventsEnabled = True Dim oRule As iLogicRule ' Iterate through the documents. For Each oDoc In refDocs ' Look for part documents. If TypeOf (oDoc) Is PartDocument Then 'ADD BOM DESCRIPTION INTERNAL RULE Try oRule = iLogicAuto.GetRule(oDoc, oRuleName) Catch oRule = iLogicAuto.AddRule(oDoc, oRuleName, "") End Try oRule.Text = oRuleText iLogicVb.DocumentUpdate End If Next End Sub