#RTCNA2016 Wish Granted – Load Group from RVT

bd5cents sent in an API wish to:

Load Group in to project from external Group file. .rvt file.

This could be particularly useful if you have a folder full of Group RVTs and want to load them all, or if you want to create a dialog box where the user can select multiple groups to load.

Unfortunately, the API does not have a simple Document.LoadGroup() method, so we have to do a bit more work.

public void LoadModelGroup()
    string groupFile = @"C:\Users\harry_000\Documents\MyGroup.rvt";
    Application app = this.Application;
    Document doc = this.ActiveUIDocument.Document;
    // find elements to copy
    // to find the model elements in the group file,
    // create a 3d view and then get all the elements in that view
    Document docGroup = app.OpenDocumentFile(groupFile);
    ICollection<ElementId> toCopy = null;
    using (Transaction t = new Transaction(docGroup, "temp"))
        View3D view = View3D.CreateIsometric(docGroup, new FilteredElementCollector(docGroup)
                             .FirstOrDefault(q => q.ViewFamily == ViewFamily.ThreeDimensional).Id);
        toCopy = new FilteredElementCollector(docGroup, view.Id).ToElementIds();
    using (Transaction t = new Transaction(doc, "Copy Group"))
        // paste the elements from the group file
        ICollection<ElementId> newIds = ElementTransformUtils.CopyElements(docGroup, toCopy, doc, Transform.Identity, new CopyPasteOptions());
        // group the newly pasted elements
        Group group = doc.Create.NewGroup(newIds);
        // set the name of the group type
        group.GroupType.Name = Path.GetFileNameWithoutExtension(groupFile);
        // delete the instance of the group

6 thoughts on “#RTCNA2016 Wish Granted – Load Group from RVT

  1. Thanks, it can be useful indeed.
    Have you ideas for automatically integrate rooms from the “groupfile”, because they are not selected in 3D View.

  2. Probably you can add to the toCopy list with OfClass, OfCategory, or various other filters such as:

    toCopy = new FilteredElementCollector(docGroup, view.Id).ToElementIds();
    toCopy.AddRange(new FilteredElementCollector(docGroup).OfCategory(…..).ToElementIds();

  3. Well, i thought it was harder to do !
    AddRange doesnot work with ICollection , i made this :
    toCopy = new FilteredElementCollector(docGroup, view.Id).ToElementIds();
    ICollection roomCollection = new FilteredElementCollector(docGroup).OfClass(typeof(SpatialElement)).ToElementIds();
    foreach(ElementId e in roomCollection)

    I dont know if i code with good way but it works

  4. While it’s definitely helpful to some extent, I wouldn’t necessarily qualify this item as “granted.” It’s a step in the right direction, and I definitely applaud your hard work in this discovery. However, we would like more access to loading and managing groups within projects. For example, reloading edited groups in a batch instead of one-by-one, and needing to browse to location each time.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s