editpoly vertex point3

Just want to loop through the selected verts in a edit poly modifier and get there point3 values.....

m = $.modifiers[#Edit_Poly]
m.GetOperation #TransformVertex   --?????

Comments

Comment viewing options

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

Commit!

Many thanks, Miauu, for Commit function!
As I rarely code something with poly modifier I often forget to call Commit(). Should bold this function in my head :D

my recent MAXScripts RSS (archive here)

JokerMartini's picture

Super simple!

Super simple solution. Makes sense.
I missed that line of code completely.
I forgot about the commit()

as for the snippet of code that you had asked why it was different was because I was just testing things trying to trouble shoot why it was not saving the move. That's all.

Thanks for your help Maiuu, it's been super helpful. I think this script just needs a few tweaks and then will be ready for posting on ScriptSpot as a final script. Do you have any ideas or recommendations for ways to add more functionality or improve upon it?

Thanks again

John

John Martini
Digital Artist
http://www.JokerMartini.com (new site)

miauu's picture

My suggestion: Use this

My suggestion:
Use this code:

for i = 1 to verts.count do
(
   selection[1].modifiers[#Edit_Poly].SetVert #{verts[i]} p3Arr[i]
)
selection[1].modifiers[#Edit_Poly].Commit()

The Commit() is out of the for loop. This will speed up the performance. On
my PC moving the 530 vertices(all verts of the standart Teapot) take 0.329
sec, but if the Commit() is in the for loop the time is 8.906 sec.

You can extend the script to copy-paste position of edges, faces(elements), spline knots, add support for Editable_mesh objects. :)

miauu's picture

First, sory for my

First, sory for my english.
What i found. In your script you have the folowing code:

selVertArr = selection[1].modifiers[#Edit_Poly].getSelection #Vertex --// BitArray
p3Arr = for v in selVertArr collect selection[1].modifiers[#Edit_Poly].GetVertex v 
for p in p3Arr do p[1] = posX 
 
verts = selVertArr as array
for i = 1 to verts.count do
(
						selection[1].modifiers[#Edit_Poly].SetVert #{verts[i]} p3Arr[i]
)

and the same code for pasteZ, but for PasteY you have:

selVerArr = undefined
selVertArr = selection[1].modifiers[#Edit_Poly].getSelection #Vertex --// BitArray
for p in p3Arr do p[2] = posY 
 
verts = selVertArr as array
for i = 1 to verts.count do
(
	selection[1].modifiers[#Edit_Poly].SetVert #{verts[i]} p3Arr[i]
)

The

p3Arr = for v in selVertArr collect selection[1].modifiers[#Edit_Poly].GetVertex v

is missing. Why?

And for the problem with reseting of the position - when you move the edit_poly vertex in the macroRecorder will see these lines:

$.modifiers[#Edit_Poly].Select #Vertex #{347}
$.modifiers[#Edit_Poly].SetOperation #Transform
$.modifiers[#Edit_Poly].MoveSelection  [17.5381,0,0] parent:(transMatrix [1,5784,2,4606,0,0000]) axis:(transMatrix [32,9160,-0,5768,17,7943])
$.modifiers[#Edit_Poly].Commit ()

After each movement max execute Commit(). Now your code move vertex 1 to 0 by X axis, but if you check the position of the vertex you will see that the position is not updatet, but the vertex is moved. One example:

selVertArr = selection[1].modifiers[#Edit_Poly].getSelection #Vertex
p3Arr = for v in selVertArr collect selection[1].modifiers[#Edit_Poly].GetVertex v

-- selVertArr = #{387}
-- p3Arr = #([42.2616,2.46056,29.3999])

Then your code do that:

for p in p3Arr do p[1] = posX
-- now p3Arr = #([0,2.46056,29.3999])
verts = selVertArr as array
for i = 1 to verts.count do
(
selection[1].modifiers[#Edit_Poly].SetVert #{verts[i]} p3Arr[i]
)
-- the vertex is moved, but if you check the ver position
selVertArr = selection[1].modifiers[#Edit_Poly].getSelection #Vertex
p3Arr = for v in selVertArr collect selection[1].modifiers[#Edit_Poly].GetVertex v

-- selVertArr = #{387}
-- p3Arr = #([42.2616,2.46056,29.3999]) - the same as befor moving

The solution is to use the Commit(). So the code must be:

selVertArr = selection[1].modifiers[#Edit_Poly].getSelection #Vertex
p3Arr = for v in selVertArr collect selection[1].modifiers[#Edit_Poly].GetVertex v 
for p in p3Arr do p[1] = posX 
 
verts = selVertArr as array
for i = 1 to verts.count do
(
   selection[1].modifiers[#Edit_Poly].SetVert #{verts[i]} p3Arr[i]
   selection[1].modifiers[#Edit_Poly].Commit()
)
JokerMartini's picture

the BUG!

I've narrowed down the problem to this.....
Why does it not put all the verts at 0,0,0?
or even try putting 10,10,10 it does not work.....

fn functionX num = (
ep = selection[1].modifiers[#Edit_Poly]
selVertArr = ep.GetSelection #Vertex -- BitArray
-- collect vert coords (Array of Point3)
p3Arr = for v in selVertArr collect ep.GetVertex v
-- changing Z only (into array elements)
for p in p3Arr do p[num] = 0 -- set new value
 
	verts = selVertArr as array
	for i = 1 to verts.count do (
		selection[1].modifiers[#Edit_Poly].SetVert #{verts[i]} p3Arr[i]
	)
 
)
 
functionX 1
functionX 2
functionX 3

John Martini
Digital Artist
http://www.JokerMartini.com (new site)

JokerMartini's picture

Test this script out!

It copies the average position of the pivot and then allows users to paste it onto objects or verts. Works with edit poly mod and editable poly modifier.

bug: if you run script and then without copying any positions if you go into edit poly mod mode and select some verts and hit the Paste X button 0.0 and then hit the Y one, it restores there original position and then moves them to the new axis. This is not right???
If you hit X,Y,Z with all being at 0.0 it should put all verts at the origin.....

Thanks

AttachmentSize
04.ms 9.33 KB

John Martini
Digital Artist
http://www.JokerMartini.com (new site)

JokerMartini's picture

I'm not sure what version of

I'm not sure what version of max your using but ep does not work as anything for me.
I have to put
selection[1].modifiers[#Edit_Poly]

if order for it to work.

John Martini
Digital Artist
http://www.JokerMartini.com (new site)

miauu's picture

As far as I know Anubis use

As far as I know Anubis use max2009.
But the problem is not the max version
See some post below. He use:

ep = selection[1].modifiers[#Edit_Poly]

So, you have to use this, and then ep will work for you. :)

JokerMartini's picture

Miauu

thanks miauu for the seeing that. I must have missed him writing that. Silly mistake.

I've posted the script of what I have so far.
It works great an all.
Except for the one edit Poly mod bug where it does not work properly if you right click C-All button to zero our the parameters and then hit the Paste X and then Y ....it restores the vert positions and then aligns them. It doesn't properly move them to the X and then to the Y leaving there new vert positions to be [0,0,*]

*unique for each vert, unless user hits the Z paste as well..

John Martini
Digital Artist
http://www.JokerMartini.com (new site)

Anubis's picture

glad to help

as for the next step - how to set just one axis - looks simple, i think ...

selVertArr = ep.GetSelection #Vertex -- BitArray
-- collect vert coords (Array of Point3)
p3Arr = for v in selVertArr collect ep.GetVertex v
-- changing Z only (into array elements)
for p in p3Arr do p[3] = 12 -- set new value
-- as we can call SetVert with Array of Point3 then
ep.SetVert selVertArr p3Arr -- no loop needs ;)

my recent MAXScripts RSS (archive here)

Comment viewing options

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