CATProducts in CATIA V5 match up with the object type in VB called the ProductDocument. This is the root object for all development having to do with assemblies.What confuses most people when they start working with the Product Object Model is the fact that every “Product” has a collection of “Products” underneath it. The Root product has a collection of products. Each Product in the collection has its own collection of Products. This structure of Product.Products.Item(1).Products.Item(1)… can go multiple levels deep. The concept is fairly easy though- each product in the tree has a collection of products under it. The collection may be empty (i.e. count=0), but it does exist.

The “Products” collection is just like any other collection. You can loop through the collection You can see how many products are in a sub-assembly using “Count”:

intNumberOfParts = objProductCollection.Count

You can get a specific item of the collection using “Item”:

Set myProduct = objProductCollection.Item(3)

To get the Product Document:
Dim objProductDoc As ProductDocument
Set objProductDoc = CATIA.ActiveDocument

 

Get the Root Product from the Product document:
Dim objRootProduct As Product
Set objRootProduct = objProductDoc.Product

 

Get the collection of level1 products:
Dim objProductCollection As Products
Set objProductCollection = objRootProduct.Products

Continue reading CATIA scripting articles.