void Command_Select_Limit(SelectLimitDialog.Result result) { var variables = GetVariables(); var firstSelection = new NEExpression(result.FirstSelection).Evaluate <int>(variables); var everyNth = new NEExpression(result.EveryNth).Evaluate <int>(variables); var takeCount = new NEExpression(result.TakeCount).Evaluate <int>(variables); var numSels = new NEExpression(result.NumSelections).Evaluate <int>(variables); var sels = Selections.Skip(firstSelection - 1); if (result.JoinSelections) { sels = sels.Batch(everyNth).Select(batch => batch.Take(takeCount)).Select(batch => new Range(batch.Last().End, batch.First().Start)); } else { sels = sels.EveryNth(everyNth, takeCount); } sels = sels.Take(numSels); SetSelections(sels.ToList()); }