×
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

How do you loop through a multi-level assembly using catvba

How do you loop through a multi-level assembly using catvba

How do you loop through a multi-level assembly using catvba

(OP)
Hi,

I am trying to formulate a loop in catvba to basically count the children of each branch of a loaded specification tree. I know Root is level 0....and the level converges to n as the branches also have smaller branches. I want to count the children in all specification tree branches (to the level n). All I can think of right now are nested loops to the nth degree and I always end up going back to square one since the loop diverges away from the starting point of branching.

Has anyone out there done something like this? I think I am going about this the wrong way.

======================================================================
Root
|
|_catproduct
| |
| |_catpart
| |
| |_catproduct
| |
| |_catpart
| |
| |_catpart
|
|_catproduct
|
|_catpart
|
|_catproduct
|
|_catpart
|
|_catpart
=====================================================

RE: How do you loop through a multi-level assembly using catvba

What you need to do is to create a recursive loop. Each product in the tree has a 'products' collection object. What you can do is check the count of products in the collection. If the count is zero, then it's something like a CATPart. If the count is not zero, then it's a product with children. At that point you call the subroutine again from within itself.

The general strategy I used was something like this:
>Start the macro and run it on a product.
>Call a subroutine to do stuff, using that product as a reference argument.
>Within the subroutine test if the product has children products.
>If there are children products, then call the same subroutine again using the current product as a reference argument.

There's an example code like this in another post:
Link
This macro was created to edit the properties of each part and assembly within the tree. It's basic, but seems to work pretty well if you're just doing simple work. It can be a good starting point for lots of other things.

Hope that helps,
Mark

RE: How do you loop through a multi-level assembly using catvba

(OP)
Thanks Mark!

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