Get Id of the current track

ZeroValue's icon

hi,
maybe a newbie question, but how to get the ID of the current track ?
I'm able to get the the id of the selected one but not the current one.

ZeroValue's icon

I found a solution by calling the parent of the current device.
Don't know if the most efficient solution.
Hope it helps someone one day

Max Patch
Copy patch and select New From Clipboard in Max.

tyler mazaika's icon

Getting the parent of the current device only returns a Track if your device is not inside of a Rack (e.g. Drum Rack, Instrument Rack). To be more correct in more cases you should either keep getting the parent(s) until you reach an object of type Track.

Alternatively, you can get the path of your device and use [zl.slice] to cut the path items list down to its first four items. For instance a canonical track path like "path live_set tracks 4 devices 2" would become "path live_set tracks 4", which you can then pass to [live.path] to get the id of the track. The downside of this approach is that you need to do a second check because your device may be on the Master track, whose path is always only 3 items long (path live_set master_track).