Isolate a selection in Python

Isolate a selection in Python

DVE2000
Contributor Contributor
1,613 Views
4 Replies
Message 1 of 5

Isolate a selection in Python

DVE2000
Contributor
Contributor

The Add-In I'm working on has a selection option in its dialog box:

        selInput0 = inputs.addSelectionInput(
            'select', 'Interior Edges or Solid Bodies',
            'Select the edge interior to each corner, or a body to apply to all internal edges')
        selInput0.addSelectionFilter('LinearEdges')
        selInput0.addSelectionFilter('SolidBodies')
        selInput0.setSelectionLimits(1,0)

The selection is iterated through like this:

        self.edges = []
        bodies = []
        for i in range(inputs['select'].selectionCount):
            entity = inputs['select'].selection(i).entity
            if entity.objectType == adsk.fusion.BRepBody.classType():
                bodies.append(entity)
            elif entity.objectType == adsk.fusion.BRepEdge.classType():
                self.edges.append(entity)

I'd like to get an occurrence of all the selected items so that I can use isIsolated to turn off all other bodies/components/etc  in an assembly so that they don't affected by the cut operations that the script does. How do I create an Occurrence for the selection? Or even how can I just temporarily isolate it?

 

Thanks!

0 Likes
Accepted solutions (1)
1,614 Views
4 Replies
Replies (4)
Message 2 of 5

erik
Advocate
Advocate

If you want to create a new occurrence you can type in:

 

adsk.core.Application.get().activeProduct.rootComponent.occurrences.addNewComponent(adsk.core.Matrix3D.create())

If one is in the design workspace, this should add a new occurrence with a new componenten with center point in (0,0,0).

 

The following link show how to copy bodies from one component to another copyPasteBodies you can use cutPasteBodies, to remove them from their original component.

Link: https://help.autodesk.com/view/fusion360/ENU/?guid=GUID-1dad75dc-4bf8-11e7-bf09-005056c00008

 

And the each component has a read/write proporty called isIsolated which can be set to true or false. 

 

I hope this helps and if you have further questions please reply!

 

- Erik

Message 3 of 5

DVE2000
Contributor
Contributor

Thanks Erik!

 

This has given me the answer, I think. I can temporarily move the BrepBodies into the new temporary Component and Occurrence, keeping track of where they were from to return them after the operations. There is a moveToComponent function that's available as well. And BRepBodies have back references to their parent components (parentComponent), so that makes it easy to keep track of for returning them. And an Occurrence has a deleteMe function that I can call too. Hopefully my understanding is correct.

 

0 Likes
Message 4 of 5

DVE2000
Contributor
Contributor

I did manage to move the bodies into a new occurrence, but the problem was moving them back. Also, turning off isIsolated didn't show the other components. So I decided to just iterate through all components and turn off the ones not containing the selected body:

        for idx in range(0, self.rootComp.allOccurrences.count):
            occ = self.rootComp.allOccurrences.item(idx)
            comp = occ.component
            if (comp not in self.components):
                comp.isBodiesFolderLightBulbOn = False

And this works, and I can turn them on again after the cut operations. In the finished code I would also do something to remember the on/off state and restore that. 

 

The issue is that I really want to get the Occurrence of a selected body. In the first post where I show the code looking for BRepBody, I added

self.components.append(entity.parentComponent)

Looking at the reference manual, I can't see a way to get the particular occurrence for a selection. From the component, I can see all occurrences, but I don't see how to get the specific selected one. How do I go about doing that?

.

0 Likes
Message 5 of 5

DVE2000
Contributor
Contributor
Accepted solution

ExtrudeFeature.participantBodies is what I really needed. Thanks Sam Cuttriss!

0 Likes