arc.addByThreePoints script is crashing f360, why?

Anonymous

arc.addByThreePoints script is crashing f360, why?

Anonymous
Not applicable

I'm trying to create a simple sketch script for a homework assignment, and running it in f360 results in a not-so-graceful degradation. I'm unsure about the data types that adsk.core.Point3D.create and the like accepts, so not sure if this is a hang-up. I run the script and can tell that something has happened, since I get an asterisk for my untitled sheet. Sometimes I run it and absolutely nothing happens. I've closed visual studio and f360 hoping it's an issue there. I've commented out each line iteratively to determine where the issue is, and it's in the arc.addByThreePoints code. Help? I don't need the solution, just a point in the right direction. Thank you!

 

Windows 10 v1909

F360: v2.0.9142

Vis Studio v1.50.1

 

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

def run(context):
    ui = None
    try:
        app = adsk.core.Application.get()
        ui  = app.userInterface
        #Grabs the active design
        design = app.activeProduct

        #Get the root component of the active design, i.e. the top item in the browser
        rootComp = design.rootComponent

        #Cast the root component
        rootComp = adsk.fusion.Component.cast(design.rootComponent)

        #Let's create a collection of sketches
        sketches = rootComp.sketches

        #Create a plane to put the sketches in
        xyPlane = rootComp.xYConstructionPlane
        sketch_Coll = sketches.add(xyPlane)

        #Creating sketch objects to work
        lines = sketch_Coll.sketchCurves.sketchLines
        arcs = sketch_Coll.sketchCurves.sketchArcs
        circles = sketch_Coll.sketchCurves.sketchCircles

        #Defining sketch
        xStart = 0
        height = 5
        length = 26

        #Creating top and bottom lines
        lines = sketch_Coll.sketchCurves.sketchLines
        topStartPt = adsk.core.Point3D.create(xStart, height, 0)
        topEndPt = adsk.core.Point3D.create(xStart + length, height, 0)
        bottomStartPt = adsk.core.Point3D.create(xStart, 0, 0)
        bottomEndPt = adsk.core.Point3D.create(xStart + length, 0, 0)
        lines.addByTwoPoints(topStartPt, topEndPt)
        lines.addByTwoPoints(bottomStartPt, bottomEndPt)

        circleHeight = 2.5
        numCircles = 5
        circleSpacing = 6.25
        circleRadius = 1.125
        # Creating Arcs
        #arcs.addByThreePoints(adsk.core.Point3D.create(xStart,0,0),adsk.core.Point3D.create(xStart, circleHeight,0), adsk.core.Point3D.create(xStart, height,0))
        #arcs.addByThreePoints(adsk.core.Point3D.create(xStart+length,0,0),adsk.core.Point3D.create(xStart+length, circleHeight,0), adsk.core.Point3D.create(xStart+length, height,0))

        #For loop to create circles at circle height
        for i in range(numCircles):
            x = i * circleSpacing
            circles.addByCenterRadius(adsk.core.Point3D.create(x,circleHeight,0), circleRadius)
    except:
        if ui:
            ui.messageBox('Failed:\n{}'.format(traceback.format_exc()))

 

0 Likes
Reply
Accepted solutions (1)
464 Views
2 Replies
Replies (2)

BrianEkins
Mentor
Mentor
Accepted solution

Looking at your code it looks like the points your defining for the arc are in a straight line.  The X value of all the points is identical.  Three points in a straight line does not define a valid arc.  You can try this in the UI too.

---------------------------------------------------------------
Brian Ekins
Inventor and Fusion 360 API Expert
Website/Blog: https://EkinsSolutions.com
1 Like

Anonymous
Not applicable

Works now as advertised. Thank you!

0 Likes