ScriptSpot

Forum topic · Scripts Wanted

editpoly vertex point3

By JokerMartini · 2011-09-02

Description

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 (20)

Commit!

Anubis · 2011-09-15

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

Super simple!

JokerMartini · 2011-09-15

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

miauu · 2011-09-15

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 · 2011-09-15

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()
)

the BUG!

JokerMartini · 2011-09-15

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

Test this script out!

JokerMartini · 2011-09-14

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

Attachments

JokerMartini · 2011-09-14

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.

miauu · 2011-09-14

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. :)

Miauu

JokerMartini · 2011-09-14

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..

glad to help

Anubis · 2011-09-11

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 ;)

Nice work

JokerMartini · 2011-09-11

That's great. It does work.

This is what I've got as the final resulting code.
Next is figuring out how to set just one axis such as only the X


selVertArr = selection[1].modifiers[#Edit_Poly].getSelection #Vertex
selection[1].modifiers[#Edit_Poly].SetVert selVertArr [10,20,30]

Hey, SetVert work for me! :)

Anubis · 2011-09-10

Why we so complicated... yeah, SetVert function missed in the help for epoly_mod but it work :) so if i say:

ep.SetVert #{8} [10,20,30]

then my vert 8 is set to that [10,20,30] pos in a world space. So next code is fine for me:

max modify mode
modPanel.setCurrentObject ep
verts = ep.GetSelection #Vertex
ep.SetVert verts [10,20,30]

(* remove "!REG3XP1!>", i seen this before, its not a part of the code but forum addition)

:)

Anubis · 2011-09-10

Yep, the lack of functions in epoly mod complicate it usage. For example, if I move vert with MoveSelection() and need the new vert coords, I s'd add TurnToMesh mod, else get the old vert pos, realy odd. Not sure is it a bug in my Max (2009) or general limitation but its weird :(

It was a while back when I used epoly mod for a last time :) Maybe s'd check SetSelection() function. Not sure, but it may not refresh correct. Try to cleanup 'old' selection and then set new one, i.e.:

ep.SetSelection #Vertex #{} -- clear sel.
ep.SetSelection #Vertex #{vert} -- then set new

Also about the MoveSelection() ... needs a bit of measurement here...

trgPos = [10,20,30]
for vert in selVertArr do (
	ep.SetSelection #Vertex #{}
	ep.SetSelection #Vertex #{vert}
	-- measure new coords
	curPos = ep.GetVertex vert
	movePos = curPos + (distance trgPos curPos)
	if curPos.x > trgPos.x do movePos.x += -1
	if curPos.y > trgPos.y do movePos.y += -1
	if curPos.z > trgPos.z do movePos.z += -1
	-- then use 'move'
	ep.MoveSelection movePos
)

Let me know if this help.

JokerMartini · 2011-09-10

Yeah it's still seeming to not working right.

I feel like this task should be simpler than it is haha.

It's not moving the selected verts.

if not setVert then try (SetSelection + MoveSelection)

Anubis · 2011-09-10

Hmm, yep, I not see setVert() for epoly modifier :/ If polyop.setVert not works, then try again with MoveSelection but iterate and because its affect selected then just select only 1 vert in the loop, that s'd do the trick, I think.

ep = selection[1].modifiers[#Edit_Poly]
modPanel.setCurrentObject epmod
SetEPolySelLevel #Vertex
subObjectLevel = 1
selVertArr = ep.GetSelection #Vertex
for vert in selVertArr do (
	ep.SetSelection #Vertex #{vert}
	ep.MoveSelection [10,20,30]
)

Yeah it doesn't seem to be working.

JokerMartini · 2011-09-09

This is what i've come up with that is bugging out.
This is for the edit poly modifier don't forget.


selVertArr = selection[1].modifiers[#Edit_Poly].getSelection #Vertex
for vert in selVertArr do (polyop.setVert $ vert [10.0,20.0,30.0])

JokerMartini · 2011-09-09

I simply just want to set the world position of a selected vert.

For example a i want to select a vert and then move it to [10,20,30] in world space.

?...

Anubis · 2011-09-09

Hi John,
am not sure i catch your goal.. 'move' is an offset function, moving vert with world coords [10,10,10] with [20,20,20] will put it in a [30,30,30], its exact as PosPoint3 += PosPoint3. Maybe you try to set all selected verts to the 'constant' point in space? If so, try

polyop.setVert

.

JokerMartini · 2011-09-09

How do I move the selected vert to a specific location in world space, not local. Which is moves in local right now.
I want to be able to type in a point 3 value and move the selected vert to that position.

Thanks


selVertArr = selection[1].modifiers[#Edit_Poly].getSelection #Vertex
for vert in selVertArr do (selection[1].modifiers[#Edit_Poly].moveselection [10,10,10]

miauu · 2011-09-02

Use this to get the point3 coordinates:
-- 102 is the index of the esired vertex
$.modifiers[#Edit_Poly].GetVertex 102

vArr = $.modifiers[#Edit_Poly].getSelection #Vertex
for v in vArr do print ($.modifiers[#Edit_Poly].GetVertex v)