 |
|
|
01-19-2019, 03:53 PM
|
#1
|
Human being with feelings
Join Date: Mar 2016
Posts: 600
|
Prevent Undo list entries
Hi
I have a script which I'd like NOT to generate an entry in the Undo history.
This seems easy to do - just don't include the "Begin Undo Block" and "End Undo Block" code.
However, during the script I use the function
reaper.SelectAllMediaItems(0,0) to clear the selection
and this DOES generate an entry in the Undo list.
Is it possible to stop any "native actions" (such as that function to deselect all) within the script from creating Undo points?
Thanks
Andy
|
|
|
01-20-2019, 02:53 AM
|
#2
|
Human being with feelings
Join Date: Apr 2011
Posts: 1,462
|
Try this in the end of your script:
Code:
reaper.defer(function() end)
|
|
|
01-20-2019, 03:00 AM
|
#3
|
Human being with feelings
Join Date: Mar 2016
Posts: 600
|
OK, thanks I'll try it.
Can you explain why that might have the desired effect?
Deferring a non-existent function - why would that affect Undo entries, and would it have any impact on Reaper's performance? (My understanding is that defer functions are called roughly 30 times a second, so will that have a noticeable impact even if the function that's called does nothing?)
Cheers
Andy
|
|
|
01-20-2019, 07:05 AM
|
#4
|
Administrator
Join Date: Jan 2005
Location: NYC
Posts: 11,796
|
The correct way is to restore the state to where you started before calling endblock -- if the user has undo for selection state configured, then you really do want to have an undo point added when you clear the selected item states (as otherwise you will end up in inconsistent states).
The defer trick (which is harmless, it only runs the script once) does work, because undo points are not added automatically for scripts that are deferred (since they might want to wait until a longer process is done).
|
|
|
01-20-2019, 07:54 AM
|
#5
|
Human being with feelings
Join Date: Mar 2016
Posts: 600
|
Thanks Justin
I'm not sure I understand though.
My script uses the reaper.SetMediaItemsSelected (0,0) function in the middle of it, but by the end of the script I have restored the original selection (which I saved to an array at the beginning).
Yet, without any Undo code on the script the Reaper Undo window shows entries for Deselect All Items, but not anything for the other things the script is doing (such as nudging, selecting things again etc).
Andy
|
|
|
01-20-2019, 10:20 AM
|
#6
|
Human being with feelings
Join Date: Jul 2010
Location: Slovakia
Posts: 724
|
There are some functions which generates undo points despite the script being deferred.
Most recently I found reaper.ReorderSelectedTracks() doing that and some time before another function but cannot remember what it was, probably something with item manipulation. Also reaper.Main_OnCommand() calls does generate undo.
So, is it expected that these few functions does generate undo even if they are in ad deferrescript or is it a bug?
|
|
|
01-20-2019, 12:02 PM
|
#7
|
Human being with feelings
Join Date: Oct 2007
Location: home is where the heart is
Posts: 8,388
|
I think in your case you could avoid creating the undo point replacing reaper.SelectAllMediaItems(0,0) with looping through all items and set them unselected with SetMediaItemInfo_Value() (using B_UISEL)
edit:
Or SetMediaItemSelected()
Last edited by nofish; 01-20-2019 at 12:08 PM.
|
|
|
01-20-2019, 12:08 PM
|
#8
|
Human being with feelings
Join Date: Mar 2016
Posts: 600
|
Thanks - yes, I could do that, I just thought the native function would be quicker (to write, and to perform!)
Will give it a go, though.
Andy
|
|
|
01-20-2019, 12:18 PM
|
#9
|
Human being with feelings
Join Date: Oct 2007
Location: home is where the heart is
Posts: 8,388
|
Quote:
Originally Posted by andyp24
I just thought the native function would be quicker (to write, and to perform!)
|
I go along with this of course. 
Just wanted to mention as possible workaround.
I too wish we had more control over when undo points are created or not, e.g.
https://forum.cockos.com/showthread.php?t=215672
|
|
|
01-20-2019, 01:47 PM
|
#10
|
Human being with feelings
Join Date: May 2017
Location: Leipzig, Germany
Posts: 725
|
Yes, the Undo/Redo/NoUndo-behavior of Reaper definetely needs some more love, as the scripter's needs surpassed the current possibilities by far in the meantime...
|
|
|
01-20-2019, 04:12 PM
|
#11
|
Human being with feelings
Join Date: Dec 2009
Location: Axis Mundi
Posts: 5,427
|
Any way to do this in a Cycle Action?
|
|
|
01-20-2019, 04:21 PM
|
#12
|
Administrator
Join Date: Jan 2005
Location: NYC
Posts: 11,796
|
Quote:
Originally Posted by andyp24
My script uses the reaper.SetMediaItemsSelected (0,0) function in the middle of it, but by the end of the script I have restored the original selection (which I saved to an array at the beginning).
|
If you use Undo_BeginBlock(), then save selection,clear selection, restore selection, and do Undo_EndBlock(), then it should eliminate the undo state point (unless something else changed). You can right click the undo point in the undo history and go to the "Undo state information" submenu to see what changed (click an item and it'll show you a diff).
|
|
|
01-20-2019, 04:49 PM
|
#13
|
Human being with feelings
Join Date: Jan 2012
Posts: 476
|
Quote:
Originally Posted by mespotine
Yes, the Undo/Redo/NoUndo-behavior of Reaper definetely needs some more love
|
If it was in the action list. Another checkbox next to "consolidate undo points" that says "no undo"
I guess it's a big one to implement otherwise it would be there already..
|
|
|
01-21-2019, 01:55 AM
|
#14
|
Human being with feelings
Join Date: Mar 2016
Posts: 600
|
Quote:
Originally Posted by Justin
If you use Undo_BeginBlock(), then save selection,clear selection, restore selection, and do Undo_EndBlock(), then it should eliminate the undo state point (unless something else changed). You can right click the undo point in the undo history and go to the "Undo state information" submenu to see what changed (click an item and it'll show you a diff).
|
Thanks Justin
The script nudges edges of some items, and then nudges a different selection of whole items.
So, between saving the selection, deselecting everything and restoring the original selection, quite a few things happen. It just seems odd that the only one of the actions I'm performing in the script to leave a trace in the Undo History is that SetMediaItemsSelected (0,0) line.
|
|
|
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 01:06 AM.
|