I've found a workaround.
app.activeEditObject (Component; expected Sketch) and app.activeProduct (Design) are "incorrect" during Edit in Place when editing a Sketch, but you can get the correct Design from app.activeEditObject.parentDesign and then get the activeEditObject from that Design. Note that anything in the Sketch will exist in this nested Design (e.g. when using design.findEntityByToken()), not the app.activeProduct Design.
def get_active_sketch() -> adsk.fusion.Sketch | None:
active = app.activeEditObject
if isinstance(active, adsk.fusion.Sketch):
return active
elif isinstance(active, adsk.fusion.Component):
# When Edit in Place is active, the activeEditObject is the component, but we can get the Sketch from the components parent design (which is different than the Design object in app.activeProduct).
comp = adsk.fusion.Component.cast(active)
compDesign = comp.parentDesign
if compDesign and isinstance(compDesign.activeEditObject, adsk.fusion.Sketch):
return compDesign.activeEditObject
return None
def get_active_sketch_design() -> adsk.fusion.Design | None:
active = app.activeEditObject
if isinstance(active, adsk.fusion.Sketch):
product = app.activeProduct
design = adsk.fusion.Design.cast(product)
return design
elif isinstance(active, adsk.fusion.Component):
# When Edit in Place is active, the activeEditObject is the component, but we can get the Sketch from the components parent design (which is different than the Design object in app.activeProduct).
comp = adsk.fusion.Component.cast(active)
compDesign = comp.parentDesign
if compDesign and isinstance(compDesign.activeEditObject, adsk.fusion.Sketch):
return compDesign
return None