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.
objProductCollection is essentially:
CATIA.ActiveDocument.Product.Products where the active document is a CATProduct file.
How do I get the collection of level2 products???
Thank you for this article.
I would like to know how or is it even possible to create a product from other products. The thing is that I need to the apply the GetTechnologicalObject to an objet that contains many products.
Set oInertia = product2.GetTechnologicalObject(“Inertia”)
I would like to replace product2 (which is only one product) by an object object that contains many objects, because my aim is to get the mass and center of gravity of a bunch of products at once.
Tank you for your help
Performing Tutorial 3.1 CATIABasicObjects of the book
CATStructureDesignSample.CATfct and 17 other names of sample files are shown
Dim doc1 As Document
Set doc1 = documents1.Item(1)
Dim partDoc1 As PartDocument
Set partDoc1 = doc1
Error thrown in last line of the code, Run time error ’13’