[Closed] Check for skin modifier.. weird results
I’m working on creating a script that will require first checking to see if an object has a skin modifier. I thought I knew how to do this, but when I tried I was getting false positives. After putting in a few format lines to debug,
hasSkin = false
for i = 0 to $.modifiers.count do
(
format "hasSkin = %
" hasSkin
if $.modifiers[i] == modifier_skin do (hasSkin = true)
format "modifer %: %
" i $.modifiers[i]
format "hasSkin = %
" hasSkin
)
the results I keep getting for an object with no modifiers are:
false
hasSkin = false
modifer 0: undefined
hasSkin = true
OK
OK
I don’t understand what I’m doing wrong…?
Hi Kevin,
modifiers is an array and starts from index 1, that’s why you got that “modifier 0: undefined”. Then you need to check the modifier class to be sure it is what you’re looking for, in this case it is ‘Skin’.
hasSkin = false
for i = 1 to $.modifiers.count do
(
if ((classOf $.modifiers[i]) == Skin) then
(
hasSkin = true
)
)
format "hasSkin = %
" hasSkin
- Enrico
Or
(for m in $.modifiers where isKindOf m skin collect m).count
Will return the amount of skin modifiers so test if the outcome is 0.
-Johan
Thanks both, I realized my mistake shortly after posting, but
(for m in $.modifiers where isKindOf m skin collect m).count
wow, is that tight code!
(selection[1].skin != undefined)
or
(selection[1].modifiers[#skin] != undefined)