Message 1 of 3
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
Seeing as how the coil functions aren't available in the API even though all the info is in the help files, I have created a script for a plain spiral using height and pitch to basically create a spring.
I am then trying to create a sweep along the path of the spiral.
The problem is the FeatuersOperation, an error occurs that I don't understand.
Any help greatly appreciated.
Thank you.
This was hacked from Brian Ekins Archimedean spiral code.
import adsk.core
import adsk.fusion
import traceback
import math
ui = None
try:
app = adsk.core.Application.get()
ui = app.userInterface
des = adsk.fusion.Design.cast(app.activeProduct)
root = des.rootComponent
# Create a new sketch.
sketch = root.sketches.add(root.xYConstructionPlane)
# Create points on the spiral
pnts = adsk.core.ObjectCollection.create()
# Convert to inches
diam = .9 * 2.54
height = 3 * 2.54
pointsPerRev = 10
pitch = .2 * 2.54
rad = diam / 2
y = 0
z = 0
pnts.add(adsk.core.Point3D.create(rad, y, z))
angle = 360 / pointsPerRev
newAngle = angle
for i in range(pointsPerRev * round(height / pitch) + 5😞
calcAngle = newAngle * math.pi / 180
x = rad * math.cos(calcAngle)
y = rad * math.sin(calcAngle)
z += pitch / pointsPerRev
pnts.add(adsk.core.Point3D.create(x, y, z))
newAngle = newAngle + angle
path = sketch.sketchCurves.sketchFittedSplines.add(pnts)
crossSketch = root.sketches.add(root.xZConstructionPlane)
rectLines = crossSketch.sketchCurves.sketchLines
center = pnts[0]
crossRectangle = rectLines.addCenterPointRectangle(center, adsk.core.Point3D.create(center.x + .105, center.y + .05, center.z))
prof = crossSketch.profiles.item(0)
sweeps = root.features.sweepFeatures
sweepInput = sweeps.createInput(prof, path, adsk.fusion.FeatureOperations.NewBodyFeatureOperation)
sweep = sweeps.add(sweepInput)
except:
if ui:
ui.messageBox('Failed:\n{}'.format(traceback.format_exc()))
Brad Bylls
Solved! Go to Solution.