[Closed] Running un-scripted commands
Can I perform commands that aren’t listed in the maxscript help but are listed as UI commands (eg. trackview zoom horizontal extents)? I can’t do a macros.run because they aren’t macroscripts.
:¬/
Ah. I’ve managed to find the zoom horizontal extents actionman command through the macro recorder when I assigned it to a quadmenu item.
Now that that’s found, I want to be able to store all of the selected objects’ keyframes in an array of the frame numbers that they occur on.
How do I do that?
hi brad,
the .keys property for a specific controller will provide a MAXkeyarray.
so any animated track ie $.position.controller.keys or $.modifiers[“bend”].controller.keys for example gives an array of key times.
to extract more information like values and tangent type, you will have to use the key index. for example, this will set an object’s visibiliy controller –
local tvis = obj.visibility.controller
addnewkey tvis currenttime
keyind = getKeyIndex tvis currenttime
tvis.keys[keyind].value = visval
tvis.keys[keyind].inTangentType = #step
tvis.keys[keyind].outTangentType = #auto
hope this helps,
Pete
Thanks for the reply pudgerboy.
What I’m actually after is the frame numbers of the earliest and latest of the selected keys in a selection of objects. Unfortunately, I can’t be as specific as ($.pos.controller.keys 1) as I want to cycle through all keys on all controllers on all selected objects.
I’m experimenting with .numsubs at the moment and trying to pull keys out of them but there is a lot of looping to do. I guess what I want to know is am I on the right track to loop through the selection, then loop through all of their animated tracks and then loop through all of their keys to find the selected ones and then finally put the frames their on info into an array?
:¬)
hi brad,
Ah okay, I get what you mean. You might want to look into using a mapped function rather than a for loop for what you are doing. You basically pass an array as the first argument in the function and it performs the function on each element of the array. That might be easier if you are performing multiple loops and array processing, as you could pass the subanims as an array to be processed by the mapped function.
simple eg –
objarr = selection as array
mapped fn dostuff thearray =
(
thearray.wirecolor = (random red blue)
thearray.pos.z += (random -20 20)
)
dostuff objarr
you can still pass multiple arguments as you would in a normal function, as long as the first argument is still an array.
while i think about it the amin and amax commands might help you with your array handling too – they give the maximum and minimum values from an array. –
arr1 = #(5,1,4,2,8)
amin arr1
amax arr1
result -
1
8
p.s. i should have realised from your site you weren’t after simple key access! that rig of yours is a thing of beauty! how did you do the FK/IK snap?
Thanks for the compliments.
I finally found out how to get all of the selected keys of an objects. The answer came from a script I already had hosted on my website. It came from Grant Adam’s tangent utility script. I’ve amended it here to include custom attribute keys as well.
selKeyArray = #()
fn getAnimProp obj =
(
if obj.numSubs > 0 then
(
for i = 1 to obj.numSubs do
(
getAnimProp obj[i]
)
)
else
(
if (obj.controller != undefined) do
(
if (keyTest = obj.keys) != undefined and keyTest.count > 0 do
(
keytest = obj.keys
for k in 1 to keyTest.count where keytest[k].selected do
(
append selKeyArray keytest[k]
)
)
)
)
)
for o in selection do
(
getAnimProp o
for i in o.modifiers do
(
if (custattributes.count i) > 0 then
(
for j = 1 to (custattributes.count i) do
getAnimProp (custattributes.get i j)
)
)
if (custattributes.count o) > 0 then
(
for i = 1 to (custattributes.count $) do
(
(
getAnimProp (custattributes.get $ i)
)
)
)
)
print selKeyArray
What it does is for each object selected, go through their subanims and if they themselves have subanims go through those. Repeat the process until you come to ones that don't have any, check that they have a controller (to exclude CAs like buttons for example) and have keys on them. If they do, put the selected ones into an array.
From there I extract their time values and use the amin and amax commands to find the earliest and latest keys in the selection.
To cut a long story short, I've used it to make a script that will zoom the trackview to the selected keys (check out the script section of my site). Works a treat and I don't have to request it in max wishlist threads ever again!
:¬)