Finding Used Types in an RVT Link

8 01 2013

Reblogged from Boost Your BIM - making Revit even better:

Click to visit the original post

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.

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;
}
Great inspiration to use Revit's API...

Actions

Information

Leave a Reply

Please log in using one of these methods to post your comment:

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 )

Connecting to %s




Follow

Get every new post delivered to your Inbox.

Join 25 other followers

%d bloggers like this: