How to give angle between two line in api

How to give angle between two line in api

sHubamyadav016
Enthusiast Enthusiast
420 Views
2 Replies
Message 1 of 3

How to give angle between two line in api

sHubamyadav016
Enthusiast
Enthusiast

Write a code for given cordinate are (10,34,0) and (11,56,0) and angle between them id 120 how can i write in fusion 360 api python script 

0 Likes
421 Views
2 Replies
Replies (2)
Message 2 of 3

BrianEkins
Mentor
Mentor

I'm not sure exactly what you want to do, but here is a guess and an example. It uses two different techniques to compute a new line, that is the specified angle to the existing line. One example uses basic math to compute the endpoint of the second line. The other uses the Fusion Matrix3D object to do it. One isn't better than other. I think the best is whatever way makes the most sense to you so you can maintain the code later. Change the value of the variable "technique" between 1 and 2 to have is change how it computes the second line.

 

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

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

        sk = root.sketches.add(root.xYConstructionPlane)
        lines = sk.sketchCurves.sketchLines

        angle = (120 * math.pi)/180
        pnt1 = adsk.core.Point3D.create(10, 34, 0)
        pnt2 = adsk.core.Point3D.create(11, 56, 0)
        line1 = lines.addByTwoPoints(pnt1, pnt2)

        technique = 2
        
        if technique == 1:
            rise = pnt2.y - pnt1.y
            run = pnt2.x - pnt1.x
            if math.fabs(run) <= 0.00001:
                # Handle a vertical line.
                if rise > 0:
                    lineAngle = math.pi / 2
                else:
                    lineAngle = math.pi * 1.5
            else:
                m = rise / run
                lineAngle = math.atan(m)

            newAngle = lineAngle + angle
            pnt3 = adsk.core.Point3D.create(pnt1.x + (line1.length * math.cos(newAngle)), pnt1.y + (line1.length * math.sin(newAngle)), 0)
        elif technique == 2:
            # Create a matrix that defines the rotation around the Z axis and the first point of the line.
            matrix = adsk.core.Matrix3D.create()
            matrix.setToRotation(angle, adsk.core.Vector3D.create(0, 0, 1), pnt1)
            pnt3 = pnt2.copy()
            pnt3.transformBy(matrix)

        # Create the second line.
        line2 = lines.addByTwoPoints(line1.startSketchPoint, pnt3)

        # Compute a midpoint between the endpoints of the line to use for the dimension text.
        midPoint = adsk.core.Point3D.create((pnt2.x + pnt3.x) / 2,
                                            (pnt2.y + pnt3.y) / 2,
                                            (pnt2.z + pnt3.z) / 2)

        # Add the dimension constraint.
        angleDim = sk.sketchDimensions.addAngularDimension(line1, line2, midPoint)
    except:
        if ui:
            ui.messageBox('Failed:\n{}'.format(traceback.format_exc()))  

  

---------------------------------------------------------------
Brian Ekins
Inventor and Fusion 360 API Expert
Website/Blog: https://EkinsSolutions.com
Message 3 of 3

sHubamyadav016
Enthusiast
Enthusiast

SEE I AM ATTACHING A DRAWING I WANT TO MAKE THIS DRAWING CAN YOU TELL ME HOW TO GO FORWARD BECAUSE IN CORNER ANGLE IS THERE PLEASE HELP ME 

0 Likes