I have an iAssembly called ExampleiAssembly.iam with multiple members in it's table(EX: ExampleiAssembly1, ExampleiAssembly2, ExampleiAssembly3, etc). I can use the subroutine in my rule below called, "ThisWorks()" to change the member. I want to be able to open ExampleiAssembly.iam from the parts list in ExampleiAssembly1.idw which references ExampleiAssembly.iam and then set the active table member to ExampleiAssembly1. The code I have written below in "ThisBreaks()" does open the iAssembly but I get an error when it tries to run "iPart.ChangeRow("", oMember)". I'm not sure what the issue is here but I suspect its to do with starting the rule from the IDW. Any advice or help would be greatly appreciated.
This is the error I get when I run the rule from an ExampleiAssembly1.idw:
Error Message
Error in rule: TestRule, in document: ExampleiAssembly1.idw
Unable to cast COM object of type 'Inventor._DocumentClass' to interface type 'Inventor.AssemblyDocument'. This operation failed because the QueryInterface call on the COM component for the interface with IID '{29F0D465-C114-11D2-B77F-0060B0F159EF}' failed due to the following error: No such interface supported (Exception from HRESULT: 0x80004002 (E_NOINTERFACE)).
More Info
System.InvalidCastException: Unable to cast COM object of type 'Inventor._DocumentClass' to interface type 'Inventor.AssemblyDocument'. This operation failed because the QueryInterface call on the COM component for the interface with IID '{29F0D465-C114-11D2-B77F-0060B0F159EF}' failed due to the following error: No such interface supported (Exception from HRESULT: 0x80004002 (E_NOINTERFACE)).
at iLogic.iPartRowChanger.GetIFactory(Document doc)
at iLogic.iPartRowChanger.ChangeIRow(Document doc, Object rowSpec)
at ThisRule.ThisBreaks()
at ThisRule.Main()
at Autodesk.iLogic.Exec.AppDomExec.ExecRuleInAssembly(Assembly assem)
at iLogic.RuleEvalContainer.ExecRuleEval(String execRule)
This is my rule "TestRule"
Sub main()
Dim app As Inventor.Application = ThisApplication
Dim oDoc As Document = app.ActiveDocument
If oDoc.DocumentType = DocumentTypeEnum.kAssemblyDocumentObject Then
Call ThisWorks()
Else If oDoc.DocumentType = DocumentTypeEnum.kDrawingDocumentObject Then
Call ThisBreaks()
End If
End Sub
Private Sub ThisWorks()
Dim app As Inventor.Application = ThisApplication
Dim oDoc As Document = app.ActiveDocument
Dim oMember As String = "ExampleiAssembly1"
iPart.ChangeRow("", oMember)
End Sub
Private Sub ThisBreaks()
Dim app As Inventor.Application = ThisApplication
Dim oDoc As DrawingDocument = app.ActiveDocument
Dim oSheet As Sheet = oDoc.ActiveSheet
Dim oPartsList As PartsList = oSheet.PartsLists(1)
Dim oMember As String = ThisApplication.ActiveDocument.FullDocumentName
' Extract the filename from the full filename.
oMember = Right$(oMember, Len(oMember) - InStrRev(oMember, "\"))
' Remove extension
oMember = Left$(oMember, InStrRev(oMember, ".")-1)
MsgBox(oMember)
ThisApplication.Documents.Open(oPartsList.ReferencedDocumentDescriptor.FullDocumentName, True)
iPart.ChangeRow("", oMember)
End Sub
Solved! Go to Solution.
Solved by Mac_W. Go to Solution.
I found a solution, the issue was that "iPart.ChangeRow" uses "ThisDoc" which would be set to the IDW and not the IAM. I read on another post that calling a VBA macro resets "ThisDoc" so I tried passing args from iLogic to VBA then back to iLogic and it worked.
external iLogic Rule to Run on IDW:
Sub Main()
Dim app As Inventor.Application = ThisApplication
Dim oDoc As DrawingDocument = app.ActiveDocument
Dim oSheet As Sheet = oDoc.ActiveSheet
Dim oPartsList As PartsList = oSheet.PartsLists(1)
Dim oMember As String = ThisApplication.ActiveDocument.FullDocumentName
' Extract the filename from the full filename.
oMember = Right$(oMember, Len(oMember) - InStrRev(oMember, "\"))
' Remove extension
oMember = Left$(oMember, InStrRev(oMember, ".")-1)
MsgBox(oMember)
ThisApplication.Documents.Open(oPartsList.ReferencedDocumentDescriptor.FullDocumentName, True)
InventorVb.RunMacro(
"ApplicationProject", ' projectName
"Module13", ' moduleName
"SendMember", ' macroName
oMember) ' the first argument we pass to the VBA macro
End Sub
VBA Macro
Sub SendMember(oMember As String)
Dim oArguments As NameValueMap
Set oArguments = ThisApplication.TransientObjects.CreateNameValueMap
oArguments.Add "arg1", oMember
Call RunIlogic("iAssyChangeRow", oArguments)
End Sub
Public Sub RunIlogic(ByVal RuleName As String, oArgs As NameValueMap)
Dim iLogicAuto As Object
Dim oDoc As Document
Set oDoc = ThisApplication.ActiveDocument
If oDoc Is Nothing Then
MsgBox "Missing Inventor Document"
Exit Sub
End If
Set iLogicAuto = GetiLogicAddin(ThisApplication)
If (iLogicAuto Is Nothing) Then Exit Sub
iLogicAuto.RunExternalRuleWithArguments oDoc, RuleName, oArgs
End Sub
Function GetiLogicAddin(oApplication As Inventor.Application) As Object
Set addIns = oApplication.ApplicationAddIns
'Find the add-in you are looking for
Dim addIn As ApplicationAddIn
On Error GoTo NotFound
Set addIn = oApplication.ApplicationAddIns.ItemById("{3bdd8d79-2179-4b11-8a5a-257b1c0263ac}")
If (addIn Is Nothing) Then Exit Function
addIn.Activate
Set GetiLogicAddin = addIn.Automation
Exit Function
NotFound:
End Function
External Ilogic Rule "iAssyChangeRow"
Sub Main()
Dim oMember As String = RuleArguments("arg1")
iPart.ChangeRow("", oMember)
ThisApplication.ActiveDocument.Close(True)
End Sub
Can't find what you're looking for? Ask the community or share your knowledge.