move vertices of baseObject with modifiers on top

Hi I would like to make a script which moves all selected Vertices to x=0.

This is what I have so far

for i = 1 to (((modPanel.getCurrentObject()).GetSelection #Vertex) as Array).count do
        $.selectedVerts[1].pos = [0, $.selectedVerts[1].pos[2], $.selectedVerts[1].pos[3]]  

Unfortunately, It is not working with modifiers on top.

I've also tryed move $.selectedVerts [$.selectedVerts[i].pos[i]*-1,0,0] but both methods give the same error :(

 What am I doing wrong?

 

 

 

 

 

 

Comments

Comment viewing options

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

Thank you all for your

Thank you all for your answers :D
Sorry vor the late response. I used the wrong email notification settings :(

Perfect_Storm/ barigazy, thanks for your help :D
I wasn't expecting that I would have to use a workaround to move a few vertices.

Thanks again :)

Anubis's picture

untested code...

try it anyway :)

for obj in selection where \
classOf obj.baseObject == Editable_Mesh or \
classOf obj.baseObject == Editable_Poly do
(obj.baseObject.selectedVerts.x = 0)

my recent MAXScripts RSS (archive here)

barigazy's picture

Hi Anubis, i test you code

Hi Anubis,
i test you code and not works

barigazy

Anubis's picture

aha, ok

am still not tested it, as the most collections in Max are mapped I presume that I can set #x at once by calling "selectedVerts.x=0" but if that not work looks like need a for-loop.

P.S. -- I check the help now and maybe replacing "...selectedVerts.x" with "..selectedVerts.pos.x" will work?
obj.baseObject.selectedVerts.pos.x = 0

my recent MAXScripts RSS (archive here)

Perfect_Storm's picture

Here you go

Ok here you go then.
The script checks if an object has modifiers, and if so, if the last modifier is an Edit_Poly modifier.
If that's the case, it will use that modifier to move the verts.
If it has any other modifier on top, it will create an Edit_Poly modifier.

If an object has no modifiers at all, it will convert the object to Editable_Poly (If needed) and then do the transformations to the verts.

note: It should work with multiple objects, but I haven't tested that yet.

(
 
	fn MoveFunction CurModifier =
	(
		CurModifier.SetEPolySelLevel #Vertex
		NumVertSelected = CurModifier.GetSelection #Vertex as array
		CurSelectedVerts = CurModifier.GetSelection #Vertex
 
			for i=1 to NumVertSelected.count do (
				MoveValue = CurModifier.getvertex NumVertSelected[i]
				CurModifier.setselection #Vertex #{}
				CurModifier.select #Vertex #{NumVertSelected[i]}
				CurModifier.moveselection [-MoveValue[1],0,0]
				CurModifier.Commit ()
			)
 
		CurModifier.setselection #Vertex #{}
		CurModifier.select #Vertex CurSelectedVerts
 
	)
 
	fn MoveFunctionEP CurObject =
	(
		for i=1 to CurObject.selectedVerts.count do (
				CurObject.selectedVerts[i].pos = [0,CurObject.selectedVerts[i].pos[2],CurObject.selectedVerts[i].pos[3]]
			)
	)
 
	initSelection = selection
 
	for i=1 to initSelection.count do (
 
		if classof initSelection[i].modifiers[1] == Edit_Poly then (
			EP = initSelection[i].modifiers[1]
			MoveFunction EP
		)
 
		else (
			if initSelection[i].modifiers.count != 0 then (
				EP = Edit_Poly()
				addmodifier initselection[i] EP
				MoveFunction EP
			)
 
			else (
				if classof initSelection[i] != Editable_Poly do (
					convertto Editable_Poly initSelection[i]
				)
				MoveFunctionEP initSelection[i]
			)
		)
	)
)
Perfect_Storm's picture

If an object has an edit poly

If an object has an edit poly modifier bind to them, you can't use the normal Polyop or Editable Poly commands anymore.
This is because you transformed the object to a PolyMesh.

I suggest you always create a new Edit Poly modifier, and work with that.
The advantage that this gives you is that you can always have your old modifiers and it will always work.
The disadvantage is that you will stack an Edit Poly modifier on top of your object.

I already created the code for you, here it is:

(
 
	EP = Edit_Poly()
	addmodifier selection EP
	EP.SetEPolySelLevel #Vertex
	NumVertSelected = EP.GetSelection #Vertex as array
 
	for i=1 to NumVertSelected.count do (
 
		MoveValue = EP.getvertex NumVertSelected[i]
		EP.setselection #Vertex #{}
		EP.select #Vertex #{NumVertSelected[i]}
		EP.moveselection [-MoveValue[1],0,0]
		EP.Commit ()
 
	)
 
)

For some reason, setSelection did not work as it should, so I just cleared the whole selection first and then used select to select the vertex.
Maybe this can be optimized, dunno, have a look at the documentation.

Bones's picture

Thank you for your quick

Thank you for your quick response.
I planning to use that macro a lot ... so it would be kinda unconfortable to add a new edit poly modifier each time :)

What I've planed to do is to add an if statement to check if I'm working on an editable poly modifier or the baseobject. How should the code look when I'm moving the vertices on the baseobject?

barigazy's picture

Another solution

max create mode
p = $ -- object whit modifiers on the top
m = snapshot p
varr = m.selectedverts as bitarray
if varr.numberset != 0 do
(
	for v in varr do m.verts[v].pos.x = 0
	update m
	if classof p.baseobject == Editable_Poly then 
	( 
		p.baseobject = (convertToPoly m) 
	)   
	else p.baseobject = m
	delete m
)

barigazy

Comment viewing options

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