Community
Fusion API and Scripts
Got a new add-in to share? Need something specialized to be scripted? Ask questions or share what you’ve discovered with the community.
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

get the active sketch

1 REPLY 1
SOLVED
Reply
Message 1 of 2
rogierweekers
64 Views, 1 Reply

get the active sketch

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
1 REPLY 1
Message 2 of 2

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


Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

Autodesk DevCon in Munich May 28-29th


Autodesk Design & Make Report