Copy and paste modifier

Copy and paste modifier

Anonymous
Not applicable
1,253 Views
11 Replies
Message 1 of 12

Copy and paste modifier

Anonymous
Not applicable
Hi I am trying to create a script that will allow me to paste the same modifier to any number of selected meshes. I have written this:

theAdjuster = Edit_poly()

for i in selection do addModifier i theAdjuster


rollout test_buttons "select meshes"

(

button theButton "Press me!"

on theButton pressed do

(

for i in selection do addModifier i theAdjuster

)

)

createDialog test_buttons 150 50

The theory is that I can create an editpoly modifier to the first selected mesh and edit that mesh... then apply that same editpoly modifier other selected meshes. I know this process works manually but I cant figure out why scripting doesn't work. The above script works... but the modifiers applied to the the additional meshes... dont adjust the model like they should.

If I change this bit of code:

for i in selection do addModifier i.baseObject theAdjuster

to include the the .baseObject... I get an error:

-- No ""addModifier"" function for Editable Poly

I noticed that even if I manually copy and paste the modifier... then try to copy the code spit out by the listener and evaluate it to do the same thing I just did manually I get the above error.


Anybody out there have any ideas.
0 Likes
1,254 Views
11 Replies
Replies (11)
Message 2 of 12

Anonymous
Not applicable
mods = #()
for i = 1 to node.modifiers.count do (mods = node.modifiers)

for i = mods.count to 1 by -1 do
(
addmodifier newnode mods
)

node is the "source" object and newnode is the "target"
0 Likes
Message 3 of 12

Anonymous
Not applicable
Hey thanks for the help... I tried the code but I keep getting an error:

-- Error occurred in anonymous codeblock; filename: ; position: 179
-- Unable to convert: #modifiers(Edit Poly:Edit Poly) to type: Modifier

Am I doing something wrong?
0 Likes
Message 4 of 12

Anonymous
Not applicable
Man...I wasn't awake for this reply either...sorry for giving you a bum-steer

Your code should work fine...if you define theAdjuster inside theButton
event handler...

rollout test_buttons "select meshes"
(
button theButton "Press me!"
on theButton pressed do
(
theAdjuster = Edit_poly()

for i in selection do addModifier i theAdjuster
)
)
createDialog test_buttons 150 50
0 Likes
Message 5 of 12

Anonymous
Not applicable
Hey thanks again, ya it does work as in applying an instance of an edit poly modifier... but it wont change the shape of those meshes I paste it to. its just an editpoly modifier that seems to have no effect.

Ill explain what I mean:

(1)I select the mesh I want to edit, then run the script... and it applies the editpoly, and the button pops up. (2) I pull some verts and change the mesh at the editpoly level. (3) I select the meshes I want to apply the same changes to, and push the button.

The result ends up being just instances of an editpoly modifier applied to the selected meshes... but it doesn't change the mesh as it should.


If you manually copy and paste the modifier it will change the mesh you apply it to.
0 Likes
Message 6 of 12

Anonymous
Not applicable
Two things come to mind...use instances (as in clone/instance)
or copy the baseobject property.

I don't know of a way to emulate the paste copy functionality.
0 Likes
Message 7 of 12

Anonymous
Not applicable
I found a way to do it using point cache... but this only works for strictly pulling points. Seems like this is a problem with max itself.
0 Likes
Message 8 of 12

Anonymous
Not applicable
It's not really a problem with Max... if you have two independent meshes, Max doesn't know for certain how the vertices in one line up with the vertices in the other. If they are identical, you can make changes that don't affect the vertex indices, but if any vertices have been added or removed that all goes out the window.

It's basically the same reason you get a warning if you try editing an object underneath an Edit Poly or Edit Mesh modifier. If the mesh is modified, the vertex indices are all out of whack. I've seen a couple of scripts that try to use the vertex position in space to re-match indices, but they were extremely slow and unreliable.
0 Likes
Message 9 of 12

Anonymous
Not applicable
The script I am trying to write would be for identical meshes... Morph targets specifically. It just seems like a bug to me if you can do something manually... yet you cant script it... 😕 even using the exact code that the listener gives you when you do it manually. Using the point cache modifier method I came up works well for now... although I would still like to make mods to meshes other than just pulling points.
0 Likes
Message 10 of 12

Anonymous
Not applicable
Does channelinfo ring any bell? Probably channel info would do a better job
in replicating the shape of 2 identical polygon object?
0 Likes
Message 11 of 12

Anonymous
Not applicable
Actually Im not familiar with channelinfo... can you enlighten me? 🙂
0 Likes
Message 12 of 12

Anonymous
Not applicable
I only understand that you can paste vertices information between 2 similar mesh with similar topology.
Did a quick search on the maxscript reference and found some stuff written about it. I am afraid you
may have to read the documentation on more details...
0 Likes