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,
Solved! Go to Solution.
Solved by ekinsb. Go to Solution.
Solved by ekinsb. Go to Solution.
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()))
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.
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
is it the
ui.commandDefinitions.itemById('FusionComputeAllCommand').execute()
command I need to call to trigger a complete update?
Looks bit like.
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.
Is there anyway to move sketch points by end coordinates to avoid the vector math and eventual rounding errors? Is merge an option?
Thanks,
line1 = sk.sketchCurves.sketchLines.item(0) Selects the first line entity
ptemp = adsk.core.Point3D.create(1.0, 1.0, 0) Creates a point to merge to
sPoint = line1.startSketchPoint
ePoint = line1.endSketchPoint
res = ePoint.merge(ptemp)
This seems to work, but is there a more straightforward way?
line1 = sk.sketchCurves.sketchLines.item(0) #Selects the first line entity
ptemp = sk.sketchPoints.add(adsk.core.Point3D.create(randint(-9,9),0,randint(-9,9)))
sPoint = line1.startSketchPoint
res = ptemp.merge(sPoint)
res = ptemp.deleteMe()
Using a Vector3D and the move method is the way to go. A vector is just used to define the delta difference between the current position and the new position. There aren't any rounding errors to worry about because those calculations are being done as double-precision floating point and are much more accurate than the geometry needs.
If you have an know end point of a line and want to move it to (5,4,0) it could be done something like this.
line1 = sk.sketchCurves.sketchLines.item(0) startPnt = line1.startSketchPoint newPosition = adsk.core.Point3D.create(5,4,0) startPnt.move(startPnt.geometry.vectorTo(newPosition))
Can't find what you're looking for? Ask the community or share your knowledge.