[Closed] Snap an object vertice to another
Hi,
I have made a script to snap the vertices of an object (ObjB) to another object (ObjA)
So here is the script :
for k=1 to polyOp.getNumVerts ObjA do ( p = polyOp.getVert ObjB k -- Take the vertice position of the first object polyOp.setVert ObjA #{k} p -- Apply the vertice position to the second object )
This is working very fine but...
Now i want to make the vertex snapping, not in the base object but in a modifier stack : Edit Poly for example.
In the modify panel i have this :
! + My new Edit Poly + Editable Poly
I want that the vertex change occurs not in the "+ Editable Poly" but in the new modifier stack : "! + My new Edit Poly"
I tryed to access the editpoly modifier by typing :
objA.modifiers[1]
this gives me as a response :
Edit_Poly:My New Edit Poly
But in my script if i replace
polyOp.setVert ObjA #{k} p
by
polyOp.setVert ObjA.[b]modifiers[1][/b] #{k} p
it gives me an error like that :
– Runtime error: EPoly operation on non-Editable Poly: Edit_Poly:My New Edit Poly
So after many tries like that, i did’nt find in the maxscript Help how to make the snapping in the EditPoly modifier only.
My last chance is your help and i hope you will find some solution to help me
Thanks a lot
Jeff
The class for the modifier edit poly is ‘Edit_Poly’, a base poly object is ‘Editable_Poly’.
polyops only work on the ‘Editable_Poly’ so that explains the error. In order to do the same things you want to do in a modifier you can (allmost) only use its own command see mxs manual for ‘Edit_Poly (Modifier)’. You would need to use most of that to get it to work but its a real pain sometimes, and a shame it doesnt work in the same way.
Thanks for the answer,
So i looked into the “Edit_Poly : Modifier” Help and came along with this new Script :
for i=1 to polyOp.getNumVerts ObjA do (
max modify mode
modPanel.setCurrentObject $.modifiers[#Edit_Poly]
subobjectLevel = 1
$.modifiers[#Edit_Poly].SetSelection #Vertex #{} –Reset the vertex Selection
$.modifiers[#Edit_Poly].SetSelection #Vertex #{i} – Select the Vertice to move
$.modifiers[#Edit_Poly].SetOperation #Transform
$.modifiers[#Edit_Poly].MoveSelection Offset – Move the vertice by an offset
$.modifiers[#Edit_Poly].Commit()
redrawviews()
)
But i have a new problem this is not working correct.
If i type the lines one by one in the listener it works very fine but when the lines are between brackets (in a for loop for example). All the object will move instead of only 1 vertice.
Example with two pictures ! (easier to expllain like that^^)
So How can i snap my vertice if each time i execute the script, all the object move instead of what the scripts ask to do : Move only one vertice.
I saw that other people had the same problem, and i hope someone knows the solution
thanks
Is there a solution to my problem ? or do you think its a bug from max ?
May be i am doing it the bad way… if someone can help me that would ve very appreciated
Look at using the polyOp struct functions, instead of the crud the Listener gives you. I’ve run across issues like this numerous times.
you set the for loop on a Wrong level , thats all
when you type
for i=1 to polyOp.getNumVerts ObjA do
this sets the operation on every vertex in the Obj , and yes all the Obj will move
cause polyop.GetNumVerts returns the Nu. of vertices in the object not the selected verts.
what you should do is first get the selection , then run the for loop on the selected vertices , and those verts only will move .
polyop.getVertSelection <Poly poly>
btw, is this a shrinkwrap stuff ?
First of all, thanks for your attention ;)[u][b]
To cyfer : [/b][/u]
Yes, I want all the vertices to move ! But in my example (the two pictures) i tryed to do it on only one vertice to show you the problem.
The script select 1 vertice, and snap it onto another.
But when the script is between brackets, it select 1 vertice, and snap it to the other, but all the other vertices take the same transformation, causing all the object to move…
If i apply my for loop to all the vertices, i have very strange results…
To Professor420 :
In the start i tried the polyop functions but as decapitator says me :
The class for the modifier edit poly is ‘Edit_Poly’, a base poly object is ‘Editable_Poly’.
polyops only work on the 'Editable_Poly' so that explains the error. In order to do the same things you want to do in a modifier you can (allmost) only use its own command see mxs manual for 'Edit_Poly (Modifier)'. You would need to use most of that to get it to work but its a real pain sometimes, and a shame it doesnt work in the same way.
so i searched into the Edit_Poly modifier commands. (in fact, this is what the listener gives.)
What i want to do, is being able to snap the vertices of a Source Object to a Target Object. But i want that the modifications are made into an editpoly modifier, and not into the Base Editable_Poly. (This way i can copy my edit_poly modifier onto other objects for example)
I finally found a solution
Put a redrewViews() just after the selection of the vertex.
If not, Max doesnt update the vertex selection and the script applys to all the vertex instead of the selected vertex.
It slow downs the script but it works very well
Thanks for the support, without all the advices i would never found it.