[Transaction(TransactionMode.Manual)]
[Regeneration(RegenerationOption.Manual)]
//[Journaling(JournalingMode.NoCommandData)]
public class cmdGroup : IExternalCommand
{
public Result Execute(ExternalCommandData cmdData, ref string message, ElementSet elements)
{
UIDocument uiDoc = cmdData.Application.ActiveUIDocument;
Selection selection = uiDoc.Selection;
Transaction ts = new Transaction(uiDoc.Document, "group");
ts.Start();
Group group = null;
ElementSet selections = uiDoc.Selection.Elements;
if (selections.Size > 0)
{
group = uiDoc.Document.Create.NewGroup(selections);
}
group.GroupType.Name = "firstGroup";
//遍历一下group
FilteredElementCollector collector = new FilteredElementCollector(uiDoc.Document);
ICollection<Element> collection = collector.OfClass(typeof(Group)).ToElements();
foreach (Element el in collection)
{
TaskDialog.Show("group", el.Name);
}
ts.Commit();
return Result.Succeeded;
}
}
[Regeneration(RegenerationOption.Manual)]
//[Journaling(JournalingMode.NoCommandData)]
public class cmdGroup : IExternalCommand
{
public Result Execute(ExternalCommandData cmdData, ref string message, ElementSet elements)
{
UIDocument uiDoc = cmdData.Application.ActiveUIDocument;
Selection selection = uiDoc.Selection;
Transaction ts = new Transaction(uiDoc.Document, "group");
ts.Start();
Group group = null;
ElementSet selections = uiDoc.Selection.Elements;
if (selections.Size > 0)
{
group = uiDoc.Document.Create.NewGroup(selections);
}
group.GroupType.Name = "firstGroup";
//遍历一下group
FilteredElementCollector collector = new FilteredElementCollector(uiDoc.Document);
ICollection<Element> collection = collector.OfClass(typeof(Group)).ToElements();
foreach (Element el in collection)
{
TaskDialog.Show("group", el.Name);
}
ts.Commit();
return Result.Succeeded;
}
}