iLogic error in rule

iLogic error in rule

Anonymous
Not applicable
458 Views
1 Reply
Message 1 of 2

iLogic error in rule

Anonymous
Not applicable

Hi,

 

I have used the below rule in a number of assemblies and it seems to work fine:

 

SyntaxEditor Code Snippet

Sub Main

auto = iLogicVb.Automation
' Set Rule name
Dim ruleName As String
ruleName = "Flat_Pattern_Assy"
' Get the active assembly.
Dim oAsmDoc As AssemblyDocument
oAsmDoc = ThisApplication.ActiveDocument
' Get all of the referenced documents.
Dim oRefDocs As DocumentsEnumerator
oRefDocs = oAsmDoc.AllReferencedDocuments
' Iterate through the list of documents.
Dim oRefDoc As Document
For Each oRefDoc In oRefDocs
If oRefDoc.SubType = "{9C464203-9BAE-11D3-8BAD-0060B0CE6BB4}" Then
Dim rule As Object
rule = auto.GetRule(oRefDoc, ruleName)
'If (rule Is Nothing) Then'Call MsgBox("No rule named " & ruleName & " was found in the document.")'Else'MessageBox.Show(rule.Name, oRefdoc.displayname)

Dim i As Integer
i = auto.RunRuleDirect(rule)

End If
Next
End Sub

 

However, I have just derived a part and created a multi-body model and then used 'Make Components' to create a new assembly. My rule above is set to run on save but the below error occurs regardless of when I am running the rule:

 

Error in rule: Flat_Pattern_Parts, in document: 04864_001.iam

Object reference not set to an instance of an object.

 

System.NullReferenceException: Object reference not set to an instance of an object.
at Microsoft.VisualBasic.CompilerServices.Symbols.Container.InvokeMethod(Method TargetProcedure, Object[] Arguments, Boolean[] CopyBack, BindingFlags Flags)
at Microsoft.VisualBasic.CompilerServices.NewLateBinding.ObjectLateGet(Object Instance, Type Type, String MemberName, Object[] Arguments, String[] ArgumentNames, Type[] TypeArguments, Boolean[] CopyBack)
at LmiRuleScript.Main()
at Autodesk.iLogic.Exec.AppDomExec.ExecRuleInAssembly(Assembly assem)
at iLogic.RuleEvalContainer.ExecRuleEval(String execRule)

 

I would appreciate any help.

 

Thanks

0 Likes
459 Views
1 Reply
Reply (1)
Message 2 of 2

frederic.vandenplas
Collaborator
Collaborator

Hi,

 

This code won't open the original part of the the derived part, your code does do that which is causing the error

 

Public Sub GetPartOccurrences() 
    ' Get the active assembly. 
    Dim oAsmDoc As AssemblyDocument 
    Set oAsmDoc = ThisApplication.ActiveDocument 

    ' Get the assembly component definition. 
    Dim oAsmDef As AssemblyComponentDefinition 
    Set oAsmDef = oAsmDoc.ComponentDefinition 

    ' Get all of the leaf occurrences of the assembly. 
    Dim oLeafOccs As ComponentOccurrencesEnumerator 
    Set oLeafOccs = oAsmDef.Occurrences.AllLeafOccurrences 

    ' Iterate through the occurrences and print the name. 
    Dim oOcc As ComponentOccurrence 
    For Each oOcc In oLeafOccs 
        'Put your code here
    Next 
End Sub

Interesting piece of lecture can be found here

 

 

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