How to Use selectTrack to Automatically Select Desired Animation Track

How to Use selectTrack to Automatically Select Desired Animation Track

ttazinazzo
Participant Participant
721 Views
6 Replies
Message 1 of 7

How to Use selectTrack to Automatically Select Desired Animation Track

ttazinazzo
Participant
Participant

Hey there, I have a question about how to use the selectTrack function in Track View Curve Editor to automatically select the desired animation track through maxscript.

 

Simple example - let's say I have a box created by the following code:

Box pos:[0,0,0] length:10 width:10 height:10 name: "First_Box"
$Box:First_Box @ [0.000000,0.000000,0.000000]

 

I want to create a curve editor trackview window named "Rotation Trackview" and open it in a window, which is accomplished with the following:
sCurveName = "Rotation Trackview"
"Rotation Trackview"
nCurve = trackviews.gettrackview sCurveName

 

I am now trying to use the selectTrack command to select the X rotation track automatically.

This will be helpful because the final project has many objects that need only be animated by one parameter.

However, I am getting the following error:

 

nCurve.selectTrack First_Box.rotation.controller.x_rotation
-- Argument count error: selectTrack wanted 2, got 1
-- MAXScript callstack:
-- thread data: threadID:25804
-- ------------------------------------------------------
-- [stack level: 0]
-- In top-level


nCurve.selectTrack First_Box.rotation.controller.x_rotation true
-- Runtime error: Attempt to access deleted scene object
-- MAXScript callstack:
-- thread data: threadID:25804
-- ------------------------------------------------------
-- [stack level: 0]
-- In top-level

 

Can someone explain how to use the selectTrack command properly in this example? The idea will be to be able to force the selection in the trackview window when the script is run.

Thank you!

0 Likes
Accepted solutions (1)
722 Views
6 Replies
Replies (6)
Message 2 of 7

Swordslayer
Advisor
Advisor
Accepted solution

Provided that First_Box is a variable that contains the node, and in case that filtering only selected objects is active also only if the object is selected beforehands, you're still missing the second argument (as the error message tells you) and you are giving it controller value at current time, not the controller itself. See the function signature:

 


<boolean>selectTrack <maxObject>object <boolean>clearSelection

Selects the specified object. If clearSelection is supplied as true, clears any previous selection.


So the first part of creating the object would be let's say 

 

 

First_Box = Box pos:[0,0,0] length:10 width:10 height:10 name:"First_Box" isSelected:on

 

 

then you open the trackview window, and the last part would be

 

nCurve.selectTrack First_Box.rotation.controller.x_rotation.controller True

 

Message 3 of 7

ttazinazzo
Participant
Participant

That's perfect, exactly what I needed. Thank you!

 

So essentially First_Box.rotation.controller.x_rotation would just be one argument and is the current value of the x rotation at the current time, correct?

And then the additional .controller is what points to the actual controller - out of curiosity do you know the logic for why the syntax has to list the .controller twice?

0 Likes
Message 4 of 7

Swordslayer
Advisor
Advisor

@ttazinazzo wrote:

And then the additional .controller is what points to the actual controller - out of curiosity do you know the logic for why the syntax has to list the .controller twice?


It's not twice, first one is the XYZ controller that has x_rotation, y_rotation and z_rotation properties, and each of them has their own controllers (in the most common case those would be Bezier Float ones).

0 Likes
Message 5 of 7

ttazinazzo
Participant
Participant

Understood, thank you - follow up question below (I replied to the wrote message sorry)

0 Likes
Message 6 of 7

ttazinazzo
Participant
Participant

Understood. A follow up question if I may - the indexing you suggested works perfectly with the position and rotation transform tracks of the First_Box object created. Now I'm also trying to figure out the indexing of selectTrack when working with custom attributes created for a dummy object that is a child to First_Box.

 

Same example above, with First_Box being created.

Then I created a dummy object and dragged it under First_Box so First_Box is the parent and Dummy001 is the child.

Within Dummy001 I made a custom attribute and named it Pitch.

The hierarchy is as follows:

 

ttazinazzo_0-1656078520421.png

 

Do you know how I would index to select pitch?

 

I tried the following with no luck:

 

nCurve.selectTrack First_Box.Dummy001.Custom_Attributes.pitch.controller True

nCurve.selectTrack Dummy001.Custom_Attributes.pitch.controller True

nCurve.selectTrack Dummy001.Custom_Attributes[Pitch] True

 

All result in:
-- Unknown property: "Custom_Attributes" in undefined
-- MAXScript callstack:
-- thread data: threadID:25804
-- ------------------------------------------------------
-- [stack level: 0]
-- In top-level

0 Likes
Message 7 of 7

Swordslayer
Advisor
Advisor

Again, there's misunderstanding on your side what's object name and what's variable name - Dummy001 is object name, you can't use it like this. Technically you can get the object by its name but since the names are non-unique in max it's a bad practice - and since you're the one creating the objects,  you should just assign it to a variable as you create it (I highly recommend watching the MAXScript 101 series on vimeo, without learning the basics you won't get far). For the actual code once you have the object in the variable you refer to, you also have to make sure the subanim actually has a controller if you use selectTrack rather than selectTrackByIndex.

0 Likes