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.
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Moving Translating Sketch

Message 1 of 15
3387 Views, 14 Replies

Moving Translating Sketch



i am trying to move a sketch with the python api in Fusion360.


Sofar i tried 


ent = adsk.core.ObjectCollection.create()



transform = adsk.core.Matrix3D.create()

transform.translation = adsk.core.Vector3D.create(10,0,0)


moveSketch = newComp.features.moveFeatures

moveSketch.objectType = "sketch"

moveInput = moveSketch.createInput(ent, transform )




that returns invalid entity type ( i guess i have to set the entity)


than i tryed 


transform = sketch2.transform 

transform.translation = adsk.core.Vector3D.create(100,100,0)

sketch2.move = transform


this did not work eider, no errors and no transform 


any suggestions ?




Tags (2)
Message 2 of 15

To move sketch, you can set the transform of the sketch. Please try the code below.


sketch1 = adsk.fusion.Sketch.cast(ui.activeSelections[0].entity)
transf = sketch1.transform
transf.translation = adsk.core.Vector3D.create(100, 100, 0)
sketch1.transform = transf

Also, sketch only can be transformed in direct modeling, setting the transform will fail in the case where the sketch is parametric.




Message 3 of 15

So could you ellaborate on what direct moddeling versus parametric means in a script context.


I have tried your example it gives me an error on the way that you use to cast sketch1, so i tried it with my sketch object directly and it run through but did not translate the object.


The only way i got it working so far was to collect all curves in the sketch ( when i create them i save them in a variable) and create a ObjectCollection, than i do, trans). 


I tried to build the collection with sketch.sketchCurves, throws me an error saying that the coll is of type core.ptr well i am not a swift user so my understanding of when something becomes a pointer in c++ or not is rather limited. But the whole documentation needs some information about internal types and how that is related to the python typesetting system.


While i was playing with other parts of the Python API i also realised that getting the reference point from the sketch object would give me simular errors, core.ptr instead of core.point3d, so it looks like python becomes a pointer if i do basePnt = sketch.originPoint the swift file also states 

 def _get_originPoint(self) -> "adsk::core::Ptr< adsk::fusion::SketchPoint >" :
        """Returns the sketch point that was automatically created by projecting the origin construction point into the sketch."""
	return _fusion.Sketch__get_originPoint(self)

so this clearly states i get type core.Ptr(fusion.SketchPoint), well yes not exactly of type core.Point3d but it explains the problem with types that i experience, are there helpers to cast back to that types ?


Message 4 of 15

Direct modeling means "Do not capture Design History". Parametric modeling means "Capture Design History".

Right-click on root component, you will see the "Do not capture Design History" or "Capture Design History" command on the context menu.


“Sketch.Transform” is used to gets and sets the transform of the sketch with respect to model space.


“Sketch.Move” is used to moves the specified sketch entities using the specified transform.


The original point retrieved from Sketch is a SketchPoint object. You can get the geometry by calling “SketchPoint.Geometry” or “SketchPoint. worldGeometry”. “SketchPoint.Geometry” returns a Point3D object which provides the position of the sketch point in sketch space. “SketchPoint. worldGeometry” returns a Point3D object which provides the position of the sketch point in world space.



Message 5 of 15

I think there's still an open question here of what it is that you're trying to do.  Here's a quick primer on what a sketch is.  You can think of a sketch as a container that only contains sketch data and is orientated within the model .  It has it's own coordinate system and the geometry it contains is defined relative to that sketch coordinate system.  Typically, the geometry all lies on the X-Y plane and is treated as 2D, but it's not limited to that.  By moving the sketch, everything within the sketch also moves so they stay in the same position relative to the sketch coordinate system.  This is true for sketches created in both the Direct ("Do not capture Design History") and the Parametric ("Capture Design History") modes.


When creating a new sketch you must select a plane (construction plane or planar face) to create the sketch on.  The selected plane defines the X-Y plane of the sketch.  When working in a parametric model, the sketch remembers the plane it was built on and if that plane changes the sketch automatically repositions itself.  The sketch is dependent on that plane and can't be moved independently of the plane.  When working in a direct model, the sketch does not remember the selected plane but only it's orientation in model space.  There is no relationship between the selected plane and the sketch, so if the plane moves the sketch does not change.  However, because the sketch is completely independent you can use the Move command to reposition the sketch within model space.


