[Closed] modPanel.getModifierIndex
Simple question here guys. I want to check if a specific modifier is present on an object, and if so return it’s index.
I figure modPanel.getModifierIndex is the best way to do this, but am getting an error thrown when the modifier is not present. According to the help files if the modifier is not present it should be returning undefined, so I think I’m just not entering the modifier into the function properly.
I tried,
modPanel.getModifierIndex $ TurboSmooth
-- Unable to convert: TurboSmooth to type: Modifier
and,
modPanel.getModifierIndex $ $.TurboSmooth
-- Unknown property: "Noise" in $Editable_Mesh:Teapot01 @ [-1.089581,-20.264460,0.000000]
and a few other things as well, but never get the expected result.
Anyways, bit of an embarrassing question because I’m sure it is an incredibly simple answer, but I’m just not sure.
This method will return the index of a specific INSTANCE of a modifier, but you are passing a class name which describes all TurboSmooth modifiers, not YOUR instance that you added to the stack.
Unless you have the actual object stored in a variable to pass to the method, you should rather loop through the modifiers list of the object and compare their class with the one you are looking for, like
theTSMods = for m in myObject.modifiers where classof m == TurboSmooth collect m
This will return an array of all TurboSmooth class modifiers on the stack of myObject.
Then, if there are any modifiers in the array, you can grab the first one, which is the top one (they are always numbered from top to bottom) and use it.
If you want to know which indices your TurboSmooth modifiers have on the stack, you can say
theTSIndex = for m = 1 to myObject.modifiers.count where classof myObject.modifiers[m] == TurboSmooth collect m
This will give you an array of all indices you want.
Well I’m glad its not as simple as I thought it was, don’t feel like as much of an idiot now! haha
Thanks for the explanation as well Bobo, that makes a lot of sense. No wonder it wasn’t working. Much appreciated!