PDA

View Full Version : how to prevent Modifier added twice


madjeter
02-05-2009, 08:46 AM
Hi all, I am making a special modifier. I do not want user to apply it to one object twice. Is it possible to prevent that in script? Thanks!

Piflik
02-05-2009, 09:42 AM
You can loop through the modifier stack of the object and test each one if it is the one your trying to add.

ZeBoxx2
02-05-2009, 10:10 AM
note, however, that this doesn't prevent the user from adding the modifier. You could check the stack of the object it is applied to* and make the modifier inactive (no code run, UI showing a warning, perhaps) if the object already has such a modifier applied.
* keep in mind that a single modifier may be applied to multiple objects via instancing

You could go so far as automatically removing the modifier after it is applied, but you have to do so through a timer (so that it removes the modifier outside of the modifier's creation scope) - otherwise max becomes unstable.

Piflik
02-05-2009, 10:58 AM
Couldn't you incorporate such a script in a way, that it is called whenever the user tries to add the modifier?

for o in selection do (if (for m in o.modifiers where m.name == YourMod collect m).count > 0 do addmodifier o YourMod)

That should prevent the modifier to be assigned to an object that has the modifier in its stack already. (But not if it is renamed...is there also a modifier.type?)

ZeBoxx2
02-05-2009, 11:22 AM
Couldn't you incorporate such a script in a way, that it is called whenever the user tries to add the modifier?
That's easy enough - the scripted modifier plugin would have its node binding code triggered whenever it is assigned to a node for the first time.

for o in selection do (if (for m in o.modifiers where m.name == YourMod collect m).count > 0 do addmodifier o YourMod)
wouldn't that just add another modifier -if- the modifier already exists?
i.e.
for o in selection -- loop over the selection
for m in o.modifiers -- loop over the modifiers
where m.name == YourMod -- get all modifiers named YourMod*
collect m -- collect that modifier into an array
.count > 0 -- if the array is non-empty (i.e. the object HAS a modifier named YourMod)
addmodifier o YourMod -- add a YourMod modifier to the object

That should prevent the modifier to be assigned to an object that has the modifier in its stack already.
It wouldn't, actually, even if you changed it to .count == 0. All that would happen is that the modifier is already added once (via 3ds Max's internals), and then next the code would not add it another time. But you're still stuck with the one 3ds Max's internals added.


(But not if it is renamed...is there also a modifier.type?)
'classOf <modifier>' or, even better, '<modifier>.classID'

But, again, the basic 'problem' is that...
1. you cannot prevent a modifier from being applied by the user, unless you want to hide the modifier panel and maxscript from them and force them to go through your own user interface
2. you cannot hide a modifier based on whether it is applicable to the object.
The 2nd functionality -is- available in 3ds Max API - it's what prevents you from applying, say, Edit Spline to a GeoSphere; 'Edit Spline' is simply not listed in the modifiers dropdown at all (and if you use buttons, the button is disabled). But this is not exposed to scripted (modifier/simplemod) plugins, and I'm not sure if the API allows you to do a full check of the selected object(s) either, or whether you can only test base classes.
Edit: Apparently, no - the validity of a modifier as related to the current selection is determined via 'InputType() { return Class_ID(<class>,0); }', so it is limited to filtering by types of objects - not specific details about those objects.

Piflik
02-05-2009, 03:05 PM
wouldn't that just add another modifier -if- the modifier already exists?


Yeah, sorry. I have been a bit to hasty...should have been '==' instead of '>'

But since it doesn't work anyway...I just thaught that you could write something like this into the modifier itself, so that adding it doesn't have an effect, when there is such a modifier in the stack already.

ZeBoxx2
02-05-2009, 04:35 PM
that you can, yes :)

madjeter
02-06-2009, 08:15 AM
thanks all of you.

CGTalk Moderation
02-06-2009, 08:15 AM
This thread has been automatically closed as it remained inactive for 12 months. If you wish to continue the discussion, please create a new thread in the appropriate forum.