Advertisement
duquesne9

Renumber cues with prefix

Sep 24th, 2020
4,279
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. --Shft+Ctrl+R Prepend Q# of selected cue(s) [BROKEN]
  2. (*
  3. Tested with QLab v3.2.14 Oct 2018
  4. Please report any issues to robotlightsyou@gmail.com with subject "QLAB 3 template issues"
  5.  
  6. Original from Rich Walsh template.*)
  7.  
  8. set userIncrement to 1 -- Use this to specify the increment between numbers
  9.  
  10. -- Declarations
  11.  
  12. global dialogTitle
  13. set dialogTitle to "Renumber with a prefix"
  14.  
  15. -- Main routine
  16.  
  17. set startingNumber to text returned of (display dialog "WARNING: This script will renumber cues incremented by 1.
  18.  
  19. Enter the Cue Number for the first selected cue:" with title dialogTitle with icon 1 ¬
  20.     default answer "" buttons {"Cancel", "OK"} default button "OK" cancel button "Cancel")
  21.  
  22. set thePrefix to startingNumber
  23. set theSuffix to ""
  24. set nonNumberFound to false
  25.  
  26. repeat with i from (count characters of startingNumber) to 1 by -1
  27.     if character i of startingNumber is not in characters of "0123456789" then
  28.         set nonNumberFound to true
  29.         set thePrefix to (characters 1 thru i of startingNumber) as text
  30.         try -- If the last character is not a number then theSuffix remains as ""
  31.             set theSuffix to (characters (i + 1) thru end of startingNumber) as text
  32.         end try
  33.         exit repeat
  34.     end if
  35. end repeat
  36.  
  37. if nonNumberFound is false then -- Edge case where the text entered is a number with no prefix
  38.     set thePrefix to ""
  39.     set theSuffix to startingNumber
  40. end if
  41.  
  42. set theSuffix to theSuffix as integer
  43.  
  44. tell application id "com.figure53.QLab.4" to tell front workspace
  45.    
  46.     set selectedCues to (selected as list)
  47.    
  48.     -- Clear existing Cue Numbers
  49.    
  50.     repeat with eachCue in selectedCues
  51.         set q number of eachCue to ""
  52.     end repeat
  53.    
  54.     -- Get a list of numbers that can't be used
  55.    
  56.     set allNumbers to q number of cues
  57.     set allNumbersRef to a reference to allNumbers
  58.    
  59.     -- Renumber the cues
  60.    
  61.     repeat with eachCue in selectedCues
  62.         set newNumber to (thePrefix & theSuffix) as text
  63.         repeat until newNumber is not in allNumbersRef -- If the number is in use, then skip it
  64.             set theSuffix to theSuffix + userIncrement
  65.             set newNumber to (thePrefix & theSuffix) as text
  66.         end repeat
  67.         set q number of eachCue to newNumber
  68.         set theSuffix to theSuffix + userIncrement
  69.     end repeat
  70.    
  71. end tell
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement