public void VisgroupCreateNew() { using (var qf = new QuickForm("Create New Visgroup") { UseShortcutKeys = true }.TextBox("Name").CheckBox("Add selection to visgroup", true).OkCancel()) { if (qf.ShowDialog() != DialogResult.OK) { return; } var ids = _document.Map.Visgroups.Where(x => !x.IsAutomatic).Select(x => x.ID).ToList(); var id = Math.Max(1, ids.Any() ? ids.Max() + 1 : 1); var name = qf.String("Name"); if (String.IsNullOrWhiteSpace(name)) { name = "Visgroup " + id.ToString(); } var vg = new Visgroup { ID = id, Colour = Colour.GetRandomLightColour(), Name = name, Visible = true }; IAction action = new CreateEditDeleteVisgroups(new[] { vg }, new Visgroup[0], new Visgroup[0]); if (qf.Bool("Add selection to visgroup") && !_document.Selection.IsEmpty()) { action = new ActionCollection(action, new EditObjectVisgroups(_document.Selection.GetSelectedObjects(), new[] { id }, new int[0])); } _document.PerformAction("Create visgroup", action); } }