ScriptSpot

Forum topic · General Scripting

Moving vertices on "Edit Mesh"-modifier

By DaDiceman · 2008-12-22

Description

I hope somebody can help me.

In my script theres is an editable mesh, wich I want to transform. It ist possible to do this tranformation manual. If I add an "edit mesh"-modifier, I can move the several vertices in the vertex-sublevelmode. By deleting the "edit mesh"-modifier I can undo my transformation if it isn't correct.

I tried to write a script, but it doesn't work. Either it is irreversible or it doesn't work. Has anybody an idea how to solve this problem?

This is my script:

disableSceneRedraw()

percent = 50
factor = (percent/100.0)
currentSelection = getCurrentSelection()
max modify mode

for obj in currentSelection do
(
-- addModifier obj (edit_mesh())
for i = 1 to getNumVerts obj do
(
vert = getVert obj i
vert.x = vert.x * factor
vert.y = vert.y * factor
vert.z = vert.z * factor
setVert obj i [vert.x, vert.y, vert.z]
)
update obj
)

enablesceneredraw()

Comments (2)

DaDiceman · 2009-01-12

Thanks for your answer.

You are right, but my problem is that I want to run the script over a UI. With this was it isn't possible to undo the modification done by the script.

If I open a existing mesh for example and run the script over a UI there is no way to undo the modification.

I don't understand why it is possible to do the modification over the "edit mesh" modifier manually but not with the script.

Ralf · 2008-12-22

i'm new to maxscript myself, but i found this in an example:


obj = sphere() --create a Sphere
convertToMesh obj --collapse to EditableMesh
for v = 1 to getNumVerts obj do --loop through all vertices
(
vert = getVert obj v --get the v-th vertex 
vert.z = 0.0 --change the Z coordinate to 0.0
setVert obj v vert --assign back to the v-th vertex
)
update obj --update the mesh - the sphere should be flattened

Which is a lot like what you did, except for the "convertToMesh obj" part... and the setVert at once.

I don't quite understand what you mean by deleting as a kind of undo-function. And why you would want to script that. There is a Max Undo call, btw.