Icon representing a recipe

Recipe: Close Cuts

created by marsfan

Profile


Name
Close Cuts
ID
103593
Shared with
Public
Parent
None
Children
Created on
June 16, 2020 at 03:55 AM UTC
Updated on
June 16, 2020 at 03:55 AM UTC
Description

Closes all cuts.

Maximum distance between cut segments can be specifid (set to 0 to disable). I have set this distance to have a default of 6 Angstroms, as based off of my simple testing, anything above that cannot be closed manually.

To manually override and prevent a cut from being closed. Add a note on either side of the cutpoint that contains the phrase "<KC>"

Best for


Code


-- Set up UI to ask for cut threshold. settings = dialog.CreateDialog("Delete Cuts") settings.cutoff = dialog.AddSlider("Max Length", 6, 0, 100, 1) settings.ok = dialog.AddButton("Close Cuts", 1) settings.cancel = dialog.AddButton("Cancel", 0) function checkNoteKC(segment) -- Check if <KC> is in a segment's note return string.find(structure.GetNote(segment), "<KC>") end function main() -- Show dialog if(dialog.Show(settings) > 0) then -- Initialize distance variable local distance = 0 -- Since last segment cannot be cut, skip it. Also avoids crashing when checking distance. for segment=1, structure.GetCount()-1 do -- Get cut length distance = structure.GetDistance(segment, segment+1) -- Check if cut is shorter than cutoff, if cutoff is disabled, and if note to skip cut is present if (distance <= settings.cutoff.value or settings.cutoff.value == 0) and not checkNoteKC(segment) and not checkNoteKC(segment+1) then -- close the cut structure.DeleteCut(segment) end end else -- User pressed cancel errHandling("Cancelled") end end function errHandling(err) if string.find(err, "Cancelled") then print("User Cancelled") else print(err) end end xpcall(main, errHandling)

Comments