Creation of Plane at Angle

Creation of Plane at Angle

dozerdroid
Enthusiast Enthusiast
659 Views
2 Replies
Message 1 of 3

Creation of Plane at Angle

dozerdroid
Enthusiast
Enthusiast

 

>> note I think I have found a solution see bottom ?

 

Hi, I am currently using code like below to create planes for sketches that are in the XY plane and offset on the Z axis, I have a points array which I use for the sketch in which all of the Z values are on the created XY plane

dozerdroid_0-1679928087114.png

 

 

 

planesObj = hullComponent.constructionPlanes
planeInput = planesObj.createInput()
xyPlane = hullComponent.xYConstructionPlane
planeInput.setByOffset(xyPlane, offsetValue)
plane0 = planesObj.add(planeInput)

 

I now need to perform a similar task except the planes offset along the Z axis will be tilted as per below

dozerdroid_2-1679928264946.png

 

I have not been successful so far in the API doing this so if someone can point me to an example or other help it would be appreciated. I can obviously create the plane manually by creating a plane through three points (all of the points in the array to draw line in the tilted plane) but I need to perform this in the api.

 

Thanks in advance. Khim 

 

Ok I think I have found an answer below ?

 

planeInput.setByThreePoints

 

0 Likes
Accepted solutions (1)
660 Views
2 Replies
Replies (2)
Message 2 of 3

kandennti
Mentor
Mentor
Accepted solution

Hi @dozerdroid .

 

Indeed, a three-point passing plane might be a good idea.

 

I made a sample of creating a plane of three points of passage while creating the points of the sketch.

# Fusion360API Python script

import traceback
import adsk.core as core
import adsk.fusion as fusion
import math

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

        des: fusion.Design = app.activeProduct
        root: fusion.Component = des.rootComponent

        angle = 30 #degrees
        offsetZ = 1 # Z direction offset value
        offsetCount = 10

        # Calculate transit points
        rad = math.radians(angle)
        pnts = [
            core.Point3D.create(0,0,0),
            core.Point3D.create(1, math.cos(rad), math.sin(rad)),
            core.Point3D.create(-1, math.cos(rad), math.sin(rad)),
        ]

        # Sketch creation for reference
        skt: fusion.Sketch = root.sketches.add(root.xYConstructionPlane)
        skt.name = 'Plane Reference'
        skt.isLightBulbOn = False

        sketchPnts: fusion.SketchPoints = skt.sketchPoints

        # Vector for updating transit points
        vec: core.Vector3D = core.Vector3D.create(0, 0, offsetZ)

        for _ in range(offsetCount):
            # reference point creation
            sktPnts = [sketchPnts.add(p) for p in pnts]

            # create plane
            constPlanes: fusion.ConstructionPlanes = root.constructionPlanes

            planeIpt: fusion.ConstructionPlaneInput = constPlanes.createInput()
            planeIpt.setByThreePoints(
                sktPnts[0],
                sktPnts[1],
                sktPnts[2],
            )

            constPlanes.add(planeIpt)

            # Updated transit points
            [p.translateBy(vec) for p in pnts]

        ui.messageBox('Done')

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

1.png

0 Likes
Message 3 of 3

dozerdroid
Enthusiast
Enthusiast

Thank you kandennti