Announcements

The Autodesk Community Forums has a new look. Read more about what's changed on the Community Announcements board.

Array of spline ?

dinocoglitore
Advocate

Array of spline ?

dinocoglitore
Advocate
Advocate

I'm new to Fusion 360 API and object oriented programming. 

It's very interesting. I'm studing the simple examples of the help.

I would like to understand why it's not possible write this kind of code.

Thank you very much.

 

import adsk.core, adsk.fusion, traceback

 

def run(context):

ui = None

try:

 

app = adsk.core.Application.get()

ui = app.userInterface

 

doc = app.documents.add(adsk.core.DocumentTypes.FusionDesignDocumentType)

design = app.activeProduct

 

# Get the root component of the active design.

rootComp = design.rootComponent

 

# Create a new sketch on the xy plane.

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

 

# Create an object collection for the points.

points[0] = adsk.core.ObjectCollection.create()

# Define the points the spline with fit through.

points[0].add(adsk.core.Point3D.create(0, 0, 0))

points[0].add(adsk.core.Point3D.create(5, 1, 0))

points[0].add(adsk.core.Point3D.create(6, 4, 3))

# Create the spline.

spline[0]=sketch.sketchCurves.sketchFittedSplines.add(points[0])

 

# Create an object collection for the points.

points[1] = adsk.core.ObjectCollection.create()

points[1].add(adsk.core.Point3D.create(7, 6, 6))

points[1].add(adsk.core.Point3D.create(2, 3, 0))

points[1].add(adsk.core.Point3D.create(0, 1, 0))

# Create the spline.

spline[1]=sketch.sketchCurves.sketchFittedSplines.add(points[1])

 

except:

if ui:

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

  

 

There is another way to use array of spline ?

Thank you very much.

Dino

 

0 Likes
Reply
Accepted solutions (2)
601 Views
2 Replies
Replies (2)

liujac
Alumni
Alumni
Accepted solution

HI,

 

You need to define empty arrays first, and then append items to the arrays. I made a little change on your script, then it should work.

 

import adsk.core, adsk.fusion, traceback
 
def run(context):
    ui = None
    try:
     
        app = adsk.core.Application.get()
        ui = app.userInterface
         
        doc = app.documents.add(adsk.core.DocumentTypes.FusionDesignDocumentType)
        design = app.activeProduct
         
        # Get the root component of the active design.
        rootComp = design.rootComponent
         
        # Create a new sketch on the xy plane.
        sketch = rootComp.sketches.add(rootComp.xYConstructionPlane)
         
        points = []
        spline = []
        # Create an object collection for the points.
        points.append(adsk.core.ObjectCollection.create())
        # Define the points the spline with fit through.
        points[0].add(adsk.core.Point3D.create(0, 0, 0))
        points[0].add(adsk.core.Point3D.create(5, 1, 0))
        points[0].add(adsk.core.Point3D.create(6, 4, 3))
        # Create the spline.
        spline.append(sketch.sketchCurves.sketchFittedSplines.add(points[0]))
         
        # Create an object collection for the points.
        points.append(adsk.core.ObjectCollection.create())
        points[1].add(adsk.core.Point3D.create(7, 6, 6))
        points[1].add(adsk.core.Point3D.create(2, 3, 0))
        points[1].add(adsk.core.Point3D.create(0, 1, 0))
        # Create the spline.
        spline.append(sketch.sketchCurves.sketchFittedSplines.add(points[1]))
 
    except:
        if ui:
            ui.messageBox('Failed:\n{}'.format(traceback.format_exc()))

 

Thanks,

Jack

0 Likes

dinocoglitore
Advocate
Advocate
Accepted solution

Hi Jack, your solution let me understand that my problem is on Python syntax.

I thank you very much for the answer.

It solved my problem.

 

Dino

0 Likes