Announcements
Attention for Customers without Multi-Factor Authentication or Single Sign-On - OTP Verification rolls out April 2025. Read all about it here.

Creating Groups from Revit API

Anonymous

Creating Groups from Revit API

Anonymous
Not applicable

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

0 Likes
Reply
Accepted solutions (1)
6,429 Views
2 Replies
Replies (2)

Dale.Bartlett
Collaborator
Collaborator
Accepted 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>




______________
Yes, I'm Satoshi.

sragan
Collaborator
Collaborator

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.

 

0 Likes