Old 06-21-2014, 06:41 AM   #1
george
Human being with feelings
 
george's Avatar
 
Join Date: Mar 2011
Posts: 82
Default create child track script - need your help

hi guys,
i was about to create a python script to automatically create a new track as child of the selected track. thought it would be easy but i'm stuck so i need your help.

below is what i've done so far:

# get the selected track and its depth
# depth: 0=normal [i.e. doesn't have children & is not last], 1=track is a folder parent, -1=track is the last in the innermost folder, -2=track is the last in the innermost and next-innermost folders, etc
selectedTrack = RPR_GetSelectedTrack(0, 0)
depth = RPR_GetMediaTrackInfo_Value(selectedTrack, "I_FOLDERDEPTH")

# this creates the track AFTER the selected track
RPR_InsertTrackAtIndex(<index of selectedTrack>, True)

# if the selected track was already a folder then we're done already
# but if it was not a folder:
if depth != 1:
# make the selected track to be a folder
RPR_SetMediaTrackInfo_Value(selectedTrack, "I_FOLDERDEPTH", 1)
# and make the new track to be the last in folder - set it to minus something
RPR_SetMediaTrackInfo_Value(newTrack, "I_FOLDERDEPTH", <-???>)

So, the problem lies on the last line, how should i compute the value for the folder depth of the new track so the script can support inserting at any level? if i hardcode it to "-1" the script will only support one level deep.

also i think i don't understand how the values for the last tracks in folder are set. take for example the screenshot i attach. although tracks C & E are in the same visual depth, track "C" has I_FOLDERDEPTH=-1 while track "E" has I_FOLDERDEPTH=-2 which seems odd to me.

thanks for the help.
Attached Images
File Type: jpg folders.jpg (32.8 KB, 205 views)
george is offline   Reply With Quote
Old 06-22-2014, 04:43 AM   #2
george
Human being with feelings
 
george's Avatar
 
Join Date: Mar 2011
Posts: 82
Default

the next day is always more clear-thinking. i've found the solution, below the code excerpt:

# get the selected track and its depth
selectedTrack = RPR_GetSelectedTrack(0, 0)
depth = RPR_GetMediaTrackInfo_Value(selectedTrack, "I_FOLDERDEPTH")

# this creates the track AFTER the selected track
RPR_InsertTrackAtIndex(<index of selectedTrack>, True)

# if the selected track was a folder we don't need to do anything more
# but if it was a normal track
if depth == 0:
# make the selected track to be a folder
RPR_SetMediaTrackInfo_Value(selectedTrack, "I_FOLDERDEPTH", 1)
# and the created track to be the last in that folder with single unindented
RPR_SetMediaTrackInfo_Value(newTrack, "I_FOLDERDEPTH", -1)
# or if the selected track was already the last in folder
elif depth < 0:
# make the selected track to be a folder
RPR_SetMediaTrackInfo_Value(selectedTrack, "I_FOLDERDEPTH", 1)
# and the created track to be the last in that folder with one more unindented
RPR_SetMediaTrackInfo_Value(newTrack, "I_FOLDERDEPTH", depth - 1)


and to clear things up folder "depth" is not how deep the track is in the folder hierarchy (relative to the root level), but how deep it is relative to the next track.
george is offline   Reply With Quote
Reply

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT -7. The time now is 01:46 PM.


Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2024, vBulletin Solutions Inc.