The contents of a sketch mostly behave the same in parametric or direct models and it's possible to move geometry within the sketch.  Where parametric sketches are different is when you include geometry from outside the sketch.  Then that geometry can't be moved because it has a dependency on the external geometry. 

Brian Ekins
Inventor and Fusion 360 API Expert
Mod the Machine blog
Message 6 of 15



i am using the python api and i wnat to create two sketches 


sketch1 = createSketch(diameter)
sketch2 = createSketch(diameter)

transform = sketch2.transform
transform.translation = adsk.core.Vector3D.create(10,10,0)
sketch2.transform = transform

so the createSketch func creates a sketch into the current component and creates 3 curves inside, diameter is used for the curve diameter.


now i would like to move the second sketch, away, the way that i show in the script does not work, the only thing that seems to work is when i combine the objects inside the sketch inside an objectCollection. But how can i move the whole sketch.

Message 7 of 15

You haven't said if you're working in a parametric design or not.  I think you're probably trying to do this in a parametric design, which is not supported for the reasons I discussed above.  To check, right-clickk on the top node in the browser.  If the command at the bottom says "Do not capture Design History", as shown below, then you're working in a parametric design and it's not possible to move a sketch.




If you are working in a Direct modeling design, then moving a sketch does work.  The code below creates a new document, makes sure it is a Direct modeling design, creates two sketches and moves one of them.


def sketchTransform():
    ui = None
        app = adsk.core.Application.get()
        ui  = app.userInterface
        doc = app.documents.add(adsk.core.DocumentTypes.FusionDesignDocumentType)
        des = adsk.fusion.Design.cast(app.activeProduct)
        des.designType = adsk.fusion.DesignTypes.DirectDesignType

        root = des.rootComponent        
        sk1 = root.sketches.add(root.xYConstructionPlane)
        sk1.sketchCurves.sketchCircles.addByCenterRadius(adsk.core.Point3D.create(0,0,0), 5)

        sk2 = root.sketches.add(root.xYConstructionPlane)
        sk2.sketchCurves.sketchCircles.addByCenterRadius(adsk.core.Point3D.create(0,0,0), 5)

        trans = sk2.transform
        sk2.transform = trans
        if ui:

Brian Ekins
Inventor and Fusion 360 API Expert
Mod the Machine blog
Message 8 of 15

I am working on an script add in, so i don't really know what kind of context if Parametric or Direct, can i decide that from within the script, can i switch back and forth during script excecution, 


anyway since i could move my curves by an ObjectCollection i could also use that way, i am just looking for a way to get all the curves inside my sketch into an objectCollection.


ent = adsk.core.ObjectCollection.create()

# how can i access all curves inside the sketch2 object ?
ent = sketch2.sketchCurves.sketchCircles.item(0)

transform = adsk.core.Matrix3D.create()
transform.translation = adsk.core.Vector3D.create(0,0,thickness)
sketch2.move(ent, transform)

is there an other python API reference as the one at i am really tyred of scrolling.


Message 9 of 15

You should be able to move all of the sketch geometry if you add all of the curves and all of the points to the collection.  There are the exceptions that I mentioned earlier where the sketch geometry has outside dependencies and is controlled by them.  It would be best if you work through your desired workflow interactively in the user-interface to get a better understanding of how Fusion works and what it's limitations are.  Below is a modified version of my previous sample that moves everything in the sketch.

def sketchTransform2():
    ui = None
        app = adsk.core.Application.get()
        ui  = app.userInterface
        doc = app.documents.add(adsk.core.DocumentTypes.FusionDesignDocumentType)
        des = adsk.fusion.Design.cast(app.activeProduct)
        des.designType = adsk.fusion.DesignTypes.DirectDesignType

        root = des.rootComponent        
        sk1 = root.sketches.add(root.xYConstructionPlane)
        sk1.sketchCurves.sketchCircles.addByCenterRadius(adsk.core.Point3D.create(0,0,0), 5)
        ln = sk1.sketchCurves.sketchLines.addByTwoPoints(adsk.core.Point3D.create(1,0,0), adsk.core.Point3D.create(5,4,0))
        ln = sk1.sketchCurves.sketchLines.addByTwoPoints(ln.endSketchPoint, adsk.core.Point3D.create(2,4,0))

        coll = adsk.core.ObjectCollection.create()
        for crv in sk1.sketchCurves:
        for pnt in sk1.sketchPoints:

        transform = adsk.core.Matrix3D.create()
        transform.translation = adsk.core.Vector3D.create(0,0,2)
        sk1.move(coll, transform)
        if ui:

