Message 1 of 6
rotating sketch that is on another plane around ConstractionPlaneAxis
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
On the end of a path sits a plane with a circle:
Now I want to rotate and copy the circle around its basis, so it looks like flowers growing from one Point.
Doing it by hand is no problem:
But in my api-Script only the lines get rotated right. The circles rotate around their plane. This is not what I want.
How can I fix it?
(PS: Workarounds like rotating just the line and draw new planes or the use of pattern feature do not help me, because this ist just a simplified example of a much more complex script where I need to rotate a sketch that way.)
import adsk.core, adsk.fusion, adsk.cam, traceback, math
def run(context😞
ui = None
try:
app = adsk.core.Application.get()
ui = app.userInterface
design = app.activeProduct
root_comp = design.rootComponent
# Create a 3 identical lines.
sketches = root_comp.sketches
xyPlane = root_comp.xYConstructionPlane
sketch = sketches.add(xyPlane)
line = sketch.sketchCurves.sketchLines.addByTwoPoints(adsk.core.Point3D.create(0, 0, 0), adsk.core.Point3D.create(0, 2, 2))
line = sketch.sketchCurves.sketchLines.addByTwoPoints(adsk.core.Point3D.create(0, 0, 0), adsk.core.Point3D.create(0, 2, 2))
line = sketch.sketchCurves.sketchLines.addByTwoPoints(adsk.core.Point3D.create(0, 0, 0), adsk.core.Point3D.create(0, 2, 2))
# create plane on the end of the line
path1 = root_comp.features.createPath(line)
planes = root_comp.constructionPlanes
planeInput = planes.createInput()
one = adsk.core.ValueInput.createByReal(1)
planeInput.setByDistanceOnPath(path1, one)
plane = planes.add(planeInput)
# create 3 identical circles on the plane
sketch1 = sketches.add(plane)
circle = sketch1.sketchCurves.sketchCircles.addByCenterRadius(adsk.core.Point3D.create(0,0,0), 1)
circle = sketch1.sketchCurves.sketchCircles.addByCenterRadius(adsk.core.Point3D.create(0,0,0), 1)
circle = sketch1.sketchCurves.sketchCircles.addByCenterRadius(adsk.core.Point3D.create(0,0,0), 1)
# Try to rotate two circles around root_comp.constructionPlane axis (does not work)
sketch = root_comp.sketches.item(0)
sketch1 = root_comp.sketches.item(1)
objects1 = adsk.core.ObjectCollection.create()
objects1.add(sketch.sketchCurves.item(0)) #that's the line
objects1.add(sketch1.sketchCurves.item(0)) #that's the circle
objects2 = adsk.core.ObjectCollection.create()
objects2.add(sketch.sketchCurves.item(1)) #that's another line
objects2.add(sketch1.sketchCurves.item(1)) #that's another circle
normal = adsk.core.Vector3D.create(0,1,0) #sketch.xDirection.crossProduct(sketch.yDirection)
normal.transformBy(sketch.transform)
origin = sketch.origin
origin.transformBy(sketch.transform)
matrix1 = adsk.core.Matrix3D.create()
matrix2 = adsk.core.Matrix3D.create()
matrix1.setToRotation( 2*math.pi/3, normal, origin)
matrix2.setToRotation(-2*math.pi/3, normal, origin)
sketch.move(objects1, matrix1)
sketch.move(objects2, matrix2)
except:
if ui:
ui.messageBox('Failed:\n{}'.format(traceback.format_exc()))