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