Finding Used Types in an RVT Link

Writing about the Copy/Monitor UI, Steve mentions that “It would be cool if Revit identified the elements and types that are actually in use in the linked file”

The Revit API can’t modify the Copy/Monitor UI, but the API can be used to identify the elements and types that are actually in use in the linked file.

levelTypes

public void levelTypesInLink()
{
    Document doc = this.ActiveUIDocument.Document;
    foreach (RevitLinkType linkType in new FilteredElementCollector(doc).OfClass(typeof(RevitLinkType)).Cast<RevitLinkType>())
    {
        string usedLevelTypes = "";
        string notUsedLevelTypes = "";
        Document linkDoc = getLinkDoc(doc, linkType);
        foreach (LevelType levelType in new FilteredElementCollector(linkDoc).OfClass(typeof(LevelType)).Cast<LevelType>())
        {
            if (new FilteredElementCollector(linkDoc).OfClass(typeof(Level)).Cast<Level>().Where(level => level.LevelType.Id == levelType.Id).Count() > 0)
                usedLevelTypes += levelType.Name + ", ";
            else
                notUsedLevelTypes += levelType.Name + ", ";
        }
        TaskDialog.Show("Level Types in " + linkDoc.Title,
                        "Used\n------\n" + usedLevelTypes + 
                        "\n\nNot Used\n---------\n" + notUsedLevelTypes);
    }
}

private Document getLinkDoc(Document doc, RevitLinkType linkType)
{
    foreach (Document linkDoc in doc.Application.Documents)
    {
      if (linkDoc.Title.Equals(linkType.Name))
      {
          return linkDoc; 
      }
    }
    return null;
}
Advertisements

3 thoughts on “Finding Used Types in an RVT Link

  1. Can we get the file name of the copy monitored element with the current selection using the API? The question came from a user the other day asking which model are these elements copy monitored to? I have 6 links.

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 )

Twitter picture

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

Facebook photo

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

Google+ photo

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

Connecting to %s