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!

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

Status
Not open for further replies.

Ruky

Aerospace
Sep 19, 2011
26
CA
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
=====================================================
 
Replies continue below

Recommended for you

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
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Top