- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
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:
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)
Autodesk Fusion 360 Evangelist
Solved! Go to Solution.