Continue to Site

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!

Bill Of Material Part count in Product Assembly

Status
Not open for further replies.

rkncatia

Mechanical
Oct 30, 2014
4
TR
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


[URL unfurl="true"]http://i.hizliresim.com/a3kGRg.jpg[/url]

[URL unfurl="true"]https://res.cloudinary.com/engineering-com/image/upload/v1462516829/tips/catia_count_owyjm0.bmp[/url]
 
Replies continue below

Recommended for you

From what I see you are counting only parts directly below top node. If you wanna count part included in subassemblies you have to go through all children assemblies (and their children) as well. Typical example to apply recursion. If I have time later I will post an example ...

Tesak
- Curved text for Catia V5
 
Try this:

Code:
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 Sub

HOW 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
- Curved text for Catia V5
 
it is my code for this count.My code similar yours code.Where is the my mistake?

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
 
As I told you already, you are counting parts only below top assembly level and you are not going deeper into the structure. In my code function ParseAssyTree is called recursively (ParseAssyTree is calling itself) on every assembly level for every component in the structure.


Tesak
- Curved text for Catia V5
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Top