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 EkinsInventor and Fusion 360 API Expert
Website/Blog:
https://EkinsSolutions.com