- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
Hello Autodesk Community! This is my first post here, I have been lurking the forums for a few weeks now trying to learn how to automate opening all the IDWs relevant to the production of a product. I want to thank the members of this community for their contributions, I've learned and pasted a lot from here.
Using Inventor Pro 2022 and Vault Basic 2022, this external Ilogic Rule sometimes successfully runs on a top level assembly IDW. For each row in the parts list, the rule opens the ipt or iam referenced and calls OpenVaultIDW which gets and opens the active document's corresponding IDW from the vault; OpenVaultIDW then closes the ipt or iam. If the referenced parts list row is an assembly then after OpenVaultIDW ends, the main sub in this rule calls itself recursively. This code works on some assemblies and does not on others. I am pretty new to VBnet and Ilogic, and am struggling to figure out what is wrong with this code; Any help or advice would be greatly appreciated.
This is the parts list for my example: "Test Assy.idw" both items are sub-assemblies containing multiple parts
ITEM DESCRIPTION QTY PART NUMBER
1 ARM, SUB, FOAM, RH 1 E10804
2 ARM, SUB, FOAM, LH 1 E10818
I get this error after E10804.idw is opened
Error in rule: OpenAll, in document: Test Assy.idw
(Error Message)
Error in rule: OpenAll, in document: Test Assy.idw
Unspecified error (Exception from HRESULT: 0x80004005 (E_FAIL))
(More Info)
System.Runtime.InteropServices.COMException (0x80004005): Unspecified error (Exception from HRESULT: 0x80004005 (E_FAIL))
at System.RuntimeType.ForwardCallToInvokeMember(String memberName, BindingFlags flags, Object target, Int32[] aWrapperTypes, MessageData& msgData)
at Inventor.DrawingBOMRow.get_BOMRow()
at ThisRule.Main()
at ThisRule.DupeCheck()
at ThisRule.Main()
at Autodesk.iLogic.Exec.AppDomExec.ExecRuleInAssembly(Assembly assem)
at iLogic.RuleEvalContainer.ExecRuleEval(String execRule)
This is the rule:
Sub Main()
'Source: https://forums.autodesk.com/t5/inventor-ilogic-and-vb-net-forum/ilogic-parts-list-amp-opening-drawings/td-p/5976549
Dim oDrawDoc As Document = ThisApplication.ActiveDocument
Dim oSheet As Sheet = oDrawDoc.ActiveSheet
Dim oPartList As PartsList
oPartList = oDrawDoc.ActiveSheet.PartsLists.Item(1)
Dim drawBomRow As DrawingBOMRow
Dim refDoc As Document
For Each oPartListRow In oPartList.PartsListRows 'goes down the parts list if there is one
If oPartListRow.Visible = "True" Then
Try
drawBomRow = oPartListRow.ReferencedRows.Item(1)
refDoc = drawBomRow.BOMRow.ComponentDefinitions.Item(1).Document
FilePath = refDoc.FullFileName()
ThisApplication.Documents.Open(FilePath, True) 'Open next Iam/Ipt on parts list for reference
Dim oDrawDoc2 As Document = ThisApplication.ActiveDocument 'set opened Iam/Ipt as active
Catch
drawBomRow = oPartListRow.ReferencedRows.Item(1)
refDoc = drawBomRow.BOMRow.ComponentDefinitions.Item(1).Document
FilePath = refDoc.FullFileName()
FilePath = Left(FilePath,Len(FilePath)-3) & "idw"
MsgBox(FilePath, "File Not Found")
End Try
End If
DupeCheck()
Next
End Sub
'we need to check if drawing is already open and if it is not then open it
'if already open then we call CopyTab()
Sub DupeCheck()
'source: https://forums.autodesk.com/t5/inventor-ilogic-and-vb-net-forum/ilogic-check-if-drawing-file-is-open/td-p/10243425
Dim oDoc As Document = ThisApplication.ActiveDocument
ThisName = System.IO.Path.GetFileNameWithoutExtension(oDoc.FullFileName)
For Each Doc In ThisApplication.Documents 'check if there is an open IDW with matching doc name
Dim oDC As Document = Doc
If oDC.DocumentType = DocumentTypeEnum.kDrawingDocumentObject And System.IO.Path.GetFileNameWithoutExtension(oDC.FullFileName) = ThisName
oDC.Activate
Call CopyTab() 'copy IDW window to new window
oDoc.Close(True) 'close the reference doc
Exit Sub
End If
Next
If ThisApplication.ActiveDocument.DocumentType = DocumentTypeEnum.kAssemblyDocumentObject Then 'If active doc=Iam, do recursion
iLogicVb.RunExternalRule("C:\Users\xXxXxXx\Desktop\Inventor Macros\OpenVaultIDW") 'opens matching IDW and closes refDoc
Call Main()
Else
iLogicVb.RunExternalRule("C:\Users\xXxXxXx\Desktop\Inventor Macros\OpenVaultIDW") 'opens matching IDW and closes refDoc
End If
End Sub
'copy IDW window to new window
Sub CopyTab()
'source: https://help.autodesk.com/view/INVNTOR/2023/ENU/?guid=GUID-DB8C7D03-9B57-403B-885F-2F2180CBD45A
Dim oDoc2 As Document = ThisApplication.ActiveDocument
Dim oView1 As View
oView1 = oDoc2.Views(1)
Dim oViewTab1 As ViewTab
oViewTab1 = oView1.ViewTab
Dim oView2 As View
oView2 = oDoc2.Views.Add
End Sub
Solved! Go to Solution.