Undo in script


#1

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

#2
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

#3

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


#4

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


#5

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


#6

@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 ?


#7

$ 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

#8

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