Message 1 of 6
Unexpected error message - "ThisAssembly"

Not applicable
06-01-2021
11:23 AM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
I have the following code as the first lines in a rule I wrote last week, as graceful error handling if the rule is called from a non-assembly document:
Dim oAsm As Document = ThisApplication.ActiveDocument
Dim oCompDef As ComponentDefinition = oAsm.ComponentDefinition
If Not oAsm.DocumentType = Inventor.DocumentTypeEnum.kAssemblyDocumentObject Then
MsgBox("You cannot call this rule in a non-assembly document.", , "Error")
Exit Sub
End If
When run in the rule I wrote last week, it works perfectly, and I get the MsgBox and it exits the rule. However, I copied and pasted that code into a NEW rule I am working on today, and instead, I get the following error message when the rule is run from a part document:
System.ArgumentException: ThisAssembly: This document "Part1" is not an assembly.
at Autodesk.iLogic.Core.ForRuleCode.ManagedAssembly.get_Document()
at Autodesk.iLogic.Core.ForRuleCode.ManagedAssembly.get_ManagedConstraints()
at ThisRule.SetHost(IRulesHost host)
at Autodesk.iLogic.Exec.AppDomExec.ExecRuleInAssembly(Assembly assem)
at iLogic.RuleEvalContainer.ExecRuleEval(String execRule)
This must be occurring at compilation, because I put a "MsgBox("Debug")" in as the VERY first line of code inside the rule, and it doesn't even pop up. What's more, I am not USING "ThisAssembly" anywhere in my code.
Can someone clarify what is happening here?