So I made a code to run at the top level assembly which would parse through all sub-assemblies and set BOMs based on a template and then Sort and Renumber. I keep getting an unspecified error when I run it at the top level, but it seems to work fine when run at any of the sub-assy levels. The code is below, and it seems like the issue is caused from the Renumber function.
'Define top level assembly as active document Dim oADoc As AssemblyDocument = ThisApplication.ActiveDocument oADocDef = oADoc.ComponentDefinition 'Creating List of all Sub-Assy within Assembly Dim oAssy As Document Dim oAssyList As New List(Of Document) For Each oAssy In oADoc.AllReferencedDocuments If oAssy.DocumentType.Equals(kAssemblyDocumentObject) 'Confirm the assembly is a Job Specific assembly If Left(oAssy.PropertySets.Item(3).Item("Part Number").Value, 1) = "H" Then oAssyList.Add(oAssy) End If End If Next ' Set a reference to the BOM For Each oAssy In oAssyList Dim oBOM As BOM = oAssy.ComponentDefinition.BOM 'Import BOM Order Template to Match GP BOM Required Columns oBOM.ImportBOMCustomization("\\revginc.net\FIRE-GRP\FIRE-HL_Company_Engineering_Docs\Inventor 2013 Files\Templates\Body BOM Order Template.xml") oBOM.StructuredViewEnabled = True oBOM.StructuredViewFirstLevelOnly = False 'Sort BOMs for Vee Drawings (Decription & Length Ascending) Dim oStructuredBOMView As BOMView oStructuredBOMView = oBOM.BOMViews.Item("Structured") Call oStructuredBOMView.Sort("Description", True, "LENGTH", True) Call oStructuredBOMView.Renumber(1,1) Next
Solved! Go to Solution.
Solved by A.Acheson. Go to Solution.
Can you share the error message more Info tab? Is the renumbering partually working? As a work around you could wrap the renumbered process in a try catch and setup an indicater document name or row to identify where it fails.
Below is the More Info tab:
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.BOMView.Renumber(Int32 StartValue, Int32 Increment, Object BOMRowsToRenumber)
at ThisRule.Main()
at Autodesk.iLogic.Exec.AppDomExec.ExecRuleInAssembly(Assembly assem)
at iLogic.RuleEvalContainer.ExecRuleEval(String execRule)
The number and sort seems to be working for every sub-assembly within the top level. But the confusing part is if I open one of the more complex sub-assemblies within the top level and run the same rule it still sorts and numbers the sub-assemblies, does not sort or renumber itself and does not pop up that same error.
Can't find what you're looking for? Ask the community or share your knowledge.