Reply
Observer
2 Posts

Moving Existing Points in an existing sketch

92 Views, 5 Replies
3 weeks ago

There is plenty of examples that create new sketches and points. 

Looking for some sample code on how to move an existing spline point in an existing sketch. This could be really useful for editing existing sketch geometry instead of always creating new, Like in the Fusion gear program I am always having to create a new component instead of editing the existing on. Thanks,

Autodesk Support
1262 Posts
353 Kudos
369 Solutions

Re: Moving Existing Points in an existing sketch

3 weeks ago in reply to: michael.graybar

Here's a very simple program that illustrates the process of moving some points on a spline.  I've also attached the model I used to test this.  The points that the spline goes through are regular sketch points and can be moved and constrained in any way other sketch points can.

 

def run(context):
    try:
        app = adsk.core.Application.get()
        ui = app.userInterface
        des = adsk.fusion.Design.cast(app.activeProduct)
        
        sk = des.rootComponent.sketches.itemByName('Test')
        
        spline = sk.sketchCurves.sketchFittedSplines.item(0)
        pnts = spline.fitPoints
        
        skPnt = pnts.item(1)
        res = skPnt.move(adsk.core.Vector3D.create(-1,2,0))

        skPnt = pnts.item(2)
        res = skPnt.move(adsk.core.Vector3D.create(2,2,0))
        
        ui.commandDefinitions.itemById('FusionComputeAllCommand').execute()
    except:
        if ui:
            ui.messageBox('Failed:\n{}'.format(traceback.format_exc()))

Brian Ekins
Inventor and Fusion 360 API Expert
Mod the Machine blog
Autodesk Support
1262 Posts
353 Kudos
369 Solutions

Re: Moving Existing Points in an existing sketch

3 weeks ago in reply to: michael.graybar

I just realized I was using a pre-production build of Fusion to create the file that I attached so you won't be able to open it.  Here's an equivalent file created with the current Fusion version.


Brian Ekins
Inventor and Fusion 360 API Expert
Mod the Machine blog
Participant
14 Posts

Re: Moving Existing Points in an existing sketch

3 weeks ago in reply to: ekinsb

I used a similar method to modify a simple sketch based on external data. Works fins. But, I couldn't figure a way to get a geometry update for the loft operation based on the sketch.

In UI mode with fusion: any edits of and root sketch result in a recalculation of the resulting body, once you click the 'finish sketch' button. Is there an equivalent to this, something like sketch.finish() in the API?

 

Thanks,

Stefan

Participant
14 Posts

Re: Moving Existing Points in an existing sketch

3 weeks ago in reply to: stefan

is it the

ui.commandDefinitions.itemById('FusionComputeAllCommand').execute()

command I need to call to trigger a complete update?

 

Looks bit like.

Autodesk Support
1262 Posts
353 Kudos
369 Solutions

Re: Moving Existing Points in an existing sketch

2 weeks ago in reply to: stefan

Yes, that is forcing a recompute.  I wasn't sure if it would be needed but found that it was after some testing.  We'll expose this as a method in the API in the future instead of making you execute the command.


Brian Ekins
Inventor and Fusion 360 API Expert
Mod the Machine blog