Finding and Removing RVT Links

By Saikat Bhattacharya

In Revit 2013, every RVT Link in a Revit model is represented via its instance which is of RevitLinkInstance type and the Link Type which is of RevitLinkType type. Now, if you want to remove the RVT Links from an existing model (which means deleting the instance of the RVT Link and also removing it from the list in the Manage Links dialog accessible from the Revit User Interface, you can use the following illustrated simple approach to get this done. The approach is to filter all the RVT Links to create a list of them and simply using Document.Delete() method to delete the RVT Link instance and remove the link from the Manage Links dialog.

using System;

using System.Collections.Generic;

using System.Text;

 

using Autodesk.Revit.Attributes;

using Autodesk.Revit.DB;

using Autodesk.Revit.UI;

 

namespace Revit.SDK.Samples.HelloRevit.CS

{

 

  [Transaction(TransactionMode.Manual)]

  public class Command : IExternalCommand

  {       

    public Result Execute(ExternalCommandData commandData,

      ref string message,

      ElementSet elements)

    {

      UIApplication uiApp = commandData.Application;

      UIDocument uiDoc = uiApp.ActiveUIDocument;

 

      FilteredElementCollector collector = new FilteredElementCollector(uiDoc.Document);

      Element linkedFile = collector.OfCategory(BuiltInCategory.OST_RvtLinks).FirstElement();

 

      Transaction trans = new Transaction(uiDoc.Document, "del");

      trans.Start();

      uiDoc.Document.Delete(linkedFile);

      trans.Commit();

 

      return Result.Succeeded;

    } 

  }

}

 


Comments

Leave a Reply

Discover more from Autodesk Developer Blog

Subscribe now to keep reading and get access to the full archive.

Continue reading