Brian Ekins
Inventor and Fusion 360 API Expert
Mod the Machine blog
Message 10 of 15

Thanks that worked,


did i actually move the sketch.basePoint with that operation , otherwhise scale and rotate would have an offset center.


Secondly is it possible to create a Constructionplane lets say (0,0,-10) from component coordinate center and pass that to sketches.add() ?

Message 11 of 15
in reply to: ekinsb

Hi there. I've been searching this forum but could not find my answer...

I am working in the active sketch and want to rotate a collection of points.

The sketch plane is none of the origin face.


I have tried something like this

However, all these 3D stuff doesn't seem appropriate since I work in 2D.

For instance, the rotation axis.


transformRot = adsk.core.Matrix3D.create()

angleRot= 1         # => radian

normale = adsk.core.Vector3D.create(0,0,1)  #  are these world coordinates or local sketch coordinates?

 returnBoolValue = transformRot.setToRotation(angleRot, normale, NosePoint)

# points is my collection defined earlier via  points = adsk.core.ObjectCollection.create()



It doesn't work...The .setToRotation fails.


By the way

I Also went through the API refernece manual. You should do something like group items by letter . The scrolling is killing! 


Thanks for all.


Message 12 of 15

What do you mean .setToRotation fails? Does it throw an error? If so, what is the error?

Message 13 of 15

I have attached the pict of the error message. To bad you can't copy/ paste the text.

Apparently it is not happy with the point.

Type Error: in matrix3D_setToRotation(self,*Args), argument 4 of type


The point I use is the endpoint of a line and  when I look at the variable "nosePoint" in Spider it says sketchPoint. May be a 3d point is expected ? But I am rotating in a skech !


Anyway, I tried creating a 3Dpoint:

returnBoolValue = transformRot.setToRotation(angleRot, normale, adsk.core.Point3D.create(NosePoint.geometry.x, NosePoint.geometry.y, 0))

This seems to work but the move function fails... (other message attatched)


I think there is a problem between points3D and sketchPoints.

I seems weird that when creating a sketch point I have to use Point3D.create and this indeed gives me a point in the skech plane. It would seem logical that Point3D.create would refer to the world(or the component) origin.
Is there a method for creating sketch points ?


By the way (I am not very familiar with Python) how can I copy the value of a variable from Spider. I have tryed to use the save button on the right but this caused Spider to crash...


Message 14 of 15

It looks like you're not passing a Point3D object to the last argument of .setToRotation. How are you getting the NosePoint? Is it a ConstructionPoint, or a BRepVertex or something?


I can't help you with spider. I only use intellij idea, with my fusion 360 plugin.



Edit: oh, sorry. I didn't fully read your response 🙂


Yeah, I can't see why you're getting that geomImpl error after you corrected the point thing. Strange.

Message 15 of 15
in reply to: franck.gressier

Unfortunately 'Internal Validation Error' tends to be API speak for "something has gone wrong and I'm not going to supply you with any more details."   Often they crop up when an argument isn't precisely what the function expected, but in too find-grained a way for the normal type checking -- something like the right object type with the wrong assemblyContext comes up for me a lot.


Often that means the problem isn't in the snippet that generates the error, but at some earlier stage.  I think that means we need to look at your code a little more broadly to see exactly how you're creating nosePoint and your other collections.  Would you be willing to post the complete script?  Or even better, the simplest version that still produces the error?




As for copying variable values in Spyder, you have at least two options, and almost certainly more.  For simple (i.e. numeric or string types) you can double click the value in the variable explorer, and that makes it editable (including copyable).  You can also type the variable name into the console (that is,  the interactive window in the bottom right where your debug lines "(Pdb)" are appearing) and hit return, and it will respond with the value.


For more complex objects that just gives you the type, so you'd need to probe a specific property of that object in the console, or use a pprint to dump them all at once, as described here.  (As an aside, if you're just trying to save the variable for later use, I really like the pickle module for that).

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