Create a plane and set the X direction

Create a plane and set the X direction

brad.bylls
Collaborator Collaborator
753 Views
2 Replies
Message 1 of 3

Create a plane and set the X direction

brad.bylls
Collaborator
Collaborator

SpringPlane.jpg

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

What I am trying to do is create a plane that is perpendicular to Surface 1 and parallel to Line 1

Line 2 is perpendicular to Surface 1 and Line 1.

Then I need for the X direction to be parallel to line 1 so I can create a CenterPointRectangle at Point 1 on the new plane with the long edge parallel to Line 1.

I am creating a spring/coil with a rectangular cross section that can be done on ANY planar surface.

I am not finding any samples or good documentation that cover this.

Any help would be great.

Thank you.

Brad Bylls
0 Likes
Accepted solutions (1)
754 Views
2 Replies
Replies (2)
Message 2 of 3

kandennti
Mentor
Mentor
Accepted solution

Hi @brad.bylls .

 

I created a sample that creates a composition plane by selecting a flat surface and a sketch line.

 

Using the two vectors, the plane object is created with the Plane.createUsingDirections method.

https://help.autodesk.com/view/fusion360/ENU/?guid=GUID-296f19c8-4889-44c1-8529-9bd1e5fba5a9 

 

Since the two vectors must be orthogonal, the crossProduct method is used.

https://help.autodesk.com/view/fusion360/ENU/?guid=GUID-40d9f46c-8767-4d69-96ca-e5dfba569184 

 

ConstructionPlaneInput.setByPlane is used to create the construction plane. In the case of parametric mode, it can be created by using baseFeature.

https://help.autodesk.com/view/fusion360/ENU/?guid=GUID-0617e8da-d860-4a39-be2b-27ab2e223a53 

 

# Fusion360API Python script

import traceback
import adsk.cam
import adsk.fusion
import adsk.core

def run(context):
    ui: adsk.core.UserInterface = None
    try:
        app: adsk.core.Application = adsk.core.Application.get()
        ui = app.userInterface

        # PlanarFace
        msg: str = 'Select Planar Face'
        selFiltter: str = 'PlanarFaces'
        sel: adsk.core.Selection = selectEnt(msg, selFiltter)
        if not sel:
            return
        face: adsk.fusion.BRepFace = sel.entity

        # SketchLine
        msg = 'Select Sketch Line'
        selFiltter = 'SketchLines'
        sel: adsk.core.Selection = selectEnt(msg, selFiltter)
        if not sel:
            return
        line: adsk.fusion.SketchLine = sel.entity

        # face normal
        point: adsk.core.Point3D = face.pointOnFace
        eva: adsk.core.SurfaceEvaluator = face.evaluator
        normal: adsk.core.Vector3D
        _, normal = eva.getNormalAtPoint(point)
        normal.normalize()

        # line vector
        sPoint: adsk.core.Point3D = line.startSketchPoint.worldGeometry
        ePoint: adsk.core.Point3D = line.endSketchPoint.worldGeometry
        lineVec: adsk.core.Vector3D = sPoint.vectorTo(ePoint)
        lineVec.normalize()

        # parallel check
        if normal.isParallelTo(lineVec):
            msg = 'Abort due to parallel surface normals and lines.'
            ui.messageBox(msg)
            return

        # Get a perpendicular vector, giving priority to the surface normal.
        tmpVec: adsk.core.Vector3D = normal.crossProduct(lineVec)
        vDirection: adsk.core.Vector3D = normal.crossProduct(tmpVec)
        vDirection.normalize()

        # create plane
        plane3d: adsk.core.Plane = adsk.core.Plane.createUsingDirections(
            sPoint,
            normal,
            vDirection
        )

        comp: adsk.fusion.Component = line.parentSketch.parentComponent

        # create BaseFeature - Parametric Design
        baseFaet: adsk.fusion.BaseFeature = None
        designType = comp.parentDesign.designType
        if designType == adsk.fusion.DesignTypes.ParametricDesignType:
            baseFaet = comp.features.baseFeatures.add()
            baseFaet.startEdit()

        # create ConstructionPlane
        planes: adsk.fusion.ConstructionPlanes = comp.constructionPlanes
        planeIpt: adsk.fusion.ConstructionPlaneInput = planes.createInput()
        planeIpt.setByPlane(plane3d)
        planes.add(planeIpt)

        # finishEdit BaseFeature - Parametric Design
        if designType == adsk.fusion.DesignTypes.ParametricDesignType:
            baseFaet.finishEdit()

    except:
        if ui:
            ui.messageBox('Failed:\n{}'.format(traceback.format_exc()))


def selectEnt(
        msg: str,
        filtterStr: str) -> adsk.core.Selection:

    try:
        app = adsk.core.Application.get()
        ui = app.userInterface
        sel = ui.selectEntity(msg, filtterStr)
        return sel
    except:
        return None

 

Message 3 of 3

brad.bylls
Collaborator
Collaborator

Many thanks kandennti.

Once I figured out how to bring your sample into my code, it works great. 

Brad Bylls
0 Likes