×
INTELLIGENT WORK FORUMS
FOR ENGINEERING PROFESSIONALS

Log In

Come Join Us!

Are you an
Engineering professional?
Join Eng-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!
  • Students Click Here

*Eng-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Students Click Here

Jobs

Bill Of Material Part count in Product Assembly

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

RE: Bill Of Material Part count in Product Assembly

Could you please post the whole code? From the snippets and pictures it is really not clear what is going on ...

Tesak
http://scripts4all.eu/txtoncurve/ - Curved text for Catia V5

RE: Bill Of Material Part count in Product Assembly

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
http://scripts4all.eu/txtoncurve/ - Curved text for Catia V5

RE: Bill Of Material Part count in Product Assembly

Try this:

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 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
http://scripts4all.eu/txtoncurve/ - Curved text for Catia V5

RE: Bill Of Material Part count in Product Assembly

(OP)
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

RE: Bill Of Material Part count in Product Assembly

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
http://scripts4all.eu/txtoncurve/ - Curved text for Catia V5

Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Eng-Tips Forums free from inappropriate posts.
The Eng-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Eng-Tips forums is a member-only feature.

Click Here to join Eng-Tips and talk with other members!


Resources