[Closed] Adding custom attributes in a loop
Hi,
I am scripting a hand controller, with an attribute holder having separate rollouts per finger, and I’ve got the same amount of attributes to add to each finger. I thought that instead of typing each one separately, I’d loop over them and get it done in less code. 3ds max, however, doesn’t like my method of doing this…
Here’s a stripped down version of the code:
handMod = $'Hand_R_CTL'.modifiers[1]
for i = 1 to 5 do
(
-- Build finger attributes
ca = attributes controls
(
parameters inparams rollout:fingR
(
finger_bend type:#float ui:finger_bend_sp
finger_curl type:#float ui:finger_curl_sp
)
rollout fingR ("Transforms")
(
spinner finger_bend_sp "Bend" range:[-1000000, 1000000, 0]
spinner finger_curl_sp "Curl" range:[-1000000, 1000000, 0]
)
)
custAttributes.add handMod ca
)
Running this code, only gives me a single rollout inside the attribute holder. Strangely enough (at least for me), if I script this as a copy-pasted repeated process, it works as it should. Like this:
handMod = Hand_R_CTL'.modifiers[1]
ca = attributes controls
(
parameters inparams rollout:fingR
(
finger_bend type:#float ui:finger_bend_sp
finger_curl type:#float ui:finger_curl_sp
)
rollout fingR ("Transforms")
(
spinner finger_bend_sp "Bend" range:[-1000000, 1000000, 0]
spinner finger_curl_sp "Curl" range:[-1000000, 1000000, 0]
)
)
custAttributes.add handMod ca
ca = attributes controls
(
parameters inparams rollout:fingR
(
finger_bend type:#float ui:finger_bend_sp
finger_curl type:#float ui:finger_curl_sp
)
rollout fingR ("Transforms")
(
spinner finger_bend_sp "Bend" range:[-1000000, 1000000, 0]
spinner finger_curl_sp "Curl" range:[-1000000, 1000000, 0]
)
)
custAttributes.add handMod ca
Does anyone out in the wonderful world of the information highway know why??
It has to do with the attributeID of the CA, each CA has to have it’s ow unique ID, it gets generated automaticly when defining a CA. There can be only 1 CA with that ID, so adding a similar CA in a scene will not work, with the ID’s max can establish if CA’s are instances or unique. So you would need to somehow copy a CA and generate a new ID per itteration. But I found no simple solution yet. Maybe someone else has a bit more experience with CA’s
-Johan
Ok this works:
handMod = $.modifiers[1]
-- Build finger attributes
for i in 1 to 5 do
(
caExe = "ca = attributes controls
"
caExe += "(
"
caExe += " parameters inparams rollout:fingR
"
caExe += " (
"
caExe += " finger_bend type:#float ui:finger_bend_sp
"
caExe += " finger_curl type:#float ui:finger_curl_sp
"
caExe += " )
"
caExe += " rollout fingR (\"Transforms"+(i as string)+"\")
"
caExe += " (
"
caExe += " spinner finger_bend_sp \"Bend\" range:[-1000000, 1000000, 0]
"
caExe += " spinner finger_curl_sp \"Curl\" range:[-1000000, 1000000, 0]
"
caExe += " )
"
caExe +=")
"
execute caExe
custAttributes.add handMod ca
custAttributes.makeUnique handMod ca
)
Executing creates a new CA each itteration, use string to custumize some more.
Cheers,
-Johan
Btw, I think because we’re in the same timezone I reply frequently on your questions, most others have mostly been answered by the time I wake up I swear I don’t do stalking
Hey – thanks again Johan! I shall seek you out and buy you a beer next time I’m in Holland
Great with the walkaround, I’ll try and see if it works with the rest of my script.
Cheers!
I finally got this implemented into my rig, and it works beautifully. Thanks again Johan