Passing SplineShape Knot Selections Up The Stack
When setting a Knot selection using the setKnotSelection method, you are always affecting the base object - the EditableSpline at the bottom of the stack. It is
not directly possible to set the sub-object vertex selection of a specific Edit_Spline modifier using this method. The selection flows up the stack through any existing
Edit_Spline modifiers and changes the sub-object selections of all of them.
In the following example, the script has to select a single vertex at the end of a
SplineShape and link it to an object using a Linked XForm modifier. Then the other
vertex on the other end of the SplineShape has to be linked to a different object
using a second Linked XForm modifier. In result, moving either object should stretch
the spline between the two objects similar to a rope.
Obviously, trying to set the vertex selection for both ends will fail because the
second selection would flow through the whole stack and overwrite the first selection,
resulting in both Linked XForm modifiers affecting the same vertex.
To avoid this, we have to do two things - we will apply the modifiers from top to
bottom instead of adding them on top of each-other, and we will use a SplineSelect
modifier as a "selection blocker" to stop the second sub-object selection from overwriting
the first one.
SCRIPT
|
resetMaxFile #noPrompt
theSphere1= sphere()
theSphere1.pos = [-100,0,0]
theSphere2= sphere()
theSphere2.pos = [100,0,0]
theShape = splineShape()
addnewSpline theShape
addKnot theShape 1 #corner #line [-100,0,0]
addKnot theShape 1 #corner #line [100,0,0]
updateShape theShape
max modify mode --switch to modify panel
select theShape --select the spline
es1 = edit_spline name:"First ES" --create 1st Edit_Spline
addmodifier theShape es1 --add to the TOP of the stack
subobjectLevel = 1 --vertex level...
setKnotSelection theShape 1 #(1) --select first vertex in BASE OBJECT
LX1 = Linked_XForm name:"First XForm" --Add Linked XForm
modPanel.addModToSelection LX1 --Add to the sub-selection
LX1.Control = theSphere1--Set control
sselect = splineselect name:"Blocker" --Add a SplineSelect to stop the flow
addmodifier theShape sselect before:2 --Add it BEFORE the first Edit_Spline!
--Note: Since modifiers are always counted from top to bottom,
--having 2 modifiers on top will place the new modifier before them
--when using "before:2"
es2 = edit_spline name:"Second ES" --Create second Edit_Spline
addmodifier theShape es2 before:3 --Add it BEFORE the SlineSelect "Blocker"
modPanel.setCurrentObject es2 --Set the Modifier stack to it
subobjectLevel = 1 --vertex SO level
setKnotSelection theShape 1 #(2) --select second vertex
--Note that at this point, the selection will flow up until it
--hits the SplineSelect modifier which is set to Object Level and does
--not let the selection pass beyond that point. This preserves
--the selection of vertex 1 in the top Edit_Spline and sets the
--selection in the bottom one to vertex 2.
LX2 = Linked_XForm name:"Second XForm" --create new Linked XForm
modPanel.addModToSelection LX2 --Add on top of the current selection
LX2.Control = theSphere2 --set second control
|