[Closed] modPanel.getModifierIndex how!?
Guys I cant get this shit to work how does the modPanel.getModifierIndex <node> <modifier> works?
I tried and I tried but nothing (oh my god did I try, and I say yeahhhhhhhhhh yeahhhhhhh yeahhhh ehhhh ehhh…)
(
n = box()
addmodifier n (a = Edit_Poly name:"poly")
addmodifier n (b = Edit_Normals name:"normals")
addmodifier n (c = Unwrap_UVW name:"uvw")
print (modPanel.getModifierIndex n a) -- 3
print (modPanel.getModifierIndex n b) -- 2
print (modPanel.getModifierIndex n c) -- 1
ok
)
where is a problem?
LOL, I had 4-N-Bs playing in my car this morning.
What Denis is saying in MXS is that you must pass the actual modifier instance, not the class of it or something like that. So you must have a variable containing the pointer to the modifier instance either from previous creation, or after accessing the modifier in a different way, for example
addModifier $ (Bend())
addModifier $ (Displace())
modpanel.getModifierIndex $ $.bend -->2
modpanel.getModifierIndex $ $.modifiers[#displace] -->1
Gotcha, thanks guys but what if I have two bends? Well, long story short I wanted to get the index or an array of the modifiers that are from a specific class…
I also tried finditem $.modifiers (turbosmooth()) for example, but it always returned 0
PS: Bobo, now that we both listen to 4NB’s can you accept my facebook invitation? xD
That won’t work, because (turbosmooth()) is not a class, it is an instance. So it won’t ever find it unless you add it first. Read the topic “The Wonderful World of Classes and Class Instances” which was taken straight from the old Max Support Forums.
Modifiers in MAXScript are indexed top to bottom. So if you loop and check the class, you can collect all indices:
theIndices = for i = 1 to $.modifiers.count where classof $.modifiers[i] == Turbosmooth collect i
I don’t see an invitation.
I have 100 people I haven’t confirmed including family members, but I don’t see you on the list. 😈
Just had a typo, I meant turbosmooth and not turbosmooth()
And I know I can do that kind of collect but what I want is someway to do something like:
for i in selection where (finditem i.modifiers turbosmooth) != 0 do
(
code goes here
)
without needing to do a collect first on the modifiers.
Other thing… can anyone PLEASE… PLEASE tell me where can I get a CHM for the 3dsmax 2012 help and maxscript help… I hate online help so much…
Sorry for the double post but Bobo, invitation sent.
And this is just a challenge I got myself into while trying to help someone here at the forum, his question was already answered but when I tried to find a way to optimize it…
Here’s the original thread: http://forums.cgsociety.org/showthread.php?f=98&t=1017370
Here’s the solution by Tim Hawker
for o in selection do (
randX = random -1000 1000
randY = random -1000 1000
randZ = random -1000 1000
for a in o.modifiers do (
if classOf a == uvwmap do (
a.gizmo.position = [randX,randY,randZ]
)
)
)
Something like this?
for a in selection do (
for b in a.modifiers where classOf b == turboSmooth do (
print "code here"
)
)
Edit:
Heh, looks like you posted that just as I was writing a reply. Cheers for the mention
No problem Tim! You beat me when finding the solution for that guy problem :applause:
But after that I was thinking on how I could optimize your snippet and the first thing I thought was to eliminate the need for the “classof a == uvwmap” by adding a where clause in the first for loop. That where clause would check if that selected object has an uvwmap modifier and only go thru that ones.
how about something like this:
for o in (makeUniqueArray (for t in (getClassinstances bend) collect refs.dependentNodes t)) do
(
print o
)
#1.You would use the getClassInstances rarely if you knew how this function works. It might surprise you but the function searches in ALL anims to match the class. So to find only one thing we are looking in thousands places. That means we have to know the place where to search to find quicker.
#2. refs.dependentNodes returns nodes both with direct and indirect dependency. You can see it using refs.DependencyLoopTest.
For some modifiers it works, but for some other it might give wrong nodes (e.g. Morpher, Sweep…).
So, what could we do?
Here is a theory:
#1. After any modifier applied to any node the node gets its Derived Object.
#2. If we know the Derived Object we can ask about modifier class instances just for this target:
getClassInstances <modifier_class> target:<derived_object>
#3. To get Derived Object we can use:
refs.dependson <the_node>
usually the Derived object is second in the list (the first one has to be the transform controller). But I can’t guaranty it. We have to verify it, and I don’t know mxs method except for parsing dependson list converted to string. :(. This is the bottleneck of the Theory.
Well… Where is the conclusion?
The simple iterating through a list of node’s modifiers to match the class is the fastest and safest method.