Profile
- Name
- Band Pruner v0.2
- ID
- 101249
- Shared with
- Public
- Parent
- Band Pruner v0.1
- Children
- None
- Created on
- July 19, 2015 at 21:16 PM UTC
- Updated on
- July 19, 2015 at 21:16 PM UTC
- Description
Deletes all bands with current length longer (or shorter) than a limit you set. Useful after banding all contacts, to get rid of the farthest ones.
Best for
Code
-- Band Pruner: deletes all bands longer than (or shorter than) a limit you pick.
-- v0.2 added current minimum band length as lower limit for sliders
------------------------
--defaults for dialog box
LongerThan = true
ShorterThan = false
MaxLength = 0
MinLength = 0
------------------------
SCRIPT = "Band Pruner"
VERSION = "0.2"
function GetCurrentRange()
LongestBandLength = 0
ShortestBandLength = 999
for b = 1, band.GetCount() do
BandLength = band.GetLength(b)
if BandLength > LongestBandLength then
LongestBandLength = BandLength
end
if BandLength < ShortestBandLength then
ShortestBandLength = BandLength
end
end
return ShortestBandLength, LongestBandLength
end
function GetParams()
CurrentMin, CurrentMax = GetCurrentRange()
dlg = dialog.CreateDialog(SCRIPT.." "..VERSION)
dlg.l1a = dialog.AddLabel("Delete Bands")
dlg.LongerThan = dialog.AddCheckbox("Longer Than",LongerThan)
dlg.MaxLength = dialog.AddSlider("Max Length:",CurrentMax,CurrentMin,CurrentMax,2)
dlg.ShorterThan = dialog.AddCheckbox("Shorter Than",ShorterThan)
dlg.MinLength = dialog.AddSlider("Min Length:",CurrentMin,CurrentMin,CurrentMax,2)
dlg.ok = dialog.AddButton("OK", 1)
dlg.cancel = dialog.AddButton("Cancel", 0)
if dialog.Show(dlg) > 0 then
LongerThan = dlg.LongerThan.value
MaxLength = dlg.MaxLength.value
ShorterThan = dlg.ShorterThan.value
MinLength = dlg.MinLength.value
if LongerThan then
print("Delete bands longer than "..MaxLength)
end
if ShorterThan then
print("Delete bands shorter than "..MinLength)
end
return true
else
print("Dialog cancelled")
return false
end
end
function DeleteBands()
for b = band.GetCount(), 1, -1 do
if LongerThan and band.GetLength(b) > MaxLength then
band.Delete(b)
elseif ShorterThan and band.GetLength(b) < MinLength then
band.Delete(b)
end
end
end
-------------------
function Cleanup()
print("Ending band count = "..band.GetCount())
end
function Main()
print("Starting band count = "..band.GetCount())
if GetParams() then
DeleteBands()
end
Cleanup()
end
--Main()
xpcall(Main, Cleanup)