[Closed] how to copy modifiers with all data?
I got a problem,like this
-
Create a box, then copy it so you have 2 box
- add an “edit poly” modifier and extrude some faces on first box.
- copy “edit poly” modifier from first box stack to second box
now you see the second box will have extrusions as well.
Is this possible with maxScript?
I have tried this:
mod=box01.modifiers[1]
addModifiers box02 modThis will apply the modifier on the other box with the same settings but the extrusions are gone
any one can tell me how to do that with maxscript,thanks lot!!!
Im guessing at a hunch here but your instancing the modifier in the form of its creation with script rather than copying all of its history?
Does
local test = copy $.modifiers[#edit_mesh]
addModifiers $box02 test
work?
Nope, ‘fraid not…
Try out the steps mentioned…
- Create two boxes side-by-side
- Apply an Edit Mesh or Edit Poly modifier to the left box
- Go to the Poly sub-object level, and select one of the sides of the box
- Bevel the selected face out
- Exit the sub-object level (optional)
- Right-click in the modifiers list, and choose Copy
- Select the right box
- Right-click in the modifiers list, and choose Paste
Upon pasting, you should see the same poly on the right box get beveled as well.
Now the only bit to worry about in the code is steps 6 and 8…
-- select the right box manually
deleteModifier $ 1 -- remove the modifier we had pasted manually
rBox = $
-- select the left box manually
lBox = $
-- get the modifier
theMod = lBox.modifiers[1]
-- try applying it to the right box in a number of ways:
-- standard modifier adding
addModifier rBox theMod
-- nope
deleteModifier $ 1
addModifier rBox (copy theMod)
-- nope
deleteModifier $ 1
-- through the modify panel
max modify mode
modPanel.addModToSelection theMod
-- nope
deleteModifier $ 1
modPanel.addModToSelection (copy theMod)
-- nope
-- maybe via replacing the instance (note that the modifier wasn't deleted last)
replaceInstances rBox.modifiers[1] theMod
-- nope
replaceInstances rBox.modifiers[1] (copy theMod)
-- nope
-- And that's where I ran out of fathomable options and tried the uiaccessor stuff
[size=2]The only method I can think of, which is going to be pretty limited as well if there’s multiple modifiers on the object to which you wish to paste the modifier, is to instance replace the object -below- the modifier.
e.g.
[size=1]
newObject = copy lBox
objectToGetTheModifiers = Sphere()
instanceReplace newObject [/size][/size][size=2]objectToGetTheModifiers
delete [/size][size=2][size=1]objectToGetTheModifiers
But as all the modifiers that may pre-exist on [/size][/size][size=2]objectToGetTheModifiers get lost, and you may not be able to re-apply them (due to the very problem we’re trying to solve here), that’s not always going to be a solution.
[/size]
Well you can get the vert positions and apply those directly. But dealing with changes to vert counts I’m not sure what you can do.
your best bet is to poke at a plugin programmer and see if the methods used in the context menu are exposed via the 3ds Max API/SDK at all… and then have them expose that to maxscript.
I did have a try with UIAccessor bits, but various areas are just too klunky to be figuring out… from having to figure out mouse coordinates within the client area of the modifier list to make sure a right-click event is sent over the correct modifier, to getting the modifier list to scroll (and detecting if it -is- scrollable, etc. etc.), to clicking an item in the context menu.
I gave up after noticing that complexity… as it stands, it will happily copy/paste the top-most modifier of object A to object B via the UI… but that won’t do you any good if you need a different modifier… especially if the modifier list gets long and starts scrolling.
( clicking an item in the context menu was a problem because I think I need the wparam and lparam values of the message… and can’t get those without attaching a watcher… which max doesn’t-allow-imagine-that. So I send down arrow key presses and an enter key press instead. ha! take that! )