Notifications
Clear all

[Closed] Undo Unavailable?

I have a script that loops through a selection of objects and sets the verts Z position to some value… it seems to work fine.

But one thing I noticed is that there is no undo possible after executing the script. Is this just the way it is when looping through many objects or is there a way to get a single undo for the execution of the script? Here’s the code:

(
	local sel = getCurrentSelection()					--returns an array
	for obj in sel do
	(--obj = $ 													--obj is selected object	
		for v = 1 to getNumVerts obj do 				--loop through all the verts
			(
				vert = getVert obj v 						--get the v-th vertex
				vert.z = 0.0 									--change the Z coordinate to 0.0
				setVert obj v vert 							--assign back to the v-th vertex
			)
		update obj) 											--update the mesh
)

Thanks!

6 Replies

i am not sure about why undo becomes unavailable but i do know of another way of doing the same thing heres the code :

(
	 local sel = getCurrentSelection()					
	for obj in sel do
	 (	
		convertToMesh obj 
		my_plane = [0,0,1] -- modify the last parameter with your z value
		meshop.moveVertsToPlane obj #{1..obj.numverts} my_plane 0.0  
		update obj 		
	 )
 )

check if this works

surrounding your code with

with undo on
(

)

usually works.

Thanks for all the ideas! Got it sorted now.

Charles, you script produced an undo (and gave me my working solution) but made the objects disappear entirely… not sure where they went. (Was a plane being created?). Turns out… all I needed to add to my script was:

convertToMesh obj

Dan, unfortunately that didn’t produce an undo… but thanks!

Thanks again.

Another question along this line.

The script works fine for setting ALL verts in a selection of objects to a particular Z position… but what if I wanted to do the same thing to only selected verts in a single, selected object? What would the syntax be for that?

(
 	local sel = getCurrentSelection()					--returns an array
 	for obj in sel do
 	(--obj = $ 													--obj is selected object	
 		for v = 1 to getNumVerts obj do 				--loop through all the verts
 			(convertToMesh obj
 				vert = getVert obj v 						--get the v-th vertex
 				vert.z = 0.0 									--change the Z coordinate to 0.0
 				setVert obj v vert 							--assign back to the v-th vertex
 			)
 		update obj) 											--update the mesh
 )

Thanks!

1 Reply
(@pixel_monkey)
Joined: 11 months ago

Posts: 0

Mesh Vertex Methods[left]getVertSelection <node> [ <modifier_or_index> ] [ name:<name> ]
[/left]
[left]
[/left]
[left]getVertSelection <mesh>
[/left]
[left]Returns the current vertex selection set, or the specified named selection set if the optional name: parameter is specified, as a BitArray. The optional <modifier_or_index> identifies the Edit Mesh or Mesh Select modifier on the given scene object from which the selection BitArray is obtained.
[/left]
[left]FOR EXAMPLE
[/left]
[left]
[/left]
[left]getVertSelection $foo $foo.modifiers[3]
[/left]
[left]
[/left]
[left]If the optional <modifier_or_index> argument is not supplied, the <node> must be an Editable Mesh object and the selection is taken from the top of the modifier stack. If <modifier_or_index> is supplied, it must be either a modifier on the node or a number. If it is a modifier, it must be either an Edit Mesh or a Mesh Select modifier. If it is a number, it is used as an index into the Edit Mesh/Select Modifiers on the <node> starting from the top of the stack.
So get your vertselection as a bitarray and convert to an array (bitarray as array). Now loop through the array entries and set the vertex position as desired. NOTE: This will only work if the converttomesh doesn’t alter the selection.

-Eric
[/left]

Thanks Eric! That sorted it.