Icon representing a recipe

Recipe: is_info 0.4

created by robgee

Profile


Name
is_info 0.4
ID
102988
Shared with
Public
Parent
None
Children
None
Created on
January 08, 2019 at 21:00 PM UTC
Updated on
January 08, 2019 at 21:00 PM UTC
Description

Create copypastable list of user-choice type of segments.

Best for


Code


-- is_info v0.4 -- prints user-choice type of segments in a dialog for copy/paste ctrl-s,ctrl-c -- user-choice types: frozen, UN-Locked, mutable, selected. -- added option to make a ranged list as output instead of csv. -- replaced range extraction code with rosetta-code -- https://www.rosettacode.org/wiki/Range_extraction#Lua -- 08/01/2018 robgee -- Thanks to LociOiling and Timo van der Laan for ideas and code. -- To do: -- do something if resultant list is empty e.g if nothing is frozen -- Condense output dialogs and segment counters into 2 functions. -- ================================================================= -- GLOBALS RANGE=false TEXT2='' -- function ListToRange(listwork) --https://www.rosettacode.org/wiki/Range_extraction#Lua local txt = '' if not RANGE then for i=1, #listwork do txt=txt..listwork[i]..',' end TEXT2=string.sub(txt,0,-2) else local startValue = nil for index, value in pairs(listwork) do if listwork[index + 1] == value + 1 then --are sequential if not startValue then startValue = value end -- else if startValue then txt = txt .. startValue .. "-" .. value .. "," startValue = nil else txt = txt .. value .. "," end end end TEXT2=string.sub(txt,0,-2) print(TEXT2) end end -- ========================================= function selected_dialog() dlg2 = dialog.CreateDialog ( "Selected segments list" ) dlg2.info2 = dialog.AddTextbox("Selected:", TEXT2) dlg2.ok = dialog.AddButton ( "OK", 1) dlg2.cancel2 = dialog.AddButton ( "Cancel", 0 ) if (dialog.Show(dlg2) > 0) then return true else print("Dialog cancelled") return ('exit') end end function selected() print('Selected segments:') local numSegs =structure.GetCount() local slct=0 local i=0 local out_table={} for i=1,numSegs do slct=selection.IsSelected(i) if slct==true then out_table[#out_table+1]=i print(i) end end print('How many selected segments:',selection.GetCount()) ListToRange(out_table) --modifies global out_table and TEXT2 selected_dialog() end function mut_dialog() dlg2 = dialog.CreateDialog ( "Mutable segments list" ) dlg2.info2 = dialog.AddTextbox("Mutable:", TEXT2) dlg2.ok = dialog.AddButton ( "OK", 1) dlg2.cancel2 = dialog.AddButton ( "Cancel", 0 ) if (dialog.Show(dlg2) > 0) then return true else print("Dialog cancelled") return ('exit') end end function mutable() print('Mutable segments:') local numSegs =structure.GetCount() local count=0 local i=0 local out_table={} for i=1,numSegs do zap=structure.IsMutable(i) if zap==true then out_table[#out_table+1]=i print(i) count=count+1 end end print('This many mutable segments:',count) ListToRange(out_table) --modifies global TEXT2 mut_dialog() end function freeze_dialog() dlg2 = dialog.CreateDialog ( "Frozen segments list" ) dlg2.info2 = dialog.AddTextbox("Frozen:", TEXT2) dlg2.ok = dialog.AddButton ( "OK", 1) dlg2.cancel2 = dialog.AddButton ( "Cancel", 0 ) if (dialog.Show(dlg2) > 0) then return true else print("Dialog cancelled") return ('exit') end end function frozen() print('Frozen segments:') local numSegs =structure.GetCount() local frap=0 local i=0 local out_table={} for i=1,numSegs do frap=freeze.IsFrozen(i) if frap==true then out_table[#out_table+1]=i print(i) end end print('How many frozen segments:',freeze.GetCount()) ListToRange(out_table) --modifies global out_table and TEXT2 freeze_dialog() end function lock_dialog() dlg2 = dialog.CreateDialog ( "Un-locked segments list" ) dlg2.info2 = dialog.AddTextbox("Free:", TEXT2) dlg2.ok = dialog.AddButton ( "OK", 1) dlg2.cancel2 = dialog.AddButton ( "Cancel", 0 ) if (dialog.Show(dlg2) > 0) then return true else print("Dialog cancelled") return ('exit') end end function nlocked() print('Not locked segments:') local numSegs =structure.GetCount() local i=0 local lk_count=0 local out_table={} for i=1,numSegs do lap=structure.IsLocked(i) if lap==false then out_table[#out_table+1]=i print(i) lk_count=lk_count+1 end end print('How many Un-locked segments:',lk_count) ListToRange(out_table) --modifies global out_table and TEXT2 lock_dialog() end -- =========================================================== function cleanup(err) print('Cleaning up.') print(err) end -- ============================================================= function Get_param() dlg = dialog.CreateDialog ( "is_info v0.4" ) dlg.rangg = dialog.AddCheckbox( 'Output list in Range format', false) dlg.tip = dialog.AddLabel('Tick one box only') dlg.info1 = dialog.AddCheckbox('Is Frozen', false) dlg.info2 = dialog.AddCheckbox('Is Not-locked', false) dlg.info3 = dialog.AddCheckbox('Is Mutable', false) dlg.info4 = dialog.AddCheckbox('Is Selected', false) dlg.ok = dialog.AddButton ( "OK", 1) dlg.cancel2 = dialog.AddButton ( "Cancel", 0 ) if (dialog.Show(dlg) > 0) then RANGE=dlg.rangg.value if (dlg.info1.value ==true) then return ('F') elseif (dlg.info2.value ==true) then return ('L') elseif (dlg.info3.value ==true) then return ('M') elseif (dlg.info4.value ==true) then return ('S') else print('You need to tick one checkbox') Get_param() end else print("Dialog cancelled") return ('exit') end end function main() print(' is_info v04') print('Total amount of segments:',structure.GetCount() ) whutdo=Get_param() if whutdo =='F' then frozen() elseif whutdo =='L' then nlocked() elseif whutdo =='M' then mutable() elseif whutdo =='S' then selected() else return end end -- ================== xpcall(main,cleanup) -- end recipe

Comments


robgee Lv 1

Simple utility recipe to create copy/paste-able list
of segments that are:
Frozen, Mutable, Not-locked, Selected.
Option: Range format e.g 21-30,42,70-79
Option: Comma separated single segments e.g 21,22,23,24,25, etc

Select your favorite segments, run this, copy the list and paste
into another recipe, text file or spreadsheet.

Thanks to LociOiling for the copy/paste idea.