Bill Of Material Part count in Product Assembly
Bill Of Material Part count in Product Assembly
(OP)
Hi Everyone
I write billof material VB code.My code is working but if I have subAssambly parts ,code is note count exactly.so how can I count my sub Assambly parts.
lNumberOfItems = oTopProduct.Products.Count
For i = 1 to lNumberOfItems
http://i.hizliresim.com/a3kGRg.jpg
https://res.cloudinary.com/engineering-com/image/upload/v1462516829/tips/catia_count_owyjm0.bmp
I write billof material VB code.My code is working but if I have subAssambly parts ,code is note count exactly.so how can I count my sub Assambly parts.
lNumberOfItems = oTopProduct.Products.Count
For i = 1 to lNumberOfItems
http://i.hizliresim.com/a3kGRg.jpg
https://res.cloudinary.com/engineering-com/image/upload/v1462516829/tips/catia_count_owyjm0.bmp





RE: Bill Of Material Part count in Product Assembly
Tesak
http://scripts4all.eu/txtoncurve/ - Curved text for Catia V5
RE: Bill Of Material Part count in Product Assembly
RE: Bill Of Material Part count in Product Assembly
Tesak
http://scripts4all.eu/txtoncurve/ - Curved text for Catia V5
RE: Bill Of Material Part count in Product Assembly
CODE --> vba
Option Explicit Sub CountParts() Dim prod Dim bom Set prod = catia.ActiveDocument.product Set bom = CreateObject("Scripting.Dictionary") ' ParseAssyTree prod, bom Dim key For Each key In bom.Keys Debug.Print key, bom(key) Next End Sub Sub ParseAssyTree(prod, dict) Dim pr For Each pr In prod.Products If dict.Exists(pr.PartNumber) Then dict(pr.PartNumber) = dict(pr.PartNumber) + 1 Else dict.Add pr.PartNumber, 1 End If ParseAssyTree pr, dict Next End SubHOW IT WORKS?
At first it creates bom dictionary and then it recursively calls ParseAssyTree routine which fills bom with part numbers. If part number does not exists in bom it is created and initialized with number 1, otherwise it is just increased by one. In the end you go through bom dictionary and print its keys and values (so part numbers and counts)
Tesak
http://scripts4all.eu/txtoncurve/ - Curved text for Catia V5
RE: Bill Of Material Part count in Product Assembly
Dim oTopProduct As Product
Dim oTopProduct As Product
Dim oDictionary
Set oTopProductDoc = CATIA.ActiveDocument
Set oTopProduct = oTopProductDoc.Product
Set oDictionary = CreateObject("Scripting.Dictionary")
lNumberOfItems = oTopProduct.Products.Count
i = 0
For i = 1 To lNumberOfItems
Set ItemToRename = oTopProduct.Products.Item(i)
ItemToRename.PartNumber = ItemToRename.PartNumber
If oDictionary.Exists(ItemToRename.PartNumber) = True Then
oDictionary.Item(ItemToRename.PartNumber) = oDictionary.Item(ItemToRename.PartNumber) + 1 Else
oDictionary.Add (ItemToRename.PartNumber), 1
End If
RE: Bill Of Material Part count in Product Assembly
Tesak
http://scripts4all.eu/txtoncurve/ - Curved text for Catia V5