Community
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.
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Unable to create periodic NurbsCurve3D

4 REPLIES 4
SOLVED
Reply
Message 1 of 5
charles-olivier.lamarche
222 Views, 4 Replies

Unable to create periodic NurbsCurve3D

Hi,

I am trying to transfer exported b-splines to Fusion 360 but I am having trouble with periodic b-splines. When the exported data is from a non-periodic one, I have no problems creating it with NurbsCurve3D.createRational. I have put together a sample Python script to represent what I am doing : 

 

 

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

def run(context):

    try:
        # EXPORTED DATA REPRESENTING B-SPLINE
        knots = [
            0.0000000000000000,
            0.0000000000000000,
            0.0000000000000000,
            0.0000000000000000,
            0.25602561235427856,
            0.27728092670440674,
            0.46725389361381531,
            0.73442411422729492,
            1.0000000000000000,
            1.0000000000000000,
            1.0000000000000000,
            1.0000000000000000
        ]

        points = [
                core.Point3D.create(-3.4881881713867191, 5.4675212860107427, 0.62845458984375002),
                core.Point3D.create(-3.4691871643066410, 5.4366035461425781, 0.68925466537475588),
                core.Point3D.create(-3.3454914093017578, 5.4225990295410158, 0.72906799316406257),
                core.Point3D.create(-3.2093914031982425, 5.4284263610839849, 0.73332176208496103),
                core.Point3D.create(-3.0950704574584962, 5.4569847106933596, 0.69166107177734382),
                core.Point3D.create(-3.3419246673583984, 5.6027492523193363, 0.38698616027832033),
                core.Point3D.create(-3.5078979492187501, 5.4995925903320320, 0.56538677215576172),
                core.Point3D.create(-3.4881881713867191, 5.4675212860107427, 0.62845458984375002)
        ]

        weights = [1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0]

        degree = 3

        isClosed = True

        app = core.Application.get()
        root = app.activeProduct.rootComponent

        sketch = root.sketches.add(root.xYConstructionPlane)

        # ---> RuntimeError: 3 : invalid argument knots. <---
        nurbsCurve1 = core.NurbsCurve3D.createRational(points, degree, knots, weights, isClosed)  

        fixedSplines = sketch.sketchCurves.sketchFixedSplines
        fixedSpline = fixedSplines.addByNurbsCurve(nurbsCurve1)

        # Instead I have to use this method to create the curve
        fittedSplines = sketch.sketchCurves.sketchFittedSplines   
        spline = fittedSplines.add(points)
        spline.isClosed = True
        nurbsCurve2 = spline.geometry

        # Harvest nurbsCurve2 parameters (Details in image attachment)
        ok, controlPoints, degree, knots, rational, weights, periodic = nurbsCurve2.getData()

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

 

 

When I use the sketchFittedSpline.add method to create the curve and I look at the underlying NurbsCurve parameters, they are completely changed from the original data of the exported Curve. What I really want is to create a transient NurbsCurve3D object with the createRational method. Why can't I do that with periodic curves ?

 

4 REPLIES 4
Message 2 of 5

Since the multiplicities of the start and end knots are each degree+1, the knot vector is not meant for a periodic curve.  Also, the last parameter for NurbsCurve3D.createRational is isPeriodic, not isClosed.  Changing that value from True to False allows a closed curve to be created.  The read-only isClosed property of the NurbsCurve3D will be True.

Message 3 of 5

*** UPDATE ***
I am now importing cross-sections into Fusion by using the method described in the first message of this post to import all the curves. The only difference is I added an additional step where I project the control points from model space to sketch space to position the cross-section correctly.
Now I am facing a new problem where Fusion doesn't seem to be creating profiles from all the imported curves (that are all closed) . Instead, there are only some of the curves that have profiles created and thus are enabled for extrusion features on them. (Screenshot is in file attachment)
Does anyone know why this is happening ? Thank you !

 

Charles

Message 4 of 5

My guess is there is a small gap somewhere.

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

Hi,

Could you share the model?

I'm thinking about making a script that will generate a selectionSet por each continuos curves, so it will be easier to detect where the discontinuous could be. So I need a model to play with.

 

Regards,

Jorge

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