简体   繁体   中英

How to unload all links ( Revit, CAD, Pointcloud, IFC ) from revit in C# macro

I need to batch unload all linked types from Revit file. So far, I found the code that takes care of Revit links, thanks to one of the posts by

https://stackoverflow.com/users/200443/maxence

// Unload all links
        var loadedExternalFilesRef = new List<RevitLinkType>();
        var collector = new FilteredElementCollector(document);
        foreach (Element element in collector.OfClass(typeof(RevitLinkType)))
        {
            ExternalFileReference extFileRef = element.GetExternalFileReference();
            if (null == extFileRef || extFileRef.GetLinkedFileStatus() != LinkedFileStatus.Loaded) 
                continue;
            var revitLinkType = (RevitLinkType)element;
            loadedExternalFilesRef.Add(revitLinkType);
            revitLinkType.Unload(null);
        }

I also need to take care of all links, including CAD, IFC, Pointcloud Seems that Revit API does not allow same functionality for CADlinktype.

Please, advise and thank you for help!

I implemented a solution to remove DWF links, CmdRemoveDwfLinks . It is provided as an external command in The Building Coder samples GitHub repo . The full documentation of the command is provided on The Building Coder blog in the discussion on removing DWF Links , including lots of background information and research that may well help you handle other link types as well. Good luck!

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM