PDA

View Full Version : get layer from name equivalent for animation layers?


fael097
11-04-2010, 07:47 PM
hi, im looking for a way to assing hiding / showing animation layers through an attribute holder modifier, with custom attributes on it, like checkboxes. i want to be able to display(enable) an animation layer when a checkbox is checked, and hide when it is unchecked, but im having a hard time trying to figure it out.
right now im stuck at getting it from name.

with regular layers, i would do the following:
LM=LayerManager.GetLayerFromName "MyLayer"
LM.isHidden = true
but dont know how to do with animation layers.

also, i still havent figured out how to assign that to work with the checkboxes yet. so any helpful thoughts are welcome.

thanks

PiXeL_MoNKeY
11-04-2010, 09:31 PM
but dont know how to do with animation layers.You can't. You would need to write a function to that wouls collect all animation layer names, then you would need to compare your desired string name with those, and then return the layer index that matches its place in the array.also, i still havent figured out how to assign that to work with the checkboxes yet. so any helpful thoughts are welcome.You would need to use a checkbox "Event" (look it up in the help file) to trigger the change, and then wrap the code you want to use inside that event. Like I did on your Wing Control script.

-Eric

fael097
11-05-2010, 11:43 AM
aye, got how to trigger checkboxes, let me ask you, will it work only if i set onchange TheState, or theres such thing as when checked so something, when checked do other thing?

what i dont know is how exactly to make that function you said

PiXeL_MoNKeY
11-05-2010, 03:41 PM
aye, got how to trigger checkboxes, let me ask you, will it work only if i set onchange TheState, or theres such thing as when checked so something, when checked do other thing?From the checkbox page:on <checkbox> changed <arg> do <expr>

Called when the user clicks the check box to check or uncheck it. The <arg> argument contains the new state of the check box, on (true) or off (false).Read the highlighted portion. The arg will be come true if it is checked and false if not. So you would wrap your code in a test of the state of the arg:on theCheckBox changed TheState do (
if TheState == true then (
-- run some code when the box is checked
) else (
-- run different code when false
)
)on theCheckBox changed TheState do (
case TheState of (
true: () -- run some code when the box is checked
false: () -- run different code when false
)
)what i dont know is how exactly to make that function you saidI really don't want to walk you through everything or you will not learn on your own. You will need to collect all names of the animation layers in an array (look "For Loops" in the help) by looping through the layers from 1 to the count of animation layers and adding the layer name to the array. You now have an array where the array index is equal to the index of the animation layers. Now loop through the array and return the index of the layer that matches your name. Now use that index to access the proper animation layer, and execute the code you need on this.

You should really try and figure this stuff out on your own and post code when it doesn't work. People are more willing to help you when you have a problem, than willing to write all the code for you. I think you need to start doing some tutorials on scripting before you try to get into writing your own code. Go through the various "How To" sections of the maxscript help, or the tutorials at scriptspot (http://www.scriptspot.com/3ds-max/tutorials), and learn from there. Apply what you learn to your own code, and post your code when you have problems.

-Eric

fael097
11-09-2010, 04:43 PM
you're right
I assumed that short knowledge in mxs and php skills would help me scripting stuff and to figure stuff by myself, but i was wrong, mxs is so much bigger, and i'd have to start from the beggining.

btw, just wanted to say that the code worked with regular layers:

ca=CustAttributes.getDef $.modifiers[1].Controls
LM=LayerManager.GetLayerFromName "MyLayer"
attributes controls
redefine:ca
(
rollout cbt "Checki"
(
checkButton chbtHideMe "Hide Me"

on chbtHideMe changed theState do
(
case TheState of
(
true:
(
LM.isHidden = true
)
false:
(
LM.isHidden = false
)
)
)
)
)

--custAttributes.add $.modifiers[1] ca


now lemme get started with looping the anim layers to an array.
i get the whole point on looping stuff to arrays, used to do that with php, my trouble is when it comes to mxs, idk the syntaxes you see, for example, i never knew that to get a layer name, i'd have to use LayerManager.GetLayerFromName "the_name" and i also have no idea what to use to loop through the animation layer names, or where to find that in maxscript help lol, but i'll figure out :)

thank you one more time

edit: hmmm interesting :)
AnimLayerManager.setLayerMute 2 true

PiXeL_MoNKeY
11-09-2010, 09:59 PM
Like I said you will need to write a function to do it like this:fn findAnimLayerNames animName = ( -- function where animName is a string that will be used in the loop
exitNow = false --set exitNow variable to false so the name loop will process
layerCnt = AnimLayerManager.getLayerCount() -- get the number of layers
layerNames = for cnt1 in 1 to layerCnt collect (AnimLayerManager.getLayerName cnt1) -- collect all names in the Animation Layers
for cnt2 in 1 to layerNames.count while not exitNow do ( -- Loop through the layer names as long as exitNow is false
if (matchpattern layerNames[cnt2] pattern:animName ignoreCase:true) do ( -- compare the animName string with the layer names
AnimLayerManager.setLayerActive cnt2 -- when the pattern is matched set the layer active
exitNow = true -- set exitNow to true to stop the name compare loop
)
)
)

findAnimLayerNames "base*"It will set the first item that matches the supplied string, and since matchpattern is used you can use wildcards.

-Eric

EDIT: Return index sample: If you change the "AnimLayerManager.setLayerActive cnt2" to "return cnt2" you can use that to for anywhere you need the index number.fn findAnimLayerNames animName = ( -- function where animName is a string that will be used in the loop
exitNow = false --set exitNow variable to false so the name loop will process
layerCnt = AnimLayerManager.getLayerCount() -- get the number of layers
layerNames = for cnt1 in 1 to layerCnt collect (AnimLayerManager.getLayerName cnt1) -- collect all names in the Animation Layers
for cnt2 in 1 to layerNames.count while not exitNow do ( -- Loop through the layer names as long as exitNow is false
if (matchpattern layerNames[cnt2] pattern:animName ignoreCase:true) do ( -- compare the animName string with the layer names
return cnt2 -- when the pattern is matched return the layer index
exitNow = true -- set exitNow to true to stop the name compare loop
)
)
)

animLayerManager.setLayerMute (findAnimLayerNames "anim*") true

PiXeL_MoNKeY
11-10-2010, 03:55 PM
Does this work for what you need?

-Eric

fael097
11-10-2010, 04:02 PM
im still testing, but probably yes

what you think is better, doing that function, or simply muting layer from index number?

PiXeL_MoNKeY
11-10-2010, 05:18 PM
The function will get the layer index based on the name. Otherwise you need to know the specific index number. My solution does what you asked for, you need to figure out how you need to use it.

-Eric

fael097
11-10-2010, 05:31 PM
yeah it worked like i wanted, and since i'll have hundreds of animation layers, i'll probably go for the names.

thank you so very much :)

CGTalk Moderation
11-10-2010, 05:31 PM
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.