Notifications
Clear all

[Closed] object replacer -keep modifiers/help please

I have done a script to replace object (animated or not) by a new version of the mesh.
You just have to select the object to replace then use the pick button to point the new one. Basically it align the new to the old add an editmesh modifier to the old then delete the geomtry then attach the new one. So every keyframes and links are not modified because this the same object
My problem is to keep the modifier (uvw, meshsmooth) from the old object to the new one.
Any help?

rollout replacer “::replacer::”
(
label blabla1″1 – Select object to replace”
label blabla2″2 – Pick new object”
pickbutton newObj “Pick New” width:150 height:25

on newObj picked b do
(
for a in selection do
(
b.name = a.name
a.wireColor = b.wireColor
b.position =a.position
b.material = a.material

addModifier a (DeleteMesh ())
collapseStack a
    
addModifier b (Edit_Mesh ())
collapseStack b
attach a b
--addModifier b (UvwMap ())
    )
                
)

)

createDialog replacer

4 Replies

Copying and pasting modifiers is easy.

Grab and apply like this:


obj1 = $Sphere01 --sphere with meshsmooth modifier applied
obj2 = $Teapot01 

mod = obj1.modifiers[1]
delete obj1
addmodifier obj2 mod

Why not simply replace the baseobject instead?

a.baseobject = b.baseobject

This will keep all Modifieres on the original Mesh (it will be a reference to the new Mesh). All Modifiers you applied to the new mesh before the operation will be ignored, but later applied ones will carry over.

You might want to turn the new Mesh to an editable Poly before, to prevent users from being stupid

convertTo b Editable_Poly
a.baseobject = b.baseobject

after getting “setting modifier Array is not implemented yet ” error
i decided to do the ghosting stuff :arteest:

rollout replacer "::replacer::" 
(
label blabla1"1 - Select object to replace"
label blabla2"2 - Pick new object" 
pickbutton newObj "Pick New" width:150 height:25 

on newObj picked b do 
(
	Max Create mode
		for a in selection do
		( 
			c = Box visible:false
			for j = 1 to a.modifiers.count  do (addmodifier c a.modifiers[j])
			b.name = a.name
			a.wireColor = b.wireColor 
			b.position =a.position
			b.material = a.material

			addModifier a (DeleteMesh ())
			collapseStack a

			addModifier b (Edit_Mesh ())
			collapseStack b
			attach a b
			for k = 1 to c.modifiers.count  do (addmodifier A c.modifiers[k])
			Delete C
			--addModifier b (UvwMap ())
		)

)
)

createDialog replacer

for many cases and types of modifiers it doesn’t make any sense to keep them after mesh exchanging. But whatever:


fn meshXChange source target keepMods:on xchangeMat:off delTarget:on =
(
	local mods = #() 
	if xchangeMat do source.mat = target.mat
	if keepMods do mods = for m in source.modifiers collect m
	instancereplace source target
	for k=mods.count to 1 by -1 do addmodifier source mods[k]
	if delTarget do delete target
	source
)