Created
October 14, 2025 10:35
-
-
Save stephensmitchell/658a538fd423307c4302f8c32c00fb7b to your computer and use it in GitHub Desktop.
Helical spring
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #https://help.alibre.com/articles/#!alibre-help-v28/helical-spring | |
| import sys | |
| import math | |
| # create dialog window | |
| Win = Windows() | |
| Options = [] | |
| Options.append(['Angle Increment', WindowsInputTypes.Real, 0.05]) | |
| Options.append(['Loop Scale', WindowsInputTypes.Real, 0.8]) | |
| Options.append(['Height Scale', WindowsInputTypes.Real, 1.0]) | |
| Options.append(['Major Helix Width Scale', WindowsInputTypes.Real, 2.0]) | |
| Options.append(['Turn Density', WindowsInputTypes.Integer, 25]) | |
| # show dialog window and get values | |
| Values = Win.OptionsDialog('Everyone Loves a Slinky', Options) | |
| if Values == None: | |
| sys.exit('User cancelled') | |
| AngleIncrement = Values[0] | |
| LoopScale = Values[1] | |
| HeightScale = Values[2] | |
| WidthScale = Values[3] | |
| TurnDensity = Values[4] | |
| print 'Angle Increment = %f' % AngleIncrement | |
| print 'Loop Scale = %f' % LoopScale | |
| print 'Height Scale = %f' % HeightScale | |
| print 'Width Scale = %f' % WidthScale | |
| print 'Turn Density = %d' % TurnDensity | |
| # create list of points for 3d sketch | |
| Points = [] | |
| Angle = 0.0 | |
| for Pass in range(0, 437): | |
| X = (WidthScale + LoopScale * math.cos(Angle * TurnDensity)) * math.cos(Angle) | |
| Y = (WidthScale + LoopScale * math.cos(Angle * TurnDensity)) * math.sin(Angle) | |
| Z = HeightScale * Angle + LoopScale * math.sin(Angle * TurnDensity) | |
| Points.extend([X, Y, Z]) | |
| Angle += AngleIncrement | |
| # create part and add 3d sketch | |
| Slinky = Part('Slinky') | |
| Path = Slinky.Add3DSketch('Path') | |
| Path.AddBspline(Points) | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment