[Closed] Modifier Index
another problem… (hopefully not always)…
is ther a way to GET or SET the current modifier index in max 6?
im trying to apply a modifer to a set of selected objects. but what i want is to place the modifier above or below a certain modifier.
here’s my current code… which only works on adding a modifier below a certain modifer.
obj = $sphere*
for i = 1 to obj.count do
(
uvwBmap = (uvwmap mapchannel:2 name:“UVW Bump 2”)
mods = obj[i].modifiers
for j = 1 to mods.count do
(
if mods[j].name == “Flex” then
(
addmodifier obj[i] uvwBmap before:j
)
)
)
whenever i add something like this…
index = j – 1
addmodifier obj[i] uvwBmap before:integer
to the addmodifier code, it wud add not just one modifier to the stack, but a couple of it instead…
Well, if you want to place a modifier after a certain one and you can only place it behind another then the solution is simple…
Place the modifier behind the modifier after it.
Also (if you didn’t know already) you should use if-do instead of if-then because maxscript will expect an else (if-then-else). This also works but it could give some strange errors in the Listener.
OK, here goes:
-- place modifier after another
obj = $sphere*
for i = 1 to obj.count do
(
uvwBmap = (uvwmap mapchannel:2 name:"UVW Bump 2")
mods = obj[i].modifiers
for j = 1 to mods.count do
(
if mods[j].name == "Flex" do
(
-- if j is the top modifier then just add
if j == 1 then
(
addModifier obj[i] uvwBmap
)
-- but if it's not, then add it before the one
-- above it, basically just adding it after j
else
(
addModifier obj[i] uvwBmap before:(j-1)
)
)
)
)
Hope this helps,
- R
P.S. This is one of the first working tests of a script I’ve picked up again. It automatically colour codes your maxscript code so that you can get maxscript colours here on CGTalk. Pretty cool huh?
wow! thats really cool rens! i was beginning to wonder how ur doing those colors! Is it an HTML code? Im not too familiar with html though. I’ve seen some posts have a seperate “quote” like window like those, and with scrollbars at the sides, how do they do that? I recall the code that I’ve pasted, it was pretty much consumed much space for the IE window… hehe:)
Oh, the code works if my flex is the 2nd modifier from below… but if i place it somewhere else, it generates multiple copies of the UVWmap mod above, i’ve observerd that it counts the layers below the flex, thus adds those many UVW modifiers above it.
so…counting from below a modifier stack:
2-FLEX (the only layer below would be its baseobject) so it gives 1 UVWmap above.
3-FLEX (gives 2 UVWmaps above)
4-FLEX (3 UVWmaps above)
5-FLEX and so on…
hmmm… im still trying to figure whats causing this… its fun though!
if-do syntax? ok, I didnt thought that it would be that way, hehe. Ill clean my codes from now on. Thanks again rens!
It’s no HTML code, it’s the vB code this forum uses. Check out http://www.cgtalk.com/misc.php?do=bbcode#color .
You can get the quote like window by wrapping the code in [CO-DE] and [/CO-DE] tags (without the “-”). Scrollbars will automatically be added when the script goes beyond a certain size.
The colour code script I wrote goes over every line of code and adds those vB code tags if necessary. Then you can just paste it into a reply screen and the code will have pretty colours.
About your script... hmm, odd. I can't test it right now but you can try a switch of some sorts. See the following example:
mod_switch = 0
...
if mod_switch == 0 do
(
addModifier blabla
mod_switch = 1
)
This will only allow another modifier as long as the switch is not 'flipped'.
Just make sure you get mod_switch = 0 out of any unwanted loops or it might reset to 0 again and again. Somewhere along uvwBmap = ... and mods = ... seems like a good place. It will reset at every object but not at every modifier loop.
Good luck!
- Rens
i see, i myt try that one, but now im currently working on another script. coz the latter one will do for my purpose.
yet ofcourse, im tied to another problem…
(ok, ill try the CODE tag)…
selist = #()
when select foo change sel do
(
if sel != undefined do
(
seln = sel.name
index = finditem selist seln
if finditem selist seln == 0 then
(
append selist seln
)
else
(
deleteitem selist index
)
)
this code is functioning how i want it to be, to collect selected objects to an array (selist)…
but my problem is i cant get it to work with a listbox… i want my list box to update everytime i do a selection…
Im also trying to put an ID for the code so that i cud delete it everytime i run the whole script… but i still dont know how…
hope this information helps…