Spiral help needed

Spiral help needed

brad.bylls
Collaborator Collaborator
480 Views
2 Replies
Message 1 of 3

Spiral help needed

brad.bylls
Collaborator
Collaborator

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
0 Likes
Accepted solutions (1)
481 Views
2 Replies
Replies (2)
Message 2 of 3

MichaelT_123
Advisor
Advisor
Accepted solution

Hi Mr Brad Bylls,

 

Consider to look deeper into what path is in:

 

 sweepInput = sweeps.createInput(prof, path, adsk.fusion.FeatureOperations.NewBodyFeatureOperation)

 

Regards

MichaelT

 

MichaelT
0 Likes
Message 3 of 3

brad.bylls
Collaborator
Collaborator

Hello Michael T.

Thanks for the response.

I found this and added it to my code:

 

 thePath = sketch.sketchCurves.sketchFittedSplines.add(pnts)
 path = adsk.fusion.Path.addCurves(self, thePath, 0)
The problem now is, I don't know how to define self to see that it works.
Brad Bylls
0 Likes