Message 1 of 2
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
In Fusion 360 you could click on "Construct" -> "Offset Plane" and then select a sketch to create a plane. How could you achieve this with code? I tried to use the sketch.profile, but I don't get how to use it for the plane creation.
Here's the code:
import adsk.core, adsk.fusion, traceback, math
def run(context):
ui = None
try:
app = adsk.core.Application.get()
ui = app.userInterface
# Create a document.
doc = app.documents.add(adsk.core.DocumentTypes.FusionDesignDocumentType)
product = app.activeProduct
design = adsk.fusion.Design.cast(product)
# Get the root component of the active design.
rootComp = design.rootComponent
# Create a sketch that has a rectangle in it
sketches = rootComp.sketches
sketch = sketches.add(rootComp.xZConstructionPlane)
sketchLines = sketch.sketchCurves.sketchLines
point0 = adsk.core.Point3D.create(0, 0, 0)
point1 = adsk.core.Point3D.create(5, 5, 0)
sketchLines.addCenterPointRectangle(point0, point1)
#Rotate Sketch
all = adsk.core.ObjectCollection.create()
for c in sketch.sketchCurves:
all.add(c)
for p in sketch.sketchPoints:
all.add(p)
normal = sketch.yDirection
normal.transformBy(sketch.transform)
origin = sketch.origin
origin.transformBy(sketch.transform)
mat = adsk.core.Matrix3D.create()
mat.setToRotation(math.pi / 8, normal, origin)
sketch.move(all, mat)
## Create Plane from the Sketch Profile
## using Offset Plane with Offset=0
# Get the profile defined by the lines.
prof = sketch.profiles.item(0)
basePlane :adsk.fusion.ConstructionPlane = prof???? # sel.entity
planes :adsk.fusion.ConstructionPlanes = rootComp.constructionPlanes
planeInput :adsk.fusion.ConstructionPlaneInput = planes.createInput()
offsetValue = adsk.core.ValueInput.createByReal(0)
planeInput.setByOffset(basePlane, offsetValue)
planes.add(planeInput)
except:
if ui:
ui.messageBox('Failed:\n{}'.format(traceback.format_exc()))
Solved! Go to Solution.