Create Plane from sketch profile

Create Plane from sketch profile

rocco.mayr
Enthusiast Enthusiast
666 Views
1 Reply
Message 1 of 2

Create Plane from sketch profile

rocco.mayr
Enthusiast
Enthusiast

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()))
0 Likes
Accepted solutions (1)
667 Views
1 Reply
Reply (1)
Message 2 of 2

rocco.mayr
Enthusiast
Enthusiast
Accepted solution

Ok sorry guys, I missed the sample 🙂

https://help.autodesk.com/view/fusion360/ENU/?guid=GUID-c4edd2d2-aea3-11e5-98bc-f8b156d7cd97

 

 # Get the profile
prof = sketch.profiles.item(0)

# Get construction planes
planes = rootComp.constructionPlanes
        
# Create construction plane input
planeInput = planes.createInput()
        
# Add construction plane by offset
offsetValue = adsk.core.ValueInput.createByReal(0)
planeInput.setByOffset(prof, offsetValue)
planeOne = planes.add(planeInput)
0 Likes