use the API to rotate an ellipse

use the API to rotate an ellipse

kmaccrimmon
Explorer Explorer
626 Views
2 Replies
Message 1 of 3

use the API to rotate an ellipse

kmaccrimmon
Explorer
Explorer

I am new to the fusion 360 API and I could not find any examples of how to rotate an ellipse. Here is the code I have so far.

        app = adsk.core.Application.get()
        ui  = app.userInterface

        design=app.activeProduct
        rootComp=design.rootComponent
        sketches=rootComp.sketches      
        sketch=sketches.add(rootComp.xYConstructionPlane)  
        sketchEllipse = sketch.sketchCurves.sketchEllipses
        #create ellipse    
        centerPoint = adsk.core.Point3D.create(0,0,0)
        vector=adsk.core.Vector3D.create(0,0,0)
        majorAxisPoint = adsk.core.Point3D.create(50,0,0)
        throughPoint = adsk.core.Point3D.create(0,25,0)        
        ellipse = sketchEllipse.add(centerPoint, majorAxisPoint, throughPoint)
        #rotate
        matrix=adsk.core.Matrix3D.create()
        matrix.setToRotation(30,vector,centerPoint)        
        sketch.move(sketch.sketchEllipse,matrix)
 
 
fusion is complaining about the sketchellipse which should be castable to sketchentites. 
Has anyone done this?
 
thanks!

 

0 Likes
Accepted solutions (1)
627 Views
2 Replies
Replies (2)
Message 2 of 3

tykapl.breuil
Advocate
Advocate
Accepted solution

Sketch.move ask for an object collection rather than sketch entities see the documentation here.

Also you can't rotate around a null vector !

Here is the fixed code :

app: adsk.core.Application = adsk.core.Application.get()
ui  = app.userInterface

design = adsk.fusion.Design.cast(app.activeProduct)
rootComp = design.rootComponent
sketches = rootComp.sketches      
sketch: adsk.fusion.Sketch = sketches.add(rootComp.xYConstructionPlane)  
sketchEllipse = sketch.sketchCurves.sketchEllipses
# create ellipse    
centerPoint = adsk.core.Point3D.create(0,0,0)
vector = adsk.core.Vector3D.create(0,0,1)
majorAxisPoint = adsk.core.Point3D.create(50,0,0)
throughPoint = adsk.core.Point3D.create(0,25,0)        
ellipse = sketchEllipse.add(centerPoint, majorAxisPoint, throughPoint)
# rotate
matrix: adsk.core.Matrix3D = adsk.core.Matrix3D.create()
matrix.setToRotation(30,vector,centerPoint)
objColl: adsk.core.ObjectCollection = adsk.core.ObjectCollection.create()
objColl.add(ellipse)  
sketch.move(objColl, matrix)
Message 3 of 3

kmaccrimmon
Explorer
Explorer

tykapl.breuil,

 

 it worked for me.  

 

I realized the rotation function needed radians so I updated to:

matrix.setToRotation(math.radians(90),vector,centerPoint)
 
thank you!!
 
Keith