Code
--Band Copy Paste by Bruno Kestemont 7/12/2014, based on modules by Jean-Bob and Timo vdL
--Copy existing bands to note and keyboard
--Paste it again in another version of the same puzzle
--It's a way to save bands and restore them afterwards. Like for Quest to the Native puzzles.
--v1.2= added band length
--v1.3 added option to copy-paste lengths and strengths
--v1.3.2 trying to fix bug deleted bands
--v1.4 better dialog and respects enabled/disabled 7/12/2014
--v1.5 worked on copying more details, including atoms
recipename="Band Copy-Paste 1.5 by BK"
--USER OPTIONS (to be used in dialog box)
multiplier=1
--SLOTS:
bsslot=3 -- back up slot
--INITS
ubandlist= {}
ubcount=band.GetCount()
OriginalFilterSetting = behavior.GetSlowFiltersDisabled()
PossibleRange=true
strengthtable={} -- global
segments=structure.GetCount()
-- Segment set and list module
-- Notice that most functions assume that the sets are well formed
-- (=ordered and no overlaps)
-- 02-05-2012 TvdL Free to use for non commercial purposes
-- 05-02-2014 BK enhanced (also Free for non commercial purposes)
-- a list is {1,2,3,8,9,10}. A set is {{1,4},{8,10}} or something like that in a 2-dimentional table:
--i {[1],[2]}
--___________
--1 { 1 , 4 }
--2 { 8 , 10}
function SegmentExtendSet(set,x,y) -- New BK 05/02/2014 x, y= nb of seg to add before and after each zone
local result={}
local x,y=x or 1, y or 1
for i=1,#set do
if set[i][1]<1+x then --first segment
result[i]={set[i][1],set[i][2]+y}
elseif set[i][2]>set[#set][2]-y then --last segment
result[i]={set[i][1]-x,set[i][2]}
else
result[i]={(set[i][1]-x and set[i][1]>x) or set[i][1] , (set[i][2]<=set[#set][2]-y and set[i][2]+y) or set[i][2]}
result[i]={set[i][1]-x ,set[i][2]+y}
end
end
return result -- overlaps are possible
end
function SegmentListToSet(list) --note: clean duplicates
local result={}
local f=0
local l=-1
table.sort(list)
for i=1,#list do
if list[i] ~= l+1 and list[i] ~= l then
-- note: duplicates are removed
if l>0 then result[#result+1]={f,l} end
f=list[i]
end
l=list[i]
end
if l>0 then result[#result+1]={f,l} end
--print("list to set")
--SegmentPrintSet(result)
return result
end
function SegmentSetToList(set)
local result={}
for i=1,#set do
--print(set[i][1],set[i][2])
for k=set[i][1],set[i][2] do
result[#result+1]=k
end
end
return result
end
function SegmentCleanSet(set) -- clean duplicates
-- Makes it well formed and clean duplicates
return SegmentListToSet(SegmentSetToList(set))
end
function SegmentInvertSet(set,maxseg)
-- Gives back all segments not in the set
-- maxseg is added for ligand
local result={}
if maxseg==nil then maxseg=structure.GetCount() end
if #set==0 then return {{1,maxseg}} end
if set[1][1] ~= 1 then result[1]={1,set[1][1]-1} end
for i=2,#set do
result[#result+1]={set[i-1][2]+1,set[i][1]-1}
end
if set[#set][2] ~= maxseg then result[#result+1]={set[#set][2]+1,maxseg} end
return result
end
function SegmentInList(s,list)
table.sort(list)
for i=1,#list do
if list[i]==s then return true
elseif list[i]>s then return false
end
end
return false
end
function SegmentInSet(set,s)
for i=1,#set do
if s>=set[i][1] and s<=set[i][2] then return true
elseif s<set[i][1] then return false
end
end
return false
end
function SegmentJoinList(list1,list2) -- duplicates allowed
local result=list1
if result == nil then return list2 end
for i=1,#list2 do result[#result+1]=list2[i] end
table.sort(result)
return result
end
function SegmentJoinSet(set1,set2) -- no duplicates, no overlap
return SegmentListToSet(SegmentJoinList(SegmentSetToList(set1),SegmentSetToList(set2)))
end
function SegmentCommList(list1,list2) -- what is common to 2 lists
local result={}
table.sort(list1)
table.sort(list2)
if #list2==0 then return result end
local j=1
for i=1,#list1 do
while list2[j]<list1[i] do
j=j+1
if j>#list2 then return result end
end
if list1[i]==list2[j] then result[#result+1]=list1[i] end
end
return result
end
function SegmentCommSet(set1,set2) -- what is common to set 1 and set 2 (no duplicate)
return SegmentListToSet(SegmentCommList(SegmentSetToList(set1),SegmentSetToList(set2)))
end
function SegmentSetMinus(set1,set2) -- set1 minus set2 (set1 minus what is common to set 1 and set2)(no duplicate)
return SegmentCommSet(set1,SegmentInvertSet(set2))
end
function SegmentPrintSet(set)
print(SegmentSetToString(set))
end
function SegmentSetToString(set)
local line = ""
for i=1,#set do
if i~=1 then line=line..", " end
line=line..set[i][1].."-"..set[i][2]
end
return line
end
function SegmentSetInSet(set,sub)
if sub==nil then return true end
-- Checks if sub is a proper subset of set
for i=1,#sub do
if not SegmentRangeInSet(set,sub[i]) then return false end
end
return true
end
function SegmentRangeInSet(set,range)
if range==nil or #range==0 then return true end
local b=range[1]
local e=range[2]
for i=1,#set do
if b>=set[i][1] and b<=set[i][2] then
return (e<=set[i][2])
elseif e<=set[i][1] then return false end
end
return false
end
function SegmentSetToBool(set)
local result={}
for i=1,structure.GetCount() do
result[i]=SegmentInSet(set,i)
end
return result
end
helptext="" -- for dialog
function SegmentMatrixToString(matrix, dimension, fieldD, field, recorD, record, printN) -- New BK 14/10/2014
local fieldD=fieldD or ";" -- field delimiter for print
local recorD=recorD or "," -- record delimiter for print
local field=field or 1 -- if we decide only to print one field (field number)
local record=record or nil -- if nil, we print all records
local dimension=dimension or 1 -- the dimension of the matrix must be specified if not 1 (simple list)
local printN=printN or false
local line = ""
if #matrix>0 then
if record== nil then
for i=1,#matrix do
if i~=1 then line=line..recorD end -- add record delimiter unless for first record
if printN then line=line.." "..i..") " end
for j=1,dimension do
line=line..matrix[i][j] -- add data
if j~=dimension then line=line..fieldD end -- add field delimiter unless for latest field
end
end
else
if printN then line=line..record..") " end
for j=1,dimension do
line=line..matrix[record][j] -- add data
if j~=dimension then line=line..fieldD end -- add field delimiter unless for latest field
end
end
helptext="2) Ctrl+c this to clipboard"
helpdesk2=[[Quit and run in destination client]]
return line
else
helptext="No valid band found"
return ""
end
end -- this function can only report a line
function SegmentPrintMatrix(matrix,dimension, fieldD, field, recorD, record, printN, display) -- New BK 14/10/2014
local matrix=matrix or {}
local fieldD=fieldD or ";" -- field delimiter for print
local recorD=recorD or "," -- record delimiter for print
local field=field or 1 -- if we decide only to print one field (field number)
local record=record -- if nil, we print all records
local dimension=dimension or 1 -- the dimension of the matrix must be specified if not 1 (simple list)
local printN=printN or false
local display=display or "list" -- can be "table" or "list"
if display=="list" then -- prints all in one line
print(SegmentMatrixToString(matrix,dimension, fieldD, field, recorD, record, printN))
elseif display=="table" then
for i=1,#matrix do
print(SegmentMatrixToString(matrix,dimension, fieldD, field, recorD, i, printN))
end
end
end
--- End of Segment Set module
--BANDS
--GET-RESTORE BANDS by Jean-Bob and Bruno Kestemont - Copyright
--Free to use for non commercial purposes
--You may use it but please acknowledge Jean-Bob and Bruno Kestemont
Ubands={} -- global
function tlist(t) --table walk & unpack from Jean-Bob (Ebola)
local i, n=0, #t -- n is the number of elements taken by unpack, equivalent to #t I think
return function ()
i=i+1
if i<=n then return unpack(t[i]) end
end
end
function GetSegFromDist(seg, atomseg, dist, atoms) -- from Jean-Bob (Ebola) enhanced for atoms by BK
local atoms=atoms or false
local atomseg=atomseg or 0
atomnb=0 -- this will be returned to global, always updated when used
if atoms then -- new experimental
local hasPassed1, lenseg, targetSeg=false, 0, 0 -- targetSeg is not used here, mais je n'ose pas l'effacer
for i=1, segments do
local atoti=structure.GetAtomCount(i)
--local distseg=structure.GetDistance(i,seg)
local buffer = 8 -- 7 is the highest sidechain length I observed
hasPassed1, lenseg=pcall(structure.GetDistance,i,seg)
if not hasPassed1 then return false -- case segment not found
else
if lenseg<dist+buffer and lenseg>dist-buffer then -- ok this segment is a candidate
local hasPassed2, lenat=false, 0
for a=0, atoti do
tempband=band.AddBetweenSegments(i, seg,a, atomseg)
--print("DEBUG seg "..i.." atom "..a.." bandnb= "..tempband)
if tempband~=0 then -- case of band 1 to 1
hasPassed2, lenat=pcall(band.GetLength,tempband)
band.Delete(tempband) -- I have the distance, I don't need this band any more
if not hasPassed2 then return false -- case no distance found (do wa abandon everything?) TO VERIFY
else
--print("DEBUG distance seg "..i.." ato "..a..": "..lenat)
if lenat==dist then
atomnb=a
print("Atom found number "..atomnb.." of seg "..i)
return i
end -- return i and keep atomnb for further use
end
end
end
end
--print("DEBUG seg "..i.." rejected, distance = "..lenseg.." dist= "..dist)
end
end -- add return false here case nothing found?
else -- working ver 1.4
local hasPassed, len, targetSeg=false, 0, 0 -- targetSeg is not used here, mais je n'ose pas l'effacer
for i=1, segments do
hasPassed, len=pcall(structure.GetDistance,i,seg)
if not hasPassed then return false -- case segment not found
else
if len==dist then return i end
end
end
end
end
atomEnd1=0
atomEnd2=0
function GetBands(keepL, keepS, keepGL, atoms) -- from Jean-Bob (Ebola) W0NDERFULL intelligent function !!! enhanced by BK 7/12/2014
local keepL= keepL or false -- also get lengths (if true)
local keepS= keepS or false -- also get lengths (if true)
local keepGL=keepGL or false -- replace length by current goal length
local benabled=1 -- 1 for enabled, 0 for unabled
local atoms=atoms or false -- true = slow but finds all bands including to atoms
--note that bands in space are impossible to find by this method I think
local i=0
local delb=0
local bn=band.GetCount()
if bn==0 then return end
print("Starting with "..bn.." bands")
local AllisOK=true
repeat
i=i+1
local isOK=true
--print("Number of bands = "..band.GetCount())
--print("Seeking band "..i)
len1=band.GetLength(i) -- distance of band i
glen1=band.GetGoalLength(i) -- goal distance of band i, not used yet
if keepGL then len1=glen1 end -- not used yet, but it's an option if we want
bstrength=band.GetStrength(i) -- strength of band i
if band.IsEnabled(i) then benabled=1 else benabled=0 end
rope=band.AddToBandEndpoint(1,i) -- band from seg 1 to end2 point of band i
len2=band.GetLength(rope) -- distance from 1 to end point of band i
band.Delete(rope) -- we do not need this band any more
if atoms then
bandEnd2=GetSegFromDist(1, 0, len2, true) -- we try all distances between all segments atoms and seg 1, and we find the one with len2 !
atomEnd2=atomnb
else -- original code for bands only
bandEnd2=GetSegFromDist(1, 0, len2) -- we try all distances between all segments and seg 1, and we find the one with len2 !
end
if not bandEnd2 then isOK=false end --break end
if atoms then
bandEnd1=GetSegFromDist(bandEnd2, atomEnd2, len1, true) -- we try all distances between all atoms and bandEnd2, and we find end1!
atomEnd1=atomnb -- the new one just found now
else
bandEnd1=GetSegFromDist(bandEnd2, 0, len1) -- we try all distances between all segments and bandEnd2, and we find end1!
end
if not bandEnd1 then isOK=false end --break end
if isOK then -- we only keep the normal bands between segments WARNING other bands are not copied, numbers may change
if atoms then -- on prevoit le place pour tout mettre !
if keepL and keepS then
table.insert(Ubands,{bandEnd1, bandEnd2, atomEnd1, atomEnd2, len1, bstrength, benabled})
--print("DEBUG end1= "..bandEnd1.." atom1= "..atomEnd1.." end2= "..bandEnd2.." atomend2= "..atomEnd2)
elseif keepL then
--table.insert(Ubands,{bandEnd1, bandEnd2, len1})
table.insert(Ubands,{bandEnd1, bandEnd2, atomEnd1, atomEnd2, len1, 1, benabled})
elseif keepS then
--table.insert(Ubands,{bandEnd1, bandEnd2, bstrength})
table.insert(Ubands,{bandEnd1, bandEnd2, atomEnd1, atomEnd2, 0, bstrength, benabled})
else -- original Jean-Bob function, first line bellow
--table.insert(Ubands,{bandEnd1, bandEnd2})
table.insert(Ubands,{bandEnd1, bandEnd2, atomEnd1, atomEnd2, 0, 1, benabled})
end
else
if keepL and keepS then
table.insert(Ubands,{bandEnd1, bandEnd2, len1, bstrength, benabled})
elseif keepL then
--table.insert(Ubands,{bandEnd1, bandEnd2, len1})
table.insert(Ubands,{bandEnd1, bandEnd2, len1, 1, benabled})
elseif keepS then
--table.insert(Ubands,{bandEnd1, bandEnd2, bstrength})
table.insert(Ubands,{bandEnd1, bandEnd2, 0, bstrength, benabled})
else -- original Jean-Bob function, first line bellow
--table.insert(Ubands,{bandEnd1, bandEnd2})
table.insert(Ubands,{bandEnd1, bandEnd2, 0, 1, benabled})
end
end
band.Delete(i)-- Always cut OK bands (the non ok remain), for copy and export, we will restore before leaving
delb=delb+1
i=i-1 -- otherwise we would jump bands because band numbers change
bn=bn-1 -- total number of bands is reduced
else
AllisOK=false
--print("Unable to get band "..i..". Leaving it on screen.")
--WARNING: band number changes always, don't rely on it
end
--end
until i == bn -- it stops when there is no deletable band any more
--print(delb.. " bands copied")
if AllisOK then -- I succeeded to identify and copy the bands
print("OK ! All ".. delb .." bands copied in memory !")
--print("OK ! All bands memorized !")
band.DeleteAll() -- I may delete the bands because there are in memory in table TO VERIFY !!! (bug deleted bands)
else -- I did not succeed to copy all the bands
print("Unable to copy bands in space or sidechains")
bndCnt=band.GetCount()
print(bndCnt .." bands not copied")
helptext4="Warning: Failed to copy "..bndCnt .." bands"
print(delb.. " bands copied in memory:")
--band.DisableAll()
end
end
function RestoreBands(keepL, keepS, atoms) -- from Jean-Bob (Ebola) enhanced by BK 7/12/2014
if #Ubands==0 then return end
local keepL= keepL or false -- also get lengths (if true)
local keepS= keepS or false -- also get strength (if true)
local bandn=0
local atoms=atoms or false
if atoms then -- TO DO
if keepL and keepS then
for end1, end2, atomEnd1, atomEnd2, len1, bstrength, benabled in tlist(Ubands) do
--print("DEBUG end1= "..end1.." atom1= "..atomEnd1.." end2= "..end2.." atomend2= "..atomEnd2)
bandn=band.AddBetweenSegments(end1, end2, atomEnd1, atomEnd2) -- FAUT ENCORE TROUVER LE BON SENS !
band.SetGoalLength(bandn,len1)
band.SetStrength(bandn,bstrength)
if benabled==1 then band.Enable(bandn) else band.Disable(bandn) end
end
elseif keepL then
for end1, end2, atomEnd1, atomEnd2, len1, bstrength, benabled in tlist(Ubands) do
bandn=band.AddBetweenSegments(end1, end2, atomEnd1, atomEnd2)
band.SetGoalLength(bandn,len1)
--band.SetStrength(bandn,1)
if benabled==1 then band.Enable(bandn) else band.Disable(bandn) end
end
elseif keepS then
for end1, end2, atomEnd1, atomEnd2, len1, bstrength, benabled in tlist(Ubands) do
bandn=band.AddBetweenSegments(end1, end2, atomEnd1, atomEnd2)
--band.SetGoalLength(bandn,0)
band.SetStrength(bandn,bstrength)
if benabled==1 then band.Enable(bandn) else band.Disable(bandn) end
end
else
for end1, end2, atomEnd1, atomEnd2, len1, bstrength, benabled in tlist(Ubands) do
bandn=band.AddBetweenSegments(end1, end2, atomEnd1, atomEnd2)
--band.SetGoalLength(bandn,0)
--band.SetStrength(bandn,1)
if benabled==1 then band.Enable(bandn) else band.Disable(bandn) end
end
end
else
if keepL and keepS then
for end1, end2, len1, bstrength, benabled in tlist(Ubands) do
bandn=band.AddBetweenSegments(end1, end2)
band.SetGoalLength(bandn,len1)
band.SetStrength(bandn,bstrength)
if benabled==1 then band.Enable(bandn) else band.Disable(bandn) end
end
elseif keepL then
for end1, end2, len1, bstrength, benabled in tlist(Ubands) do
bandn=band.AddBetweenSegments(end1, end2)
band.SetGoalLength(bandn,len1)
--band.SetStrength(bandn,1)
if benabled==1 then band.Enable(bandn) else band.Disable(bandn) end
end
elseif keepS then
for end1, end2, len1, bstrength, benabled in tlist(Ubands) do
bandn=band.AddBetweenSegments(end1, end2)
--band.SetGoalLength(bandn,0)
band.SetStrength(bandn,bstrength)
if benabled==1 then band.Enable(bandn) else band.Disable(bandn) end
end
else
for end1, end2, len1, bstrength, benabled in tlist(Ubands) do
bandn=band.AddBetweenSegments(end1, end2)
--band.SetGoalLength(bandn,0)
--band.SetStrength(bandn,1)
if benabled==1 then band.Enable(bandn) else band.Disable(bandn) end
end
end
end
end
function DeleteBands(enabled) -- by BK, it deletes enables (true) or disabled (false) bands
local enabled= enabled or false -- default erase only disabled bands
local whichOnes=" disabled bands deleted from screen"
if enabled then whichOnes=" enabled bands deleted from screen" end
local bnb=0
local delb=0
local bn=band.GetCount()
if bn==0 then return end
repeat
bnb=bnb+1
if (enabled and band.IsEnabled(bnb)) or (not enabled and not band.IsEnabled(bnb)) then
band.Delete(bnb)
delb=delb+1
bnb=bnb-1 -- otherwise we would jump bands because band numbers change
bn=bn-1 -- total number of bands is reduced
end
until bnb == bn -- it stops when there is no deletable band any more
print(delb..whichOnes)
end
--End GET-RESTORE BANDS by Jean-Bob and Bruno Kestemont
-- not used here:
function SetNewStrengths(bandtable) -- changing band strength
for i= 1, #bandtable do
if PossibleRange then
band.SetStrength(i, strengthtable[i])
else
band.SetStrength(i, 10)
end
end
end
function MakeStrengthTable(bandtable, multiplier)
maxstrength=0.1
for i= 1, #bandtable do
strengthtable[i]=r1(band.GetStrength(i)*multiplier) -- Warning, strength is rounded to 1-2 decimals max
if strengthtable[i]>maxstrength then maxstrength=strengthtable[i] end
end
if maxstrength==0 then
maxstrength=0.1 --because I think it stops at 0
elseif maxstrength>=10 then
maxstrength=10 --because I think it stops at 10
--PossibleRange=false
end
print("Maximum band strength= ".. maxstrength)
--return maxstrength -- to global
end
-- end not used
helptext0="1) Copy or Cut"
helptext="2) It will write what to export in this box:"
helptext2=[[3) Paste from memory; Clear memory; Delete all bands]]
helpdesk2a=[[Quit and open destination client]]
helptext3="4) On destination client, Ctrl+v here from clipboard:"
helptext4=[[Warning: unable to copy bands in space. Sidechains optional]]
function GetParameters ()
local txtExport=""
local txtImport=""
local loopimport=1 -- TO VERIFY (could be 0) or delete
local keepL=true
local keepS=true
local keepGL=false
local atoms= false
local dlog = dialog.CreateDialog ( recipename )
dlogresult=9 -- must be initialized here
repeat
--dlog.keepL=dialog.AddCheckbox("Take length as goal length", keepL)
--dlog.keepGL=dialog.AddCheckbox("Keep goal length", keepGL)
--dlog.keepS=dialog.AddCheckbox("Keep strength", keepS)
dlog.atoms=dialog.AddCheckbox("Include bands to sidechains (very slow)", atoms)
dlog.L0=dialog.AddLabel(helptext0)
dlog.L1=dialog.AddLabel(helptext)
dlog.txtExport=dialog.AddTextbox("Export:", txtExport)
dlog.L2=dialog.AddLabel(helptext2)
dlog.L3=dialog.AddLabel(helptext3)
dlog.txtImport=dialog.AddTextbox("Import", txtImport)
dlog.L4=dialog.AddLabel("-------------------")
dlog.L5=dialog.AddLabel(helptext4)
dlog.copy = dialog.AddButton ( "Copy" , 1 )
dlog.cut = dialog.AddButton ( "Cut" , 2 )
--dlog.export = dialog.AddButton ( "Export" , 3 )
dlog.paste = dialog.AddButton ( "Paste" , 4 )
dlog.import = dialog.AddButton ( "Import" , 5 )
dlog.erase = dialog.AddButton ( "Clear" , 6 )
dlog.delete = dialog.AddButton ( "Delete" , 7 )
dlog.cancel = dialog.AddButton ( "Quit" , 0 )
dlogresult = dialog.Show ( dlog )
if dlogresult > 0 then
--keepL=dlog.keepL.value
--keepS=dlog.keepS.value
--keepGL=dlog.keepGL.value
atoms=dlog.atoms.value
local D=5
if atoms then
D=7
helptext4="WARNING: unable to copy bands in space"
end
--if keepL and keepS then D=4 elseif keepL or keepS then D=3 else D=2 end
if dlogresult==1 then -- copy
Ubands={} -- clearing old list
print("Getting bands")
if atoms then
helptext4="Warning: unable to copy bands in space"
else
helptext4="Warning: will not copy bands to sidechains (fast)"
end
GetBands(keepL, keepS, keepGL, atoms)
keepLarchive=keepL
keepSarchive=keepS
--SegmentPrintMatrix(matrix,dimension, fieldD, field, recorD, record, printN, display)
SegmentPrintMatrix(Ubands,D, " - ", nil, "", nil, true, "table")
txtExport=SegmentMatrixToString(Ubands,D, "-", nil, " ", nil, false) -- important to respect format of here
--SegmentMatrixToString(matrix, dimension, fieldD, field, recorD, record, printN)
--all bands disappear here, but they are still in memory
--band.DeleteAll() -- otherwise I have them twice after restoring
RestoreBands(keepL, keepS, atoms) -- otherwise there are gone from screen (not from memory)
helptext3="4) On destination client, Ctrl+v here from clipboard:"
dlogresult=1 --to force return to main menu
elseif dlogresult==2 then -- cut
Ubands={} -- clearing old list
print("Getting bands")
if atoms then
helptext4="Warning: unable to copy bands in space"
else
helptext4="Warning: will not copy bands to sidechains (fast)"
end
GetBands(keepL, keepS, keepGL, atoms)
keepLarchive=keepL
keepSarchive=keepS
SegmentPrintMatrix(Ubands,D, " - ", nil, "", nil, true, "table")
txtExport=SegmentMatrixToString(Ubands,D, "-", nil, " ", nil, false) -- important to respect format here
--print("Deleting bands")
--band.DeleteAll() -- otherwise I have them twice after paste
dlogresult=2 --to force return to main menu
helptext3="4) On destination client, Ctrl+v here from clipboard:"
elseif dlogresult==3 then -- export
Ubands={} -- clearing old list
print("Getting bands")
if atoms then
helptext4="Warning: unable to copy bands in space"
else
helptext4="Warning: will not copy bands to sidechains (fast)"
end
GetBands(keepL, keepS, keepGL, atoms)
keepLarchive=keepL
keepSarchive=keepS
SegmentPrintMatrix(Ubands,D, " - ", nil, "", nil, true, "table")
txtExport=SegmentMatrixToString(Ubands,D, "-", nil, " ", nil, false) -- important to respect format here
--band.DeleteAll()
RestoreBands(keepL, keepS, atoms) -- otherwise there are gone
dlogresult=3 --to force return to main menu with new options
helptext3="4) On destination client, Ctrl+v here from clipboard:"
elseif dlogresult==4 then -- paste inside
--print("Deleting existing bands")
--band.DeleteAll()
print("Pasting bands, including duplicates")
RestoreBands(keepLarchive, keepSarchive, atoms) -- be careful for double paste
dlogresult=4 --to force return to main menu
elseif dlogresult==5 then -- import
loopimport=loopimport+1
if loopimport ==1 then --the first time is only to get the input textbox
print("Getting the import dialog")
elseif loopimport>1 then
txtImport=dlog.txtImport.value
print("Importing bands")
Ubands={} -- clearing old list
--print("Getting existing bands")
--GetBands(keepL, keepS, keepGL, atoms)
if txtImport~='' then -- the delimitor must be the same as Dfield in copy and cut above
if D== 7 then
for a,b,c,d,e,f,g in txtImport:gmatch('(%d+)-(%d+)-(%d+)-(%d+)-(%S*)-(%S*)-(%d+)') do -- %g*: represents all list of printable characters except space
table.insert(Ubands,{a,b,c,d,e,f,g})
end
elseif D== 6 then
for a,b,c,d,e,f in txtImport:gmatch('(%d+)-(%d+)-(%d+)-(%S*)-(%S*)-(%d+)') do -- %g*: represents all list of printable characters except space
table.insert(Ubands,{a,b,c,d,e,f})
end
elseif D== 5 then
for a,b,c,d,e in txtImport:gmatch('(%d+)-(%d+)-(%S*)-(%S*)-(%d+)') do -- %g*: represents all list of printable characters except space
table.insert(Ubands,{a,b,c,d,e})
end
elseif D ==4 then
for a,b,c,d in txtImport:gmatch('(%d+)-(%d+)-(%S*)-(%S*)') do -- %g*: represents all list of printable characters except space
table.insert(Ubands,{a,b,c,d})
end
elseif D==3 then
for a,b,c in txtImport:gmatch('(%d+)-(%d+)-(%S*)') do
table.insert(Ubands,{a,b,c})
end
else
for a,b in txtImport:gmatch('(%d+)-(%d+)') do
table.insert(Ubands,{a,b})
end
end
else
print("Nothing to import")
--Ubands={}
end
--band.DeleteAll() -- to avoid duplicates
print("Imported bands:")
RestoreBands(keepL, keepS, atoms) -- be careful for double paste
SegmentPrintMatrix(Ubands,D, " - ", nil, "", nil, true, "table")
end
dlogresult=5 --to force return to main menu with new options
elseif dlogresult==6 then
print("Clearing memory")
Ubands={}
txtImport=""
helptext3="Memory cleared. Ctrl+x to clear above box"
dlogresult=6 --to force return to main menu
elseif dlogresult==7 then
print("Deleting bands (not memory)")
band.DeleteAll()
dlogresult=7 --to force return to main menu
end
end
until dlogresult<1 -- do not end if result is anything but Cancel
return dlogresult> 0 -- returns true if we did ok somewhere, false if immediately cancelled
end
function MAIN()
print(recipename)
save.Quicksave(bsslot) -- init
if GetParameters () then
print("Done")
end
end
MAIN()