Problem with selection

Hi
I made a little script to random in z selected edges. ( like random boards )
It works fine but after using it I can't select another edges and run script as script use selection done before running script.

(
a = $
selE = a.EditablePoly.getSelection #Edge as array
 
	try destroyDialog rlslice catch()
	global rlslice = rollout rlslice "RDM edges on Z" 
	(		
		button butconnect "GO" pos:[2,2]
		spinner spX "MIN " width:90 range:[-10000,10000,-0.5] type:#float pos:[55,5]
		spinner spY "MAX " width:90 range:[-10000,10000,0.5] type:#float pos:[55,25]
 
 
			on butconnect pressed do 
			(	
			undo on
			(
				for ss in selE do
				(
				pp = polyop.getEdgeVerts a ss as array
				ppx1 = a.verts[pp[1]].pos.z
				ppz2 = a.verts[pp[2]].pos.z
				ppx3 = ppx1 + random  spx.value spy.value
 
 
				polyOp.setVert a pp[1]  [  a.verts[pp[1]].pos.x , a.verts[pp[1]].pos.y , ppx3]
				polyOp.setVert a pp[2]  [  a.verts[pp[2]].pos.x , a.verts[pp[2]].pos.y , ppx3]
 
			)
			)
		)
	)	
createDialog rlslice 160 50
 
)

I made a button to get selection to "reset" selection.
But it don't work... anybody can help ?
It is certainly a "$", "selection","$selection","GetCurrentSelection",.... problem ???
Thanks :-)

(
	try destroyDialog rlslice catch()
	global rlslice = rollout rlslice "RDM edges on Y" 
	(
		button butget "get" 
 
		spinner spX "MIN " width:90 range:[-10000,10000,0] type:#float
		spinner spY "MAX " width:90 range:[-10000,10000,0] type:#float
		button butconnect "GO" 
 
		on butget pressed do 
		(
		a=$
		selE = a.EditablePoly.getSelection #Edge as array
		)
 
		on butconnect pressed do 
		(
			undo on
			(
 
				for ss in selE do
				(
				pp = polyop.getEdgeVerts a ss as array
				ppx1 = a.verts[pp[1]].pos.z
				ppz2 = a.verts[pp[2]].pos.z
				ppx3 = ppx1 + random  spx.value spy.value
 
				polyOp.setVert a pp[1]  [  a.verts[pp[1]].pos.x , a.verts[pp[1]].pos.y , ppx3]
				polyOp.setVert a pp[2]  [  a.verts[pp[2]].pos.x , a.verts[pp[2]].pos.y , ppx3]
 
				)
			)
 
		)
	)	
createDialog rlslice 160 150
 
)

Comments

Comment viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.
titane357's picture

my script :move edge

my script :
move edge randomly on z
move each vextex's edge randomly on z
:-)

(
---corrected by MIAUU
	try destroyDialog rlslice catch()
	global rlslice = rollout rlslice "RDM edges on Z" 
	(
		local a = undefined
		local selE = undefined
		spinner spY "VAL " range:[-10000,10000,.1] type:#float width:75  offset:[-55,10]
		spinner spYY "" range:[-10000,10000,.01] type:#float width:70  offset:[10,-21]
		button butconnect "GO" width:90  offset:[0,20]
		on butconnect pressed do 
		(
			undo on
			(
 				a=$
				selE = a.EditablePoly.getSelection #Edge as array
				for ss in selE do
				(
				pp = polyop.getEdgeVerts a ss as array
 
				ppx1 = a.verts[pp[1]].pos.z
				ppx2 = a.verts[pp[2]].pos.z
 
				RDMMAX = random (-spY.value) (spY.value)
 
				ppx11 = ppx1 + ( RDMMAX ) + (random (-spYY.value) (spYY.value))
 
				ppx22 = ppx2 + ( RDMMAX ) + (random (-spYY.value) (spYY.value))
 
				polyOp.setVert a pp[1]  [  a.verts[pp[1]].pos.x , a.verts[pp[1]].pos.y , ppx11]
				polyOp.setVert a pp[2]  [  a.verts[pp[2]].pos.x , a.verts[pp[2]].pos.y , ppx22]
 
				)
			)
 
		)
	)	
createDialog rlslice 160 100
)
miauu's picture

.

To make it a little bit faster move the polyop.getEdgeVerts and polyop.setVert outside of the on butconnect pressed do and make them local variables to the rollout.

jahman's picture

.

it seems like you overcomplicate things without a reason

move $.selectedEdges [0,0,1]  -- for Editable Poly
 
$.modifiers[#Edit_Poly].MoveSelection [0,0,1] -- for Edit Poly
titane357's picture

Hi jahman , yes perhaps,but I

Hi jahman ,
yes perhaps,but I have in mind the possibility ( in futur ) to move randomly the vertex of same edge. :-)

miauu's picture

.

( 
	try destroyDialog rlslice catch()
	global rlslice = rollout rlslice "RDM edges on Z" 
	(		
 
		button butconnect "GO" pos:[2,2]
		spinner spX "MIN " width:90 range:[-10000,10000,-0.5] type:#float pos:[55,5]
		spinner spY "MAX " width:90 range:[-10000,10000,0.5] type:#float pos:[55,25] 
 
		on butconnect pressed do 
		(	
			if selection.count == 1 do
			(
				if classOf (curO = selection[1]) == Editable_Poly do
				(
					selEdgesBA = polyop.getEdgeSelection curO
					undo on
					(
						for ss in selEdgesBA do
						(
							pp = polyop.getEdgeVerts curO ss
							ppx1 = curO.verts[pp[1]].pos.z
							ppz2 = curO.verts[pp[2]].pos.z
							ppx3 = ppx1 + random  spx.value spy.value
 
 
							polyOp.setVert curO pp[1]  [  curO.verts[pp[1]].pos.x , curO.verts[pp[1]].pos.y , ppx3]
							polyOp.setVert curO pp[2]  [  curO.verts[pp[2]].pos.x , curO.verts[pp[2]].pos.y , ppx3]
 
						)
					)
				)
			)
 
 
		)
	)	
	createDialog rlslice 160 50 
)

Do you see why your script is not working?
You get the selected edges when you run the script and the roolout is created. After that every time when you press the GO button it will work with edges, selected when the script was executed.
The second version not works because the variables "a" and "selE" are local for the "GET" button and are not accessable by the GO button. This will solve the problem:

(
	try destroyDialog rlslice catch()
	global rlslice = rollout rlslice "RDM edges on Y" 
	(
		local a = undefined
		local selE = undefined
 
		button butget "get" 
 
		spinner spX "MIN " width:90 range:[-10000,10000,0] type:#float
		spinner spY "MAX " width:90 range:[-10000,10000,0] type:#float
		button butconnect "GO" 
 
		on butget pressed do 
		(
		a=$
		selE = a.EditablePoly.getSelection #Edge as array
		)
 
		on butconnect pressed do 
		(
			undo on
			(
 
				for ss in selE do
				(
				pp = polyop.getEdgeVerts a ss as array
				ppx1 = a.verts[pp[1]].pos.z
				ppz2 = a.verts[pp[2]].pos.z
				ppx3 = ppx1 + random  spx.value spy.value
 
				polyOp.setVert a pp[1]  [  a.verts[pp[1]].pos.x , a.verts[pp[1]].pos.y , ppx3]
				polyOp.setVert a pp[2]  [  a.verts[pp[2]].pos.x , a.verts[pp[2]].pos.y , ppx3]
 
				)
			)
 
		)
	)	
createDialog rlslice 160 150
 
)
titane357's picture

Hi, Miauu Thanks again and

Hi, Miauu
Thanks again and again...
I knew that the first version have the problem, it is why I did the second one.
I undestand now the need to define variables locally for the whole script.
It wasn't so obvious to me that my variables was just defined inside the"on get pressed"
:-)

Comment viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.