[Closed] Help with theHold function?
Just wrote a little script that aligns selected verts of an object to the surface of another target object, however I want the whole process to be undoable. Here is the sample code:
(
fn g_filter o = superclassof o == Geometryclass
fn find_intersection z_node node_to_z =
(
local testRay = ray node_to_z [0,0,-1]
local nodeMaxZ = z_node.max.z
testRay.pos.z = nodeMaxZ + 0.0001 * abs nodeMaxZ
intersectRay z_node testRay
)
on isEnabled return selection.count > 0
on Execute do
(
if (theHold.holding() == false) do theHold.begin()
target_mesh = pickObject message:"Pick Target Surface:" filter:g_filter
if isValidNode target_mesh do
(
Selected_verts = ((getvertselection $)as array)
for i = 1 to Selected_verts.count do
(
currentvert = (getvert $ selected_verts[i])
vert_Z = find_intersection target_mesh currentvert
if vert_z != undefined then setVert $ Selected_verts[i] vert_z.pos
update $
)
)
if (theHold.holding() == true) do theHold.accept "Move vert"
)
)
Originally I nested the If isvalidnode statement in an Undo on, but this didn’t seem to work so tried it with theHold instead but this still doesnt seem to register any udo blocks. Any thoughts as to where I may be going wrong.
Thanks,
D.
it’s a macroscript ,right? you don’t need to use THEHOLD. Simply use UNDO
on execute do undo "Whatever" on
(
...
)
only don’t forget to set autoUndoEnabled to OFF…[b][b]
[/b]from mxs help:[/b]
The autoUndoEnabled: parameters controls whether the MacroScript body will be automatically wrapped in a theHold begin/accept calls internally. When set to false, the execution of the MacroScript body will not generate an undo record for the whole MacroScript. When set to true or not specified, the whole MacroScript body will create an undo record when executed. The default value is true.
Yeah it is a macroscript, should also have pointed out the script is running in max 2009 so the autoUndoEnabled is not supported in this version.
Added the undo line to the on execute and this still didn’t resolve the undo problem in itself, however adding a convertToMesh line and now the undo is registering correctly. Thanks.
For undoing vert position changes, I just set them to themselves first, then moved, so when I did ctrl+z, they went back to where they were.
I didn’t know about the autoUndoEnabled though