get the active sketch

get the active sketch

rogierweekers
Enthusiast Enthusiast
446 Views
1 Reply
Message 1 of 2

get the active sketch

rogierweekers
Enthusiast
Enthusiast

I have bee searching for a way to edit entries in the active sketch instead of creating a new one, finally found a solution that works. Maybe there is a better way.

this is the code i use in the commandExecuteHandler

 

            #first get a reference to the application
            app = adsk.core.Application.get()
            #get a reference to the active design
            design = adsk.fusion.Design.cast(app.activeProduct)
            #get a collection of all sketches in the active component
            Sketches=design.activeComponent.sketches
            #determin the number of sketches
            SketchCount=Sketches.count
            # Get the active sketch, which is the last one, in the active design
            mySketch = Sketches.item(SketchCount-1)

            # If there is no active sketch, exit the command
            if mySketch is None:
                ui.messageBox('no sketch')
                return
0 Likes
Accepted solutions (1)
447 Views
1 Reply
Reply (1)
Message 2 of 2

john.kirchner
Autodesk
Autodesk
Accepted solution

One other way you can do this is to use the app.activeEditObject property - here's the link to its doc reference https://help.autodesk.com/view/fusion360/ENU/?guid=GUID-ac27a7e8-5c75-45de-9218-152844057096 

So your script could be reduced to

            #first get a reference to the application
            app = adsk.core.Application.get()
            mySketch = adsk.fusion.Sketch.cast(app.activeEditObject)

            # If there is no active sketch, exit the command
            if mySketch is None:
                ui.messageBox('no sketch')
                return