Generating BOM (bill of material) from CATIA V5

To test this sample you should have installed Pywin32 and start CATIA V5 before running this script.

import win32com.client 
catapp = win32com.client.Dispatch("CATIA.Application") 
doc=catapp.ActiveDocument.Product
product_count = doc.Products.Count 
print "This example prints all Parts and subproducts of \
  a CATProduct up to the 2nd level." 
for products in range(product_count): 
  products = products + 1 
  print doc.Products.Item(products).Name, ":" 
  part_count = doc.Products.Item(products).Products.Count 
  for parts in range(part_count): 
    parts = parts +1 
    print " ", doc.Products.Item(products).Products.Item(parts).Name
For a HTML-generated Bill of materialyou should better use the BOM-generation from CATIA V5:
import win32com.client 
catapp = win32com.client.Dispatch("CATIA.Application") 
doc=catapp.ActiveDocument.Product
doc.Product.ExtractBOM(2, "c:\BOM.html")

Leave a Reply

Your email address will not be published. Required fields are marked *