This failure is as-designed. You'll see this with most of the features whenever you try to query or edit the entities that were provided as input when the feature was created. You can still get the entities but you need to roll the timeline back to just before the feature you're querying was created. This is because the input entities are only guaranteed to exist at that point in time.
The best example to illustrate this is the fillet feature. If you try to query for edges that were input to the fillet feature after the fillet has been created, they can't be returned because they were consumed by the fillet feature and no longer exist. However, if your roll back the timeline to just before the fillet feature, the edges are now available again.
I know you weren't creating a fillet but similar cases can exist with any feature. In most cases, it's not the feature you created that would consume the inputs, but subsequent features could. It's also possible that the input entities do still exist, but Fusion doesn't check for that and plays it safe by forcing a roll back.
This is the same behavior you see in the UI too. Whenever you edit a feature, Fusion rolls the timeline back to a point just before that feature existed. You can now edit the input and then clicking OK, which moves the timeline back to where it was. Here's how to do it in code.
def run(context):
ui = None
try:
app = adsk.core.Application.get()
ui = app.userInterface
des = adsk.fusion.Design.cast(app.activeProduct)
root = des.rootComponent
sk = root.sketches.add(root.xYConstructionPlane)
circle = sk.sketchCurves.sketchCircles.addByCenterRadius(adsk.core.Point3D.create(0,0,0), 5)
prof = sk.profiles.item(0)
ext = root.features.extrudeFeatures.addSimple(prof, adsk.core.ValueInput.createByString('2 in'), adsk.fusion.FeatureOperations.NewBodyFeatureOperation)
filletInput = root.features.filletFeatures.createInput()
edges = adsk.core.ObjectCollection.create()
edges.add(ext.bodies.item(0).edges.item(0))
filletInput.addConstantRadiusEdgeSet(edges, adsk.core.ValueInput.createByString("0.5 in"), False)
fillet = root.features.filletFeatures.add(filletInput)
# Get the current position of the stop node in the timeline.
position = des.timeline.markerPosition
# Roll the timeline to before the feature to edit.
fillet.timelineObject.rollTo(True)
# Edit the feature
edgeSet = adsk.fusion.ConstantRadiusFilletEdgeSet.cast(fillet.edgeSets.item(0))
edges = adsk.core.ObjectCollection.create()
edges.add(ext.bodies.item(0).edges.item(0))
edges.add(ext.bodies.item(0).edges.item(1))
edgeSet.edges = edges
# Move the node to the original position.
des.timeline.markerPosition = position
except:
if ui:
ui.messageBox('Failed:\n{}'.format(traceback.format_exc()))
---------------------------------------------------------------
Brian EkinsInventor and Fusion 360 API Expert
Website/Blog:
https://EkinsSolutions.com