Continue to Site

Eng-Tips is the largest engineering community on the Internet

Intelligent Work Forums for Engineering Professionals

  • Congratulations KootK on being selected by the Eng-Tips community for having the most helpful posts in the forums last week. Way to Go!

MACRO Scripting Get BillOfMaterial from Currently Selected Product Node in Tree

Status
Not open for further replies.

JCReynolds79

Automotive
Sep 6, 2007
115
Hi Folks,

I am pulling my hair out a bit. I want to extract a BOM for a product in a lower portion of the main Product. i.e. a sub-assembly.

Product Tree e.g.:

Product (this is the Window's top level product)
-> Product 1
- -> Product 2
- - -> Product 3
- - - -> Product 4

I created a macro by "recording" the following actions...

1. Double Click on "Product 4" to activate it.
2. Go to Analyze -> Bill of Material... -> Save As... (save somewhere locally).
3. Stop recording.

The created macro looks like this:

Code:
Language="VBSCRIPT"

Sub CATMain()

Set productDocument1 = CATIA.ActiveDocument

Set product1 = productDocument1.Product

Set products1 = product1.Products

Set product2 = products1.Item("Product 1.1")

Set products2 = product2.Products

Set product3 = products2.Item("Product 2.1")

Set products3 = product3.Products

Set product4 = products3.Item("Product 3.1")

Set products4 = product4.Products

Set product5 = products4.Item("Product 4.2")

Set assemblyConvertor1 = product5.GetItem("BillOfMaterial")

Dim arrayOfVariantOfBSTR1(2)
arrayOfVariantOfBSTR1(0) = "Part Number"
arrayOfVariantOfBSTR1(1) = "Revision"
arrayOfVariantOfBSTR1(2) = "Description"
assemblyConvertor1.SetCurrentFormat arrayOfVariantOfBSTR1

assemblyConvertor1.Print "TXT", "C:\Users\me\macros\bom.txt", product5

End Sub

This works fine...BUT as a useful macro, the names of the products are all hard-coded...I want to be able to run this macro, either with the sub-assy already "double-clicked" or prompt user to select in tree and extract its BOM.

The bit I am struggling with is GetItem of the desired sub-assy. I can get a BOM of the very top level easy enough, but cannot figure out how to JUST get the selected lower level sub-assy.

Hope someone can help.

Many thanks.

Regards,

Jon Reynolds
 
Replies continue below

Recommended for you

Hi Ferdo,

We run LCA/VPM here, so I cannot open the sub-assy in its own window, only in context, so I have to be able to select/activate the lower child sub-assy in the tree.

Thanks.

Regards,

Jon Reynolds
 
If I understand well, that means your subassy is in fact a CATIA component and that is why you cannot open in new window.

I believe you will need to create a custom BoM... for example search and select all parts/products/components under your selected node and extract what ever you need from there.

Regards
Fernando

- Romania
- EU
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor