|
|
|
08-31-2012, 05:42 PM
|
#1
|
Human being with feelings
Join Date: Feb 2012
Posts: 1,972
|
Selecting only item with specific name (looking for mistake)
I have a part of the code which should select only item with name "Pitch Up" among selected items. But it doesn't work, Only when i have such item (named "Pitch Up") among selected items Reaper freezes...what i'm doing wrong?
Thanks!
Code:
num_items = RPR_CountSelectedMediaItems(0)
i = 0
while i < num_items:
Item_Index = 0
Item_ID = RPR_GetSelectedMediaItem(0, Item_Index)
Current_Take = RPR_GetMediaItemInfo_Value(Item_ID, "I_CURTAKE") # Get active take index for current item
Take_ID = RPR_GetMediaItemTake(Item_ID, int(Current_Take));
Take_Name = RPR_GetSetMediaItemTakeInfo_String(Take_ID, "P_NAME", "", 0)[3] # Get active take name
if Take_Name == "Pitch Up" :
RPR_SetMediaItemInfo_Value(Item_ID, "B_UISEL", 1)
else:
RPR_SetMediaItemInfo_Value(Item_ID, "B_UISEL", 0)
i += 1
Last edited by Viente; 08-31-2012 at 06:06 PM.
|
|
|
09-01-2012, 01:00 AM
|
#2
|
-blänk-
Join Date: Jun 2008
Posts: 11,359
|
Not sure, but it looks like
i += 1
should be executed also when the take name fits. I think now when the take name fits it will go into an infinite loop, because it doesn't change i in that case.
try
Code:
if Take_Name == "Pitch Up" :
RPR_SetMediaItemInfo_Value(Item_ID, "B_UISEL", 1)
else:
RPR_SetMediaItemInfo_Value(Item_ID, "B_UISEL", 0)
i += 1
|
|
|
09-01-2012, 02:14 AM
|
#3
|
Human being with feelings
Join Date: Feb 2012
Posts: 1,972
|
Thanks for reply gofer!
Its not freezes now but still doesnt work (not selecting any item at all)
|
|
|
09-01-2012, 02:53 AM
|
#4
|
-blänk-
Join Date: Jun 2008
Posts: 11,359
|
Maybe it's just missing the
RPR_UpdateTimeline()
at the end?
with that line a quick check seemed to work (deselects all items where the active take isn't called "Pitch Up").
|
|
|
09-01-2012, 03:04 AM
|
#5
|
Human being with feelings
Join Date: Mar 2010
Posts: 4,713
|
Firstly, you don't need 'Item_Index'. The first line of the loop should be:
Item_ID = RPR_GetSelectedMediaItem(0, i)
... otherwise you're not incrementing through items.
But even with that change, it won't work properly in all scenarios; it will miss items sometimes.
Try this:
Code:
num_items = RPR_CountSelectedMediaItems(0)
i = 0
while i < num_items:
item = RPR_GetSelectedMediaItem(0, i)
cur_take = RPR_GetMediaItemInfo_Value(item, "I_CURTAKE")
take = RPR_GetMediaItemTake(item, int(cur_take))
take_name = RPR_GetSetMediaItemTakeInfo_String(take, "P_NAME", "", 0)[3]
if take_name == "Pitch Up": # unselect wanted items
RPR_SetMediaItemInfo_Value(item, "B_UISEL", 0)
else:
i += 1
RPR_Main_OnCommand(41115, 0) # invert item selection
Calling the invert item sel action negates the need to update the arrange again.
- edit - oops - actually no don't use invert item selection - it will mess everything up .... off to lunch now, will reply again at some point
Last edited by timlloyd; 09-01-2012 at 03:10 AM.
|
|
|
09-01-2012, 03:28 AM
|
#6
|
-blänk-
Join Date: Jun 2008
Posts: 11,359
|
Quote:
Originally Posted by timlloyd
Firstly, you don't need 'Item_Index'. The first line of the loop should be:
Item_ID = RPR_GetSelectedMediaItem(0, i)
... otherwise you're not incrementing through items.
|
That's a thing I thought about as well... you're partly right.
He is actually incrementing through items, because items get deselected during the loop and the next item will be Item_Index 0.
But (and this I didn't think about earlier):
That's true only until the take is called "Pitch Up". It stays selected, so the next loop iteration will use the same item again. and again until i = num_items.
Probably it will work to accumulate a list of "to be deselected" items in the loop (not doing Item_Index =0) and deselect them afterwards in a separate step.
EDIT: or - in the original script - increment Item_Index by 1 if Take_Name == "Pitch Up". (That would afford the line Item_Index = 0 to be before the loop, not inside, to not reset it to zero again)
Last edited by gofer; 09-01-2012 at 03:35 AM.
|
|
|
09-01-2012, 03:42 AM
|
#7
|
Human being with feelings
Join Date: Mar 2010
Posts: 4,713
|
Quote:
Originally Posted by gofer
But (and this I didn't think about earlier):
That's true only until the take is called "Pitch Up". It stays selected, so the next loop iteration will use the same item again. and again until i = num_items.
|
True - I'm now remembering I had the same problem a while ago.
Quote:
Probably it will work to accumulate a list of "to be deselected" items in the loop (not doing Item_Index =0) and deselect them afterwards in a separate step.
|
yep
Quote:
EDIT: or - in the original script - increment Item_Index by 1 if Take_Name == "Pitch Up". (That would afford the line Item_Index = 0 to be before the loop, not inside, to not reset it to zero again)
|
yeah that's what you want:
Code:
num_items = RPR_CountSelectedMediaItems(0)
i = 0
for j in range(0, num_items):
item = RPR_GetSelectedMediaItem(0, i)
cur_take = RPR_GetMediaItemInfo_Value(item, "I_CURTAKE")
take = RPR_GetMediaItemTake(item, int(cur_take))
take_name = RPR_GetSetMediaItemTakeInfo_String(take, "P_NAME", "", 0)[3]
if take_name == "TEST":
RPR_SetMediaItemInfo_Value(item, "B_UISEL", 1)
i += 1
else:
RPR_SetMediaItemInfo_Value(item, "B_UISEL", 0)
RPR_UpdateArrange()
|
|
|
09-01-2012, 06:46 AM
|
#8
|
Human being with feelings
Join Date: Feb 2012
Posts: 1,972
|
I luv you guys
|
|
|
Thread Tools |
|
Display Modes |
Linear Mode
|
Posting Rules
|
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
HTML code is Off
|
|
|
All times are GMT -7. The time now is 03:32 AM.
|