Modifying features without recreating them

Modifying features without recreating them

loster.mcleod
Explorer Explorer
875 Views
5 Replies
Message 1 of 6

Modifying features without recreating them

loster.mcleod
Explorer
Explorer

I am trying to modify an extrude feature after it has been created. Specifically, changing the profile of the extrude.

 

During creation we use ExtrudeFeatureInput to specify the extrude parameters, but when the extrude feature is already created, how do we change the existing feature?

 

It doesn't work the way I'm trying, maybe there's a way that can work without recreating the body?

 

This is what I'm trying to do:

extrude = extrudes->itemByName("ExtrudeName");

extrude->profile(newProfile);

 

 

0 Likes
876 Views
5 Replies
Replies (5)
Message 2 of 6

BrianEkins
Mentor
Mentor

Here's a simple script that demonstrates changing the profile used for an extrusion.  The main thing to remember is that you're still under all the constraints as when you edit the profile in the user-interface.  Primarily that the sketch the profile is from must exist in the timeline before the extrude.

 

To edit the extrusion to point to a different profile, you have to roll the timeline back to before the extrusion.  This happens automatically in the UI when you edit a feature.  In the API you have to explicitly do it.  It's demonstrated in the script.

def run(context):
    try:
        app = adsk.core.Application.get()
        ui = app.userInterface
        des = adsk.fusion.Design.cast(app.activeProduct)
        root = des.rootComponent

        msgResult = ui.messageBox('Yes = Create\nNo = Edit', 'Create or Edit', 
                                  adsk.core.MessageBoxButtonTypes.YesNoButtonType)
        if msgResult == adsk.core.DialogResults.DialogYes:
            sk = root.sketches.add(root.xYConstructionPlane)
            circles = sk.sketchCurves.sketchCircles
            circles.addByCenterRadius(adsk.core.Point3D.create(0,0,0), 2)
            circles.addByCenterRadius(adsk.core.Point3D.create(5,0,0), 1)

            prof = sk.profiles.item(0)
            extrude = root.features.extrudeFeatures.addSimple(prof, 
                                adsk.core.ValueInput.createByReal(5), 
                                adsk.fusion.FeatureOperations.NewBodyFeatureOperation)
            extrude.name = 'Test Extrude'
        else:           
            extrude = root.features.extrudeFeatures.itemByName('Test Extrude')

            sk = extrude.profile.parentSketch
            prof = sk.profiles.item(1)

            tl = des.timeline
            currentPstn = tl.markerPosition
            extrude.timelineObject.rollTo(True)
            extrude.profile = prof
            tl.markerPosition = currentPstn
    except:
        if ui:
            ui.messageBox('Failed:\n{}'.format(traceback.format_exc())) 
---------------------------------------------------------------
Brian Ekins
Inventor and Fusion 360 API Expert
Website/Blog: https://EkinsSolutions.com
0 Likes
Message 3 of 6

loster.mcleod
Explorer
Explorer

Wow! Thank you so much, I will try this!!

 

0 Likes
Message 4 of 6

loster.mcleod
Explorer
Explorer

Unfortunately, it doesn't seem to work.

 

I do this now, but the profile is still not selected and the extrude feature is in yellow (warning) in the timeline.

Sketch1 is created before the extrude feature. Sketch1->profiles()->count() is 1.

 

extrude->timelineObject()->rollTo(true);
extrude->profile(sketch1->profiles()->item(0));

0 Likes
Message 5 of 6

loster.mcleod
Explorer
Explorer

Maybe this is related to the CPP API?? I was missing core.lib and some other libs that I had to download from a package on here.. They date from april 19th. Could that be the problem? If so, where are those new libraries?

 

I reinstalled fusion and now have the most recent libraries, but still not working.

0 Likes
Message 6 of 6

loster.mcleod
Explorer
Explorer

I have a work-around, but it seems there's an issue in the api.

I created a second sketch and make a profile in the new one. After that, I never have issues to change the profile of the extrude.

 

So I have sketch1, create the extrude. I now run my add-in again, create sketch2 instead and bind the profile to the extrude. I then rerun the add-in, recreate sketch2 with the same name, and no problem.

 

So it looks like I have to never delete anything in the sketch and simply rollback the timeline and recreate the sketch.

0 Likes