Extending the Sweep built in shapes
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
I'm trying to create a library of Sweep shapes by expanding the built in list, but I'm having problems getting it to work.
First, I created a new shape type using the plugin simpleSpline system. The script file is in my startup folder, and my new shape appears in the modifier panel under Create -> Shape -> RayScripts as expected. I can choose on my new shape and draw it in the viewport. I have a parameters panel exposed, and adjusting the values causes the shape to redraw properly.
Secondly, I modified the \plugcfg\sweep.ini file to add my custom shape. I added it to the end of the BuiltInSections list in the Global section, and then I defined my shape by cloning the Cylinder entry, renaming it and setting the ClassID to match my plugin simpleSpline.
When I restart Max 2025 and create a new sweep modifier, I see my new shape at the bottom of the list of built in shapes, but selecting it does nothing. It does not use my shape and I don't see any parameter rollouts for my shape. I feel like I'm almost there, but I can't seem to figure out what to do next.
Here's my custom shape code:
plugin simpleSpline splineSegment
name:"Spline Segment"
classID:#(0x52617943, 0x53504C31)
category:"RayScripts"
usePBValidity:true
(
local bezierShapeClass = dotNetClass "Autodesk.Max.MaxPlus.BezierShape"
local splineKnot = dotNetClass "Autodesk.Max.MaxPlus.SplineKnot"
local vector3 = dotNetClass "Autodesk.Max.MaxPlus.Point3"
local bezierKnot = (dotNetClass "Autodesk.Max.MaxPlus.SplineKnot+KnotType").BezierKnot
local curveLine = (dotNetClass "Autodesk.Max.MaxPlus.SplineKnot+LineType").CurveLineType
local initialized = true
fn vec3 xyz = dotNetObject vector3 xyz.x xyz.y xyz.z
fn getSplineKnot pos inVec outVec = dotNetObject splineKnot bezierKnot curveLine (vec3 pos) (vec3 (pos + inVec)) (vec3 (pos + outVec))
fn getPointPlaneProjection pos pTM = pos + dot (pTM.translation - pos) pTM.row3 * pTM.row3
parameters main rollout:params (
segLen default:5 type:#worldUnits animatable:on ui:segLen_spn
on segLen set val do if initialized do this.rebuildShape()
changed default:true type:#boolean invisibleInTV:true
)
fn orient &nodeTM pos = (
local projPos = getPointPlaneProjection pos nodeTM
local x = normalize (projPos - nodeTM.translation)
if keyboard.shiftPressed do case of
(
(abs (dot x x_axis) > abs (dot x y_axis)): x = if dot x x_axis > 0 then x_axis else -x_axis
(abs (dot x y_axis) > abs (dot x x_axis)): x = if dot x y_axis > 0 then y_axis else -y_axis
)
local y = cross nodeTM.row3 x
nodeTM = matrix3 x y (cross x y) nodeTM.translation
projPos
)
fn makeSeg addNext = (
addNext (getSplineKnot [segLen / -2.0, 0, 0] \
[0, 0, 0] \
[0, 0, 0])
addNext (getSplineKnot [segLen / 2.0, 0, 0] \
[0, 0, 0] \
[0, 0, 0])
)
fn rebuildShape = (
local shapeWrapper = bezierShapeClass._CreateWrapperFromFPValue BezierShape
shapeWrapper.NewShape()
local spline = shapeWrapper.NewSpline()
makeSeg spline.AddKnot
shapeWrapper.UpdateSels()
shapeWrapper.InvalidateGeomCache()
changed = false
)
rollout params "Parameters" (
spinner segLen_spn "Segment Length: " range:[1e-9, 1e9, 5] type:#worldUnits align:#right offset:[10,0]
)
tool create numPoints:2 (
local center
on mousePoint click do case click of
(
1: nodeTM.translation = gridPoint
)
on mouseMove click do case click of
(
2: segLen = (distance nodeTM.translation (orient &nodeTM gridPoint)) * 2.0
)
)
on create do initialized = false
on postCreate do initialized = true
on clone orig do segLen = segLen
on buildShape do if changed do rebuildShape()
)
My modification/addition to the sweep.ini
[Global]
BuiltInSections= Angle,Bar,Channel,Cylinder,Half Round,Pipe,Quarter Round,Tee,Tube,Wide Flange,Egg,Ellipse,splineSegment
[splineSegment]
ClassID= 52617943, 53504C31
IconFile=Sweep_DefaultSections
IconIndex=9
NumDefaults= 1
Default1= 0,float,10.000000