Fusion API and Scripts
Got a new add-in to share? Need something specialized to be scripted? Ask questions or share what you’ve discovered with the community.
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Bug? createRational and createNonRational NurbsCurve2D

Message 1 of 4
153 Views, 3 Replies

Bug? createRational and createNonRational NurbsCurve2D

Has anyone tried creating a rational or non-rational 2D nurbs curve?  It keeps throwing an "invalid argument controlPoints" runtime error: 3.


 If I'm doing something wrong I just can't see it.  As far as I can determine I'm passing the appropriate Point2DVector for the controlPoints argument. 


createNonRational and createRational functions are supposed to be static functions (according the the API ref manual), and aren't tied to any specific F360 object.  I'm using Pandas to manage the data, but I can't see that being too relevant. 


Any suggestions?  Is this a bug?



        data ='records')

        points = [adsk.core.Point2D.create(row['dist'], row['offset']) for row in data]  #convert data points to 2D points
        knots = [0.0 for x in range(4)] + [x/len(points) for x in range(len(data))] + [1.0 for x in range(5)]
        weights = [ 20 for x in range(len(data))]
        scribeCurveNR = adsk.core.NurbsCurve2D.createNonRational(points, 1, knots, False)
        scribeCurveR = adsk.core.NurbsCurve2D.createRational(controlPoints = points,
                                                             degree = 1,
                                                             knots = knots,
                                                             weights = weights,
                                                             isPeriodic = False)
I'm not an expert, but I know enough to be very, very dangerous.

Life long R&D Engineer (retired after 30+ years in Military Communications, Aerospace Robotics and Transport Automation).
Message 2 of 4
in reply to: pludikar

I'm curious why you want to create a 2D curve. The only place they're used in Fusion is to define the shape of a co-edge in the parametric space of the face that owns it.


However, I successfully used the API to create both a rational and non-rational curve. Because of that, I suspect it's a problem with the data you're using.


import adsk.core, adsk.fusion, traceback

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

        # Get the active design.
        product = app.activeProduct
        design = adsk.fusion.Design.cast(product)
        root = design.rootComponent

        points = []
        points.append(adsk.core.Point2D.create(-4.85267, 0.0))
        points.append(adsk.core.Point2D.create(-4.85267, -4.85267))
        points.append(adsk.core.Point2D.create(0, -4.85267))
        points.append(adsk.core.Point2D.create(4.85267, -4.85267))
        points.append(adsk.core.Point2D.create(4.85267, 0))
        points.append(adsk.core.Point2D.create(4.85267, 4.85267))
        points.append(adsk.core.Point2D.create(0, 4.85267))
        points.append(adsk.core.Point2D.create(-4.85267, 4.85267))
        points.append(adsk.core.Point2D.create(-4.85267, 0))

        degree = 2
        knots = [0.0, 0.0, 0.0, 1.5707963267948966, 1.5707963267948966, 3.141592653589793, 3.141592653589793, 4.71238898038469, 4.71238898038469, 6.283185307179586, 6.283185307179586, 6.283185307179586]
        weights = [1.0, 0.7071067811865476, 1.0, 0.7071067811865474, 1.0, 0.7071067811865477, 1.0, 0.7071067811865476, 1.0]
        isPeriodic = False

        curve = adsk.core.NurbsCurve2D.createRational(points, degree, knots, weights, isPeriodic)
        curve = adsk.core.NurbsCurve2D.createNonRational(points, degree, knots, isPeriodic)
        ui.messageBox("Failed to import image:\n{}".format(traceback.format_exc()), "Error")


Brian Ekins
Inventor and Fusion 360 API Expert
Message 3 of 4
in reply to: BrianEkins



many thanks for that. To satiate your curiosity, I’m attempting to create an edge (or equivalent to a coedge) based on data from a spreadsheet.  I’ve got pieces of board that I want to scribe to a surface, such as a wall or ceiling, - I’ve successfully done it manually, but I now want to speed up the process. I’ve played with doing piecewise linear lines, which worked, but I thought using splines would give me a better result. 

In theory, there should be absolutely no difference between generating a list/vector using comprehensions and creating the list longhand as you’ve done.  I’ll try tomorrow to see if your longhand method yields a different result. When I delve into the point2D vector I create, everything appears normal and well formed.



I'm not an expert, but I know enough to be very, very dangerous.

Life long R&D Engineer (retired after 30+ years in Military Communications, Aerospace Robotics and Transport Automation).
Message 4 of 4
in reply to: pludikar

Hi @BrianEkins,


I've had a chance to play with the NurbsCurves and it appears that the issue is not with the control points but with the knots, or at least with the relationship of controlPoints to knots. 


According to the API reference the number of knots should be >=degree + N + 1.  I've not gone into it in any great detail, but I think that is a mistake!  It appears that it should be =degree + N + 1.  I get the runtime error if the number of knots is !=degree + N + 1.


I would also suggest that the runtime Error of "invalid argument controlPoints" is highly misleading, and should actually be more reflective of the actual issue.  It's like having an error for /0 that throws a Maths error, instead of div by 0.  If there's a way for you to throw both these onto AD's todo list, I think it would help people in the future.


Anyway thanks for your input - there aren't many examples of the creation of NurbsCurves around, and what you provided put me on the right path.




I'm not an expert, but I know enough to be very, very dangerous.

Life long R&D Engineer (retired after 30+ years in Military Communications, Aerospace Robotics and Transport Automation).

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

Autodesk DevCon in Munich May 28-29th

Autodesk Design & Make Report