I'm currently trying to figure out a method for producing multiple group types from geometry in a project based on views. The end goal is to be able to define views with a specified naming convention, create a group type from the geometry in each view, and create group instances throughout the model.
The problem I'm facing is that there doesn't seem to be a good way to create these groups. I'm able to narrow down my selection to the specific elements I want, and I'm able to use the postcommand enumeration for create group, the problem is that the enumeration doesn't leave room for arguments and I'm not sure how to issue the command to name the group and create the group from the selection. Is there any known method for creating a group from a selected set of elements?
-Jared Regan
Solved! Go to Solution.
I'm currently trying to figure out a method for producing multiple group types from geometry in a project based on views. The end goal is to be able to define views with a specified naming convention, create a group type from the geometry in each view, and create group instances throughout the model.
The problem I'm facing is that there doesn't seem to be a good way to create these groups. I'm able to narrow down my selection to the specific elements I want, and I'm able to use the postcommand enumeration for create group, the problem is that the enumeration doesn't leave room for arguments and I'm not sure how to issue the command to name the group and create the group from the selection. Is there any known method for creating a group from a selected set of elements?
-Jared Regan
Solved! Go to Solution.
Solved by Dale.Bartlett. Go to Solution.
Hi Jared, Not sure if this helps. Dale
<code>
public static Group MakeGroup(Document doc, string pstrGroupName)
{
Group group = null;
using (Transaction tr = new Transaction(doc, "MakeGroup"))
{
tr.Start();
try
{
// create collector to collect all elements on active view
FilteredElementCollector collector = new FilteredElementCollector(doc, doc.ActiveView.Id);
// get ids of all elements in view
ICollection<ElementId> ids = collector.ToElementIds().ToList();
// make into group
if (ids.Count > 0)
{
group = doc.Create.NewGroup(ids);
group.GroupType.Name = pstrGroupName;
}
tr.Commit();
}
catch (Exception ex)
{
//tr.RollBack(); // no need, "using" does this
MessageBox.Show("Error: " + ex.Message);
}
}
return group;
}
</code>
Hi Jared, Not sure if this helps. Dale
<code>
public static Group MakeGroup(Document doc, string pstrGroupName)
{
Group group = null;
using (Transaction tr = new Transaction(doc, "MakeGroup"))
{
tr.Start();
try
{
// create collector to collect all elements on active view
FilteredElementCollector collector = new FilteredElementCollector(doc, doc.ActiveView.Id);
// get ids of all elements in view
ICollection<ElementId> ids = collector.ToElementIds().ToList();
// make into group
if (ids.Count > 0)
{
group = doc.Create.NewGroup(ids);
group.GroupType.Name = pstrGroupName;
}
tr.Commit();
}
catch (Exception ex)
{
//tr.RollBack(); // no need, "using" does this
MessageBox.Show("Error: " + ex.Message);
}
}
return group;
}
</code>
Have seen the Autodesk "my first plugin"?
It has an example that creates and copies groups. That sounds at least similar to what you are trying to do.
Have seen the Autodesk "my first plugin"?
It has an example that creates and copies groups. That sounds at least similar to what you are trying to do.
Can't find what you're looking for? Ask the community or share your knowledge.