Eng-Tips is the largest engineering community on the Internet

Intelligent Work Forums for Engineering Professionals

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

Macro to expand nested Product into parts? 2

Status
Not open for further replies.

Matt_NM

Automotive
Aug 20, 2018
4
NL
Hi,

I am looking for a macro to help me expand hundreds of products into their parts. To be clear, what I have is a single product(Product A) which contains hundreds of products and parts, each of those products then contains a large number of parts or sometimes further nested products. I want to pull all of the individual parts out from the nested products so that Product A only contains CATParts. Retaining the positioning of the parts may be sometimes needed as well.

Does such a macro exist out there somewhere? Or can somebody help me to create one?

Thank you,

 
Replies continue below

Recommended for you

Depending on how they were modeled, here is a a few steps:
1.Create a new product
2.Click Insert
3.Click Existing Component
4.Navigate to folder that the design is saved in.
5.Sort by Type and select every part in the folder
6.Click Open and it should load every part you have selected into the new product you created.
 
7 open source product
8 read position matrix of all elements
9 apply position matrix to element in new product

Eric N.
indocti discant et ament meminisse periti
 
I wish it would be that easy. Unfortunately, that will not work as in the folder there are many times more parts and products that are not loaded into my product.
 
Save Management the top product into a new folder with all of its parts and perform the steps.
 
Here is the macro you wanted:

Sub CATMain()
dim prd: set prd = CATIA.ActiveDocument.Product
dim sel: set sel = CATIA.ActiveDocument.Selection
sel.Search "CATPrtSearch.PartFeature,all"
dim i, prt, instance, coords(11)
i = sel.Count
do while i > 0
if sel.Item(i).LeafProduct.Parent.Parent.Name < > prd.Name then
set instance = prd.Products.AddComponent(sel.Item(i).Value.Parent.Product)
instance.Name = sel.Item(i).LeafProduct.Name
sel.Item(i).LeafProduct.Position.GetComponents coords
instance.Position.SetComponents coords

set instance = sel.Item(i).LeafProduct
sel.Remove i
sel.Add instance
else
sel.Remove i
end if
i = i - 1
loop
sel.Delete
End Sub
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top