Application.activeEditObject is a Component not Sketch when editing a sketch during Edit in Place

Application.activeEditObject is a Component not Sketch when editing a sketch during Edit in Place

richard_sim
Contributor Contributor
95 Views
1 Reply
Message 1 of 2

Application.activeEditObject is a Component not Sketch when editing a sketch during Edit in Place

richard_sim
Contributor
Contributor

When you use Edit in Place for a component in an Assembly design, and edit a sketch in that component, Application.activeEditObject remains as a Component, not the Sketch (as would normally happen when you edit a sketch in a regular design). I can't find any other way of identifying the sketch currently being edited (or if one even is being edited).

 

Does anyone have any insight into this behaviour or know of an alternate way of getting the Sketch currently being edited? It feels like a bug, but I have a horrible feeling that it's a "feature" they had to use, to get Edit in Place working, as a workaround for internal limitations.

0 Likes
Accepted solutions (1)
96 Views
1 Reply
Reply (1)
Message 2 of 2

richard_sim
Contributor
Contributor
Accepted solution

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