Edit Sketch via API

Edit Sketch via API

scottmoyse
Mentor Mentor
1,423 Views
5 Replies
Message 1 of 6

Edit Sketch via API

scottmoyse
Mentor
Mentor

It looks to me like this isn't possible. But I would like to be able to loop through a heap of sketches, then once I find one with a specific attribute, 'select' it for manual editing by the user. 

 

But it looks like in most cases you can't call native Fusion commands on objects you have selected via the API... or am I missing a trick here?


Scott Moyse
Did you find this post helpful? Feel free to Like this post.
Did your question get successfully answered? Then click on the ACCEPT SOLUTION button.


EESignature


RevOps Strategy Manager at Toolpath. New Zealand based.

Co-founder of the Grumpy Sloth full aluminium billet mechanical keyboard project

0 Likes
Accepted solutions (1)
1,424 Views
5 Replies
Replies (5)
Message 2 of 6

BrianEkins
Mentor
Mentor
Accepted solution

You can start ANY command using the API.  However, most commands don't use the current selection or need additional input besides a selection so just starting the command doesn't cause anything to happen except for the command dialog to pop up, waiting for input.  There are a few commands that don't require any input or they do use the active selection and that's enough for them to do whatever they do without requiring any additional input.  The edit sketch command happens to be one of these.  Here's an untested example of how it would work.

sk = root.Sketches.ItemByName('MySketch')
ui.activeSelections.clear()
ui.activeSelections.add(sk)
skCmd = ui.commandDefinitions.itemById('SketchActivate')
skCmd.execute()

 

 

---------------------------------------------------------------
Brian Ekins
Inventor and Fusion 360 API Expert
Website/Blog: https://EkinsSolutions.com
0 Likes
Message 3 of 6

scottmoyse
Mentor
Mentor
Legend. Thanks. I'll give that a try.

Scott Moyse
Did you find this post helpful? Feel free to Like this post.
Did your question get successfully answered? Then click on the ACCEPT SOLUTION button.


EESignature


RevOps Strategy Manager at Toolpath. New Zealand based.

Co-founder of the Grumpy Sloth full aluminium billet mechanical keyboard project

0 Likes
Message 4 of 6

yosef.ali.omar
Participant
Participant

when following this code i get this error the rootLogger object has no occurrence ItemByName I am wondering where I want wrong here is what i used 

 

 

     

 

        sk = root.sketches.ItemByName('Sketch1')
        #Activating SKETCH
        #choose the section sketch as active
        ui.activeSelections.clear()
        ui.activeSelections.add(sk)


        skCmd=ui.commandDefinitions.itemById('SketchActivate')
        skCmd.execute()

 

0 Likes
Message 5 of 6

kandennti
Mentor
Mentor

Hi @yosef.ali.omar .

 

This is due to the fact that the first letter of the method name is capitalized.

sk = root.sketches.itemByName('Sketch1')
Message 6 of 6

yosef.ali.omar
Participant
Participant
Thank you, yes that fixed it
0 Likes