Post news RSS XSI Script: Spring v1

A quick script for automatically generating a spring model along with a set of parameters for making adjustments to it's length, thickness, etc.

Posted by on


Here's a quick script that will automatically generate a Spring mesh. You can either run the script to generate the spring, or save the result as a model and load that.

I decided to post this as an article instead of a download as it's currently a bit unpolished, and just in a text-script format. Future iterations will make it even easier to use, but for now you can export the result to a .mdl to reload in a scene for quicker use.



CreatePrim "Cube", "MeshSurface"
CreatePrim "Spiral", "NurbsCurve"
Rotate , -90, 0, 0, siRelative, siGlobal, siObj, siXYZ, , , , , , , , 0
Translate , -4.06163782374669, 0, 0, siRelative, siView, siObj, siXYZ, , , , , , , , , , 0
ActivateObjectSelTool
ActivateObjectSelTool
SelectObj "cube", , True
SetValue "cube.cube.length", 1.582
ActivateRaycastPolySelTool
ActivateRaycastPolySelTool
SelectGeometryComponents "cube.poly[0]"
ApplyTopoOp "ExtrudeComponent", "cube.poly[0];spiral", siUnspecified, siPersistentOperation
SetValue "cube.polymsh.extrudecomponentop.subdivs", 10
GetPrim "Null"
SetValue "null.Name", "Spring"
SelectObj "spiral"
CopyPaste "spiral", , "Spring", 1
SelectObj "cube"
CopyPaste "cube", , "Spring", 1
AddProp "Custom_parameter_list", , , "Spring_Controls"
SelectObj "cube.Spring_Controls"
SIAddCustomParameter "cube.Spring_Controls", "Spring_Length", siDouble, 0, , 80, , 2053, , 80
SIAddCustomParameter "cube.Spring_Controls", "Spring_Thickness", siDouble, 0, , 8, , 2053, , 8
SIAddCustomParameter "cube.Spring_Controls", "Spring_Subdivisions", siDouble, 0, , 400, , 2053, , 400
SelectObj "spiral"
SetValue "spiral.spiral.height", 3.226
SetValue "spiral.spiral.height", 1
SetValue "cube.Spring_Controls.Spring_Length", 1
CopyPaste "cube.Spring_Controls.Spring_Length", , "spiral.spiral.height", 1
SetValue "spiral.spiral.startangle", 1
SetValue "spiral.spiral.startangle", 0
SetValue "spiral.spiral.endradius", 4
SetValue "spiral.crvlist.geom.subdivu", 24
SelectObj "cube.polymsh.extrudecomponentop"
CopyPaste "spiral.crvlist.geom.subdivu", , "cube.polymsh.extrudecomponentop.subdivs", 1
SetValue "cube.Spring_Controls.Spring_Subdivisions", 24
CopyPaste "cube.Spring_Controls.Spring_Subdivisions", , "spiral.crvlist.geom.subdivu", 1
SetValue "cube.Spring_Controls.Spring_Length", 2.581
SetValue "cube.Spring_Controls.Spring_Length", 1
SIAddCustomParameter "cube.polymsh.extrudecomponentop", "Start Radius", siDouble, 0, , 20, , 2053, , 20
SIAddCustomParameter "cube.polymsh.extrudecomponentop", "Start Radius", siDouble, 4, , 20, , 2053, , 20
SIAddCustomParameter "cube.polymsh.extrudecomponentop", "Start_Radius", siDouble, 4, , 8, , 2053, , 8
SelectObj "cube.Spring_Controls"
SetValue "PlayControl.In", 1
SetValue "PlayControl.Out", 100
SIAddCustomParameter "cube.Spring_Controls", "Start_Radius", siDouble, 4, , 12, , 2053, , 12
SIAddCustomParameter "cube.Spring_Controls", "End_Radius", siDouble, 4, , 12, , 2053, , 12
CopyPaste "cube.Spring_Controls.Start_Radius", , "spiral.spiral.startradius", 1
CopyPaste "cube.Spring_Controls.End_Radius", , "spiral.spiral.endradius", 1
SIAddCustomParameter "cube.Spring_Controls", "Start Angle", siDouble, 0, , 7200, , 2053, , 7200
SIAddCustomParameter "cube.Spring_Controls", "End_Angle", siDouble, 540, , 7200, , 2053, , 7200
CopyPaste "cube.Spring_Controls.End_Angle", , "spiral.spiral.endangle", 1
CopyPaste "cube.Spring_Controls.Start_Angle", , "spiral.spiral.startangle", 1
SelectObj "cube"
SelectObj "cube.Spring_Controls"
SetValue "cube.Spring_Controls.Spring_Thickness", 1.5
CopyPaste "cube.Spring_Controls.Spring_Thickness", , "cube.cube.length", 1
SelectObj "cube"
SetValue "Spring.cube.Name", "Spring"


While unpolished, using this script is still pretty simple:


Spring Length:
Controls the length/height of the spring
Spring Thickness:
Controls the thickness of the mesh
Spring Subdivisions:
Adds more subdivisons to the spring. You'll probably want to increase this if you increase the length or number of rotations
Radius:
Controls the radius of the spring. Probably don't want to touch this (you can always scale later). Keep these numbers identical for a standard spring shape (no taper)
End Angle:
Controls how many rotations are in the Spring

Freeze and rename spring when done.


Post a comment
Sign in or join with:

Only registered members can share their thoughts. So come on! Join the community today (totally free - or sign in with your social account on the right) and join in the conversation.