How is best to create a plane on a spline path?

How is best to create a plane on a spline path?

MichaelAubry
Autodesk Autodesk
949 Views
3 Replies
Message 1 of 4

How is best to create a plane on a spline path?

MichaelAubry
Autodesk
Autodesk

Hi!  I'm continuing to build out my fibonacci script. It takes input values now!  I'm trying to make the program create a loft along a centerline but I'm getting stuck at creating the planes along the path I'll need to make loft profiles.  Can you take a look at my code?

 

Here's what I'm working towards:

fib6.jpg

 

Thank you!

Mike

 

import adsk.core, adsk.fusion

 

app= adsk.core.Application.get()

design = app.activeProduct

ui = app.userInterface

 

#**Default User Inputs**

steps = "5 cm" #How many steps of Fibonacci would you like to plot?

#(Note, while the steps variable should be unitless, right now our API can't handle unitless number.

#cm are the absolute units we use on the API side.)

length = "3 cm" #How long is the first segment? (cm)

 

input = steps

createInput = ui.inputBox('Enter Steps', 'Steps', input)

if createInput[0]:

(input, isCancelled) = createInput

unitsMgr = design.unitsManager

realSteps = unitsMgr.evaluateExpression(input, unitsMgr.defaultLengthUnits)

 

input = length

createInput = ui.inputBox('Enter Length', 'Length', input)

if createInput[0]:

(input, isCancelled) = createInput

realLength = unitsMgr.evaluateExpression(input, unitsMgr.defaultLengthUnits)

 

#Get root component

rootComp = design.rootComponent

#Create a new sketch on XY plane

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

 

# Create an object collection for the points.

points = adsk.core.ObjectCollection.create()

 

# R = total steps to be run thru the For loop

R = int(realSteps - 2)

 

#starting x and y coordiantes

x = 0

y = 0

 

#Create 1st coordinate

points.add(adsk.core.Point3D.create(x,y,0))

 

#starting values for sequence

fib = 1

fib1 = 1

 

#Create 2nd coordinate

x = 1 * realLength

points.add(adsk.core.Point3D.create(x,y,0))

ui.messageBox('x: ' + str(x))

 

#bins for shifting x and y coordinates

Bin1 = range(0,R,4)

Bin2 = range(1,R,4)

Bin3 = range(2,R,4)

Bin4 = range(3,R,4)

 

for i in range(R):

fib2 = fib + fib1

fib = fib1

fib1 = fib2

fibLength = fib*realLength #adds the scalar component to coordinates

ui.messageBox('fiblength: ' + str(fibLength))

 

if i in Bin1:

x = x

y = y + fibLength

points.add(adsk.core.Point3D.create(x,y,0))

if i in Bin2:

x = x - fibLength

y = y

points.add(adsk.core.Point3D.create(x,y,0))

if i in Bin3:

x = x

y = y - fibLength

points.add(adsk.core.Point3D.create(x,y,0))

if i in Bin4:

x = x + fibLength

y = y

points.add(adsk.core.Point3D.create(x,y,0))

 

# Create the spline.

sketch.sketchCurves.sketchFittedSplines.add(points)

 

# Create the Planes for the loft

spline1 = sketch.sketchCurves.sketchFittedSplines.item(0)

plane1 = rootComp.ConstructionPlaneInput.setByDistanceOnPath.add(spline1,0)

Michael Aubry
Autodesk Fusion 360 Evangelist
Accepted solutions (2)
950 Views
3 Replies
Replies (3)
Message 2 of 4

xiaohui.wang
Explorer
Explorer
Accepted solution

Hi Michael,

 

Please have a try to replace 'plane1 = rootComp.ConstructionPlaneInput.setByDistanceOnPath.add(spline1,0)' with the following code .

 

    planeInput = rootComp.constructionPlanes.createInput() # you could also specify the occurrence in the parameter list

    planeInput.setByDistanceOnPath(spline1, adsk.core.ValueInput.createByReal(0))

    plane1 = rootComp.constructionPlanes.add(planeInput)

 

Besides, loft feature hasn't been included in the API yet. Sorry for the inconvenience.

 

Thanks,

Xiaohui





Xiaohui Wang

SW Engineer
Message 3 of 4

MichaelAubry
Autodesk
Autodesk
Accepted solution

Success!  Thanks so much. Your soluiton worked like a charm.  

 

plane on face.jpg

 

Thanks for the warning that we don't have loft from the API yet.  Thats's okay. I'll just set the script up to get to that point.

 

Thank you!

Mike

Michael Aubry
Autodesk Fusion 360 Evangelist
0 Likes
Message 4 of 4

MichaelAubry
Autodesk
Autodesk

For those following the thread, here's what the final solution ended up as.

 

Gallery Post: https://fusion360.autodesk.com/projects/horn-of-fibonacci

Code: https://github.com/MichaelAubry/Fusion360.git

Video: 

 

Big thanks to Brian, Xiaohui, and Casey for helping with this!

 

Best,

Mike

Michael Aubry
Autodesk Fusion 360 Evangelist
0 Likes