Notifications
Clear all

[Closed] Undo in script

Hello,
I have created a script useful for me (moves vertexes by the specified value)
The problem is returning with ctrl + z
When I try to go back wertexy do not go back to the state before the change but it only happens when I use the buttons in the script. What is the reason and how can I fix this error ? Here is source of my script

rollout newRollout "Move Vertex" width:200 height:200
(
    button bnt1 "Y +0,3" pos:[10,35] width:100 height:40
    on bnt1 pressed do
    (
        $.modifiers[#Edit_Poly].MoveSelection  [0,0,0.3]
		$.modifiers[#Edit_Poly].Commit ()
    )
		button bnt2 "Y -0,3" pos:[132,35] width:100 height:40
    on bnt2 pressed do
    (
        $.modifiers[#Edit_Poly].MoveSelection  [0,0,-0.3]
		$.modifiers[#Edit_Poly].Commit ()
    )
		button bnt3 "X +0,3" pos:[10,80] width:100 height:40
    on bnt3 pressed do
    (
        $.modifiers[#Edit_Poly].MoveSelection  [0.3,0,0]
		$.modifiers[#Edit_Poly].Commit ()
    )
		button bnt4 "X -0,3" pos:[132,80] width:100 height:40
    on bnt4 pressed do
    (
        $.modifiers[#Edit_Poly].MoveSelection  [-0.3,0,0]
		$.modifiers[#Edit_Poly].Commit ()
    )
)
bntThing = newrolloutfloater "Move Vertex" 250 150
addrollout newRollout bntThing
7 Replies
rollout newRollout "Move Vertex" width:200 height:200
(
    button bnt1 "Y +0,3" pos:[10,35] width:100 height:40
    on bnt1 pressed do with undo "Move Selection Y +0,3" on
    (
        $.modifiers[#Edit_Poly].MoveSelection  [0,0,0.3]
		$.modifiers[#Edit_Poly].Commit ()
    )
		button bnt2 "Y -0,3" pos:[132,35] width:100 height:40
    on bnt2 pressed do undo "Move Selection Y -0,3" on
    (
        $.modifiers[#Edit_Poly].MoveSelection  [0,0,-0.3]
		$.modifiers[#Edit_Poly].Commit ()
    )
		button bnt3 "X +0,3" pos:[10,80] width:100 height:40
    on bnt3 pressed do undo "Move Selection X +0,3" on
    (
        $.modifiers[#Edit_Poly].MoveSelection  [0.3,0,0]
		$.modifiers[#Edit_Poly].Commit ()
    )
		button bnt4 "X -0,3" pos:[132,80] width:100 height:40
    on bnt4 pressed do undo "Move Selection X -0,3" on
    (
        $.modifiers[#Edit_Poly].MoveSelection  [-0.3,0,0]
		$.modifiers[#Edit_Poly].Commit ()
    )
)
bntThing = newrolloutfloater "Move Vertex" 250 150
addrollout newRollout bntThing

Thanks for help ! Nice to learn smt new + for you.

why buttons are named “Y …” if they move verts on Z?

This is the test version, the name of the button does not matter. It’s important that it works

@miauu
Hey. I have found a error in my script and dont know how to solve it. For example I have 2 object with quad chamfer – I add edit poly on 2 object and select vertex and when I try to use script I get this error. What this mean ?

$ represent currently selected object or objects. When you have only one object selected then you can use $ as you use it in your code. But when you have two or more selected objects you can’t use $ as you use it now.
Use this as a reference.

rollout newRollout "Move Vertex" width:200 height:200
(
    button bnt1 "Y +0,3" pos:[10,35] width:100 height:40
    on bnt1 pressed do with undo "Move Selection Y +0,3" on
    (		
		if (selObjsArr = selection as array).count != 0 do
		(
			for o in selObjsArr do
			(
				o.modifiers[#Edit_Poly].MoveSelection  [0,0,10]
				o.modifiers[#Edit_Poly].Commit ()
			)
		)
       
    )
		
)
bntThing = newrolloutfloater "Move Vertex" 250 150
addrollout newRollout bntThing

Thanks, works now I’ll gona learn more and more about scripting in 3ds max. + for you.