replacing modyfier

Hello everybody.

I have some skin isue and I have to refresh turbosmooth on many scenes with many characters so I want automatise it - refresh turbosmooth.

How to replace modyfier Turbosmooth on this same modyfier:
Script should look like this:
1)check all objecf for turbo smooth
2)if there is turbosmooth get properties of turbosmooth
3)delete turbosmooth
4)create turbosmooth in this same place in modyfier stack
5) set identical paramiters for this turbosmooth like in oryginal turbosmooth.

I already have:

for obj in selection do
(
for m in obj.modifiers do
(
if classOf m==turboSmooth do
(
-- <--- here I have to get settings of turbosmooth
deleteModifier obj m
addModifier meshsmooth obj m -- <--- here is error
-- <--- here I have to set settings for turbosmooth
)
)
)

For me it's important to delete and create turbosmooth in this same place in Modyfier stack.
(I used turbosmooth word 14 times in this post, I know:))

Comments

Comment viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.
kredka's picture

???

So regarding Your code, I'm not maxscript master, I making my first baby steps in maxscript so I would need more explanation regarding this script:

fn reassignModifier mode: modyClass: =
(
local tsArr = getClassInstances modyClass
local objs = case mode of
(
#all:
(
if tsArr.count == 0 then #() else
(
for i = 1 to tsArr.count where (nodes = refs.dependentNodes tsArr[i]).count != 0 collect nodes[1]
)
)
#selection:
(
if selection.count == 0 then #() else
(
local firstInstances = #()
for o in selection where o.modifiers.count != 0 do
(
InstanceMgr.GetInstances o &firstOnly
if firstOnly.count > 1 then append firstInstances firstOnly[firstOnly.count-1] else append firstInstances o
)
firstInstances
)
)
)
if objs.count != 0 and tsArr.count != 0 do
(
max create mode
with redraw off
(
for o in objs do
(
for m = o.modifiers.count to 1 by -1 where isKindOf o.modifiers[m] TurboSmooth do
(
bulb = o.modifiers[m].enabled
mody = copy o.modifiers[m] ; mody.enabled = bulb ; deleteModifier o m ; addModifier o mody before:(m-1)
)
)
)
)
)

I created some objects with active turbosmooth, fired it up and I noticed script do preety much nothing:) I eresed
"addModifier o mody before:(m-1)" line 37 so cript should only delete modyfiers(it's only way for me to check if script work, because modyfier look identical before and after execution) but it seems script dont erase modyfiers. I have also impression that max don't touched this modyfiers - last script make it blink - there was some reaction on max modyfi interface . I don't even know is it working at all or it's work and I use it in wrong way? Next thing is, you gave to line for action on selection and action for all scene elements but how to use it, exactly, how to create two different script for this using this command. Next thing is script copy and paste this same turbosmooth. When there is skin glitch cased by turbosmooth - turbosmooth must be deleted and added new because contain glitch so if I copy and paste this same turbosmoothit is useless.So settings from oryginal turbosmooth mus be taken, old turbosmooth must be removed, new added and settings from oryginal must be set also check if turbosmmoth is active or not and set it identical.

I know my understanding of maxscript leave a lot to be desired but I'm beginner:)
Can You explane this script, please, maybe I just don't get it.

Don't retired, people need help:)

this secund script
if (tsArr = getClassInstances TurboSmooth).count != 0 do
(
for i = 1 to tsArr.count where (nodes = refs.dependentNodes tsArr[i]).count != 0 do
(
for m = nodes[1].modifiers.count to 1 by -1 where isKindOf nodes[1].modifiers[m] TurboSmooth do
(
mody = copy nodes[1].modifiers[m] ; deleteModifier nodes[1] m ; addModifier nodes[1] mody before:(m-1)
)
)
)
I don't even now what to do with it, I run it and it don't work, only listner error.

barigazy's picture

...

First of all read this to see how to properly post your code on this forum.
http://www.scriptspot.com/filter/tips
You need to put code between "mxs" or "code" tags. For link use "url" tags
Also meaning of each syntax you can find in maxscrip Help document.
This is the best place where you can find better explanations of everithing that you want to know.

barigazy

kredka's picture

one more thing

when modyfier turbosmooth exist but is not active(light bulb off) script relpace it but the new one is active. Can it also check and set active or not active like oryginal turbosmooth?

barigazy's picture

...

I posted this example on the wrong thread. My bad (15000 point) :)
Kostadin noticed that. Credits for him :)

barigazy

barigazy's picture

...

If this not works for you than you have serious problem with your file or max

fn reassignModifier mode: modyClass: = 
(
	-- array of unique modifiers (in your case TurboSmooth)
	local tsArr = getClassInstances modyClass
	-- "objs" array will contain all scene objects with assigned modifiers by specified class (in your case TurboSmooth)
	local objs = case mode of
	(
		#all: -- this mode will consider all scene nodes with modifiers by specified class
		(
			if tsArr.count == 0 then #() else
			(
				for i = 1 to tsArr.count where (nodes = refs.dependentNodes tsArr[i]).count != 0 collect nodes[1]
			)
		)
		#selection: -- this mode will consider selected scene nodes (unique and first incance only) with modifiers by specified class
		(
			if selection.count == 0 then #() else
			(
				local firstInstances = #()
				for o in selection where o.modifiers.count != 0 do 
				(
					InstanceMgr.GetInstances o &firstOnly
					if firstOnly.count > 1 then append firstInstances firstOnly[firstOnly.count-1] else append firstInstances o
				)
				firstInstances
			)
		)
	)
	if objs.count != 0 and tsArr.count != 0 do -- code will continue process if both statements are "true"
	(
		max create mode -- this swich command panel to create mode and prevent blinking (first optimization of this function)
		with redraw off -- this will prevent viewport redrawing (second optimization of this function)
		(
			for o in objs do -- loop throught filtered "objs" array
			(
				-- when you need to delete modifiers, faces, or any item from array you always have to go from the back ei. last item
				for m = o.modifiers.count to 1 by -1 where isKindOf o.modifiers[m] TurboSmooth do -- loop throught all assigned modifiers of current node (object)
				(
					mody = TurboSmooth() -- new modifier
					-- collect all properties of current modifier and add it to new one
					for prop in getPropNames o.modifiers[m] do setProperty mody prop (getPropery o.modifiers[m] prop)
					mody.enabled = o.modifiers[m].enabled -- set new modifier "enabled" property according to old one
					deleteModifier o m ; addModifier o mody before:(m-1) -- delete old and assigne new one at the same place in the modifier stuck
				)	
			)
		)			
	)
)

barigazy

barigazy's picture

...

I already explained how to use it but ... anyway
First run previous function
Now select some scene objects and run next line

reassignModifier mode:#selection modyClass:TurboSmooth

If you want to process on the all objects ei. modifiers then
you not need to select enithing. Just run next line

reassignModifier mode:#all modyClass:TurboSmooth

barigazy

kredka's picture

my fold - it work:)

I just forgot to insert parenthesis :)

However could you modyfy a bit that script could work for selection instead of all objects , please.

kredka's picture

script don't work

I received this error when I fired your code up:

-- Error occurred in anonymous codeblock; filename: E:\WORK\doctor\temporary\; position: 371; line: 9
-- Frame:
-- tsArr: undefined
-- Unknown property: "count" in undefined

I used scene with few teapots, some of them has turbosmooth, some not.
Unfortunately script don't work at all.

It also would be great if script could work on group instead of all object so I could use it also on specific object. Could You check what's wrong with this?
I would be greatefull for help.

barigazy's picture

...

Is this good enough

if (tsArr = getClassInstances TurboSmooth).count != 0 do
(	
	for i = 1 to tsArr.count where (nodes = refs.dependentNodes tsArr[i]).count != 0 do
	(
		for m = nodes[1].modifiers.count to 1 by -1 where isKindOf nodes[1].modifiers[m] TurboSmooth do
		(
			mody = copy nodes[1].modifiers[m] ; deleteModifier nodes[1] m ; addModifier nodes[1] mody before:(m-1)
		)
	)
)

barigazy

Comment viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.