Itterates through Each Sub Assembly of a TOP Assm, then Sort & Renumber Structured BOM.

Itterates through Each Sub Assembly of a TOP Assm, then Sort & Renumber Structured BOM.

G.Binl
Advocate Advocate
357 Views
2 Replies
Message 1 of 3

Itterates through Each Sub Assembly of a TOP Assm, then Sort & Renumber Structured BOM.

G.Binl
Advocate
Advocate

Hi all,

I have some code that separately works great.

1. Opens each Sub Assemblies and displays them. (1A &1B) remove (2)

2. Sorts Structured BOM and renumbers them.  (2) remove (1A&1B)

When I merge them no go. It seems to jump right over 2.

Code is below.

GBinl_0-1716499726235.png

open sub assemble

2A before code (2)

2B After Code (2)

GBinl_3-1716500757617.pngGBinl_4-1716500909752.png

 

 

Here is the code.

Dim oDoc As Inventor.Document
Dim oRefDoc As Inventor.Document
Dim oCompDoc As Inventor.Document
  oDoc = ThisApplication.ActiveDocument

For Each oRefDoc In oDoc.ReferencedDocuments
    If oRefDoc.IsModifiable Then
          oCompDoc = ThisApplication.Documents.Open(oRefDoc.FullFileName)
        If oCompDoc.ReferencedDocuments.Count > 0 Then

'xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx			
Dim oAsmDoc As AssemblyDocument
Dim oAsmCompDef As AssemblyComponentDefinition
Dim oBOMView As BOMView
oAsmDoc = ThisDoc.Document
oAsmCompDef = oAsmDoc.ComponentDefinition
oBOMView = oAsmCompDef.BOM.BOMViews.Item("Structured")
oBOMView.Sort("BOM Structure", 0, "Subject", 1, "Description", 1)
'oBOMView.Sort("Item", 1)
oBOMView.Renumber(300)
'xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx


   End If

        oCompDoc.Close
    End If
Next

 

0 Likes
Accepted solutions (2)
358 Views
2 Replies
Replies (2)
Message 2 of 3

A.Acheson
Mentor
Mentor
Accepted solution

Hi @G.Binl 

The issue is using the below line. This is referencing the main assembly you launch the rule from. 

oAsmDoc = ThisDoc.Document

 Use the document object when opened which is oCompDoc

oAsmCompDef = oCompDoc.ComponentDefinition

 Or you actually don't need to open it because it is allready opened in the context of the assembly so just reference the referencedDocument.

oAsmCompDef = oRefDoc.ComponentDefinition

 

 

 

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

G.Binl
Advocate
Advocate
Accepted solution

Thank @A.Acheson  Now I See my Error, Works like a charm. This will allow so much flexibility for what we do. have a great week end. 

0 Likes