Revit API Forum
Welcome to Autodesk’s Revit API Forums. Share your knowledge, ask questions, and explore popular Revit API topics.
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Creating Groups from Revit API

2 REPLIES 2
SOLVED
Reply
Message 1 of 3
jregan
5578 Views, 2 Replies

Creating Groups from Revit API

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

2 REPLIES 2
Message 2 of 3
Dale.Bartlett
in reply to: jregan

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.
Message 3 of 3
sragan
in reply to: jregan

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.

Post to forums  

Autodesk DevCon in Munich May 28-29th


Rail Community