How to get the participating bodies of an extrudefeature

Anonymous

How to get the participating bodies of an extrudefeature

Anonymous
Not applicable

Hello,

 

I'm developing an add-in that at a certain point cuts trough multiple bodies, by extruding a profile. I need to know which bodies are cut, for further actions.

 

This is the code I'm using for extruding:

 

			sketch = occ.component.sketches.itemByName('Sparing')
			prof = sketch.profiles.item(1)
			distance = adsk.core.ValueInput.createByString("1000 mm")
			extrude = occ.component.features.extrudeFeatures.addSimple(prof, distance, adsk.fusion.FeatureOperations.CutFeatureOperation)

 

I have a hard time to find the participating bodies of the extrudeFeatures command. I found the "bodies" property, but that property only recognizes the body of the parentComponent, while there are multiple other bodies being cut (in other components). The "participantBodies" property is also not what I'm looking for. That property serves as an input, rather than an output.

 

Actually, I'm looking for the bodies being shown in the "Objects to Cut" section in the edit feature dialogue (of the just created extrude features):

 

Naamloos.png

Could anyone please help me out?

 

Thanks in advance!

0 Likes
Reply
Accepted solutions (2)
824 Views
5 Replies
Replies (5)

kandennti
Mentor
Mentor
Accepted solution

Hi Jellej.

 

I haven't tried it, but I think there's probably no way to know.


This is an idea I came up with.
・Acquire the volume of all bodies in advance.
 ↓
・Actually extrude.
 ↓
・Obtain a body whose volume has changed.
 ↓
・Return before execution

 

Go back and delete on the timeline.
https://help.autodesk.com/view/fusion360/ENU/?guid=GUID-9d25e8b0-926d-4183-ab46-42f2045242ff 

   timeline_var.moveToPreviousStep()
   timeline_var.deleteAllAfterMarker()


If you do undo command.

   cmd = ui.commandDefinitions.itemById('UndoCommand')
   cmd.execute()
0 Likes

Anonymous
Not applicable

I already feared that, but that is quite a creative and neat workaround!

 

But there is one problem, which is probably just my amateurism: My design has a lot of bodies. In order to make this code run fast, i should only acquire the bodies inside a certain (sub)component. Therefore, I should be able to get the parentComponent of the parentComponent of the extrude. But I can't find a way to make this happen. I'm looking for something like this (extrude.parentComponent.parentComponent), but can't find a solution:

 

			sketch = occ.component.sketches.itemByName('Sparing')
			prof = sketch.profiles.item(1)
			distance = adsk.core.ValueInput.createByString("1000 mm")
			extrude = occ.component.features.extrudeFeatures.addSimple(prof, distance, adsk.fusion.FeatureOperations.CutFeatureOperation)
			ComponentsToCut = extrude.parentComponent.parentComponent

Any suggestions would be highly appreciated!

0 Likes

Anonymous
Not applicable

Nevermind, eventually I decided to just split the fullPathName property. It feels a little abusive, but it is a bulletproof method.

0 Likes

BrianEkins
Mentor
Mentor
Accepted solution

It is possible to get the participating bodies.  Here's a little test I put together.  This is taking advantage of the linkedFeatures property of the ExtrudeFeature object.  The UI is playing some games to simplify things for the user when a feature impacts bodies in multiple components.  What's actually happening is that a unique extrude feature is being created in each component.  However, Fusion knows that these extrude features were created because of the main extrusion and it's only the main extrusion that shows up in the timeline.  If you edit it, the edits are automatically applied to the other extrusions and if you delete it, the other extrusions are automatically deleted.  So, from the UI it appears there is only one extrusion.  However, the API is closer to the internals and represents what's really happening.  The code below goes through each of the linked extrusions and gets the bodies for each one.

 

import adsk.core, adsk.fusion, adsk.cam, traceback

def run(context):
    ui = None
    try:
        app = adsk.core.Application.get()
        ui  = adsk.core.UserInterface.cast(app.userInterface)
        extrudeSel = ui.selectEntity('Select a feature', 'Features')

        if extrudeSel.entity.objectType == adsk.fusion.ExtrudeFeature.classType():
            extrude = adsk.fusion.ExtrudeFeature.cast(extrudeSel.entity)

            resultBodies = []
            
            # Add the bodies for the selected feature.
            body = adsk.fusion.BRepBody.cast(None)
            for body in extrude.bodies:
                resultBodies.append(body)

            linkedExtrude = adsk.fusion.ExtrudeFeature.cast(None)
            for linkedExtrude in extrude.linkedFeatures:
                for body in linkedExtrude.bodies:
                    resultBodies.append(body)

            message = ''
            for body in resultBodies:
                message += '\n' + body.name

            ui.messageBox(message)
        else:
            ui.messageBox('You must select an extrusion.')
    except:
        if ui:
            ui.messageBox('Failed:\n{}'.format(traceback.format_exc()))
---------------------------------------------------------------
Brian Ekins
Inventor and Fusion 360 API Expert
Website/Blog: https://EkinsSolutions.com
1 Like

Anonymous
Not applicable

 That is perfect! I'm also appreciating your explanation about how one extrusion is actually a combination of multiple ones. Very useful, thank you!

0 Likes