Custom Sort Error at Top Level Assembly

Custom Sort Error at Top Level Assembly

Zackery.Breeland
Contributor Contributor
695 Views
2 Replies
Message 1 of 3

Custom Sort Error at Top Level Assembly

Zackery.Breeland
Contributor
Contributor

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
		
0 Likes
Accepted solutions (1)
696 Views
2 Replies
Replies (2)
Message 2 of 3

A.Acheson
Mentor
Mentor
Accepted solution

Hi @Zackery.Breeland 

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. 

If this solved a problem, please click (accept) as solution.‌‌‌‌
Or if this helped you, please, click (like)‌‌
Regards
Alan
0 Likes
Message 3 of 3

Zackery.Breeland
Contributor
Contributor

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.

0 Likes