ScriptSpot

Forum topic · General Scripting

Align selected ring edges to selected vertex z value

By titane357 · 2018-08-16

Description

Hi,
I have a road for exemple where vertex are not at same z values at the right and left side.
I select all the edges along the road (a ring )
I select all the vertices I want to stay in place
I run the script and all the edges become horizontal.
That is what I want.
But I can't manage to find how to write in maxscript :"pp[1] exist in selP" in the script below. If somebody could help.
Thanks :-)


a = $
selE = a.EditablePoly.getSelection #Edge as array
selP = a.EditablePoly.getSelection #Vertex as array
for ss in selE do
(
pp = polyop.getEdgeVerts a ss as array


if "pp[1] exist in selP" then
					(
					polyOp.setVert $ pp[2]  [ a.verts[pp[2]].pos.x , a.verts[pp[2]].pos.y , a.verts[pp[1]].pos.y  ]
					)
					else
					(
					polyOp.setVert $ pp[1]  [ a.verts[pp[1]].pos.x , a.verts[pp[1]].pos.y , a.verts[pp[2]].pos.y  ]
					)
	
)
 
Attachments
Comments (2)

titane357 · 2018-08-17

Thank you very much !! Works fine !
One day I will do something by myself ! :-)

.

jahman · 2018-08-16


(
obj = selection[1]
esel = polyop.getEdgeSelection obj
vsel = polyop.getVertSelection obj

for index in esel do
(
	ev = polyop.getEdgeVerts obj index
	v1 = ev[1]
	v2 = ev[2]
	
	if vsel[ v1 ] == vsel[ v2 ] do continue -- skip edge where zero or both verts are selected
	
	if vsel[ v1 ] then 
	(
		pt = polyop.getVert obj v2
		pt.z = (polyop.getVert obj v1).z
		
		polyop.setVert obj v2 pt
	
	) 
	else 
	(
		pt = polyop.getVert obj v1
		pt.z = (polyop.getVert obj v2).z
		
		polyop.setVert obj v1 pt
	
	)

)
redrawViews()
)