[Closed] get layer from name equivalent for animation layers?
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
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
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
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 said
I 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, and learn from there. Apply what you learn to your own code, and post your code when you have problems.
-Eric
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
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
[i][b]return cnt2 -- when the pattern is matched return the layer index[/b][/i]
exitNow = true -- set exitNow to true to stop the name compare loop
)
)
)
animLayerManager.setLayerMute (findAnimLayerNames "anim*") true
im still testing, but probably yes
what you think is better, doing that function, or simply muting layer from index number?
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
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