Finding nested structures and performing a stitching operation

Finding nested structures and performing a stitching operation

PuzzleBoxes
Contributor Contributor
492 Views
1 Reply
Message 1 of 2

Finding nested structures and performing a stitching operation

PuzzleBoxes
Contributor
Contributor

High everyone,

 

I'm working on a model that has about 100+ nested components.

So in my top hierarchy I have 7 component groups, in those component groups I have components or more components groups which at some point have only components. All the single components contain an Origin and Bodies group (folder).

And all the Bodies groups contain an Unstitched group.

 

Now I need to be able to locate/access all the unstitched groups 1 by 1 and stitch every Unstitched group.

 

I know this should be to hard but I couldn't find out how to find nested groups and look for all groups with a specific name.

I know I should be able to look up the name with the name attribute but I first need to be able find/access all the nested groups (folder).

 

I really don't feel like doing this by hand since all 7 of those original component groups have somewhere around 20 components (or nested components) in them.

 

More so I might easily forget one.

0 Likes
493 Views
1 Reply
Reply (1)
Message 2 of 2

PuzzleBoxes
Contributor
Contributor

I've used a crude script to do what I needed to get done for now.

 

From the script I found that I needed to stitch a 132 bodies, no thank you XD. 

 

If someone has a more elegant solution I would love to hear it.

 

//Author-Autodesk Inc.
//Description-Delete empty components from an assembly.
/*globals adsk*/
function run(context) {

    'use strict';

    if (adsk.debug === true) {
        /*jslint debug: true*/
        debugger;
        /*jslint debug: false*/
    }
    
    var ui;
    try {
        
        var app = adsk.core.Application.get();
        ui = app.userInterface;
        
        // Get all components in the active design.
        var product = app.activeProduct;
        var design = adsk.fusion.Design(product);
        var title = 'Stitching all bodies';
        if (!design) {
            ui.messageBox('No active Fusion design', title);
            adsk.terminate();
            return;
        }
        var components = design.allComponents;

        // Find all of the empty components.
        // It is empty if it has no occurrences, bodies, featres, sketches, or construction.
        var root = design.rootComponent;
        var nComponents = components.count;
        var i, component, tel, R;
        tel=0;
        R=0;
        for (i = 0; i < nComponents; ++i) {
            component = components.item(i);

            // Skip the root component.
            if (root.equals(component)) {
                continue;
            }
            
            //Stitch the bodies, 5 is an arbitrary number chosen so that when bodies are already stitched fusion doesn't give an error.
            if (component.bRepBodies.count>5) {
                tel=tel+1;
                
                var features = component.features;
                
                var surfaces = adsk.core.ObjectCollection.create();
                for (R=0; R < component.bRepBodies.count; ++R){
                    surfaces.add(component.bRepBodies.item(R));
                }
                
                // Define tolerance with 1 cm.
                var tolerance = adsk.core.ValueInput.createByReal(0.01);

                // Create a stitch input to be able to define the input needed for an stitch.
                var stitches = features.stitchFeatures;
                var stitchInput = stitches.createInput(surfaces, tolerance, adsk.fusion.FeatureOperations.NewBodyFeatureOperation);

                // Create a stitch feature.
                var stitch = stitches.add(stitchInput);
            }
            
        }

        
        var msg;
        if (tel > 1) {
            msg = 'Bodies stitched '+ tel;
        } else {
            msg = 'NO BODIES TO STICTH FOUND';
        }
        ui.messageBox(msg, title);

    } 
    catch (e) {
        if (ui) {
            ui.messageBox('Failed : ' + (e.description ? e.description : e));
        }
    }

    adsk.terminate();
}

 

 

 

0 Likes