I am trying to create a Dynamo script that will open a Revit file (in the background), remove all Revit links from that file, and then save over that current Revit file.
I can find all link types & instances and delete them, but they remain in the Manage Links browser, and thus still need to be temporarily upgraded whenever the host files are upgraded.
I cannot find anything online that discusses removing Revit links (deleting the linked files entirely from the host file). Everything I find online discusses removing the elements or instances.
Is this something the Revit API can do?
Thanks in advance
Edit: I am still very new at Dynamo, and do not have any Python experience. So if Python is the solution, I will need a step by step on how to implement it
import clr
import sys
clr.AddReference('RevitAPI')
from Autodesk.Revit.DB import *
from Autodesk.Revit.DB.Structure import *
clr.AddReference('RevitAPIUI')
from Autodesk.Revit.UI import *
clr.AddReference('System')
from System.Collections.Generic import List
clr.AddReference('RevitNodes')
import Revit
clr.ImportExtensions(Revit.GeometryConversion)
clr.ImportExtensions(Revit.Elements)
clr.AddReference('RevitServices')
import RevitServices
from RevitServices.Persistence import DocumentManager
from RevitServices.Transactions import TransactionManager
doc = DocumentManager.Instance.CurrentDBDocument
uidoc=DocumentManager.Instance.CurrentUIApplication.ActiveUIDocument
# The inputs to this node will be stored as a list in the IN variables.
linkInstances = FilteredElementCollector(doc).OfClass(RevitLinkInstance).ToElements()
OUT = linkInstances
So for deleting a linked file i need there ID but which one? Revit ID, unique Id, TypeID?
how do i remove it via for loop, or can i “clean up” my variable to None ?
do i clear, delete or remove my links ?
Did you have any luck with this? i am looking at doing the same thing. (open a revit file in the background, remove linked revit files, close file) it appears that you can only delete instance of linked file and not the linked file.
i would have thought a node similar to remove.link would exist
just delete the element type of the revit link types not wanted. Get all elements of Type Revit Link and delete elements. if you have already a script getting the revit link instances, then get the types of those, and delete
I have not had a chance to run the script yet, however from the looks of it, it appears to be removing the linked elements placed in the model - I am looking to remove the links from being loaded in the model all-together
I am looking for a way to take old models, strip them of any loaded link, so when I upgrade them to a newer version for pulling information from, Revit does not have to go through the process of upgrading every loaded link
As said before you need to delete the link types. I have a node in Crumple which returns all linked files and their types/instances. Iirc I put it under Revit>Collect in the latest build. If you delete those types that should remove the link entirely from the model (similar to removing a link from manage links).
This is the node contents in Python for your testing if it helps, but looks to work for me currently. Wondering if maybe there’s something to do with BIM360 links involved.
Hi Gavin, I’ve also been trying to collect all link types and remove them from my project. When I use your node and connect it to Element.Delete, the links disappear ( even though in the node results some of the entries are “false”)
That list represents the type of each instance in the second output, so if you have links with more than one instance, only the first type will need to be deleted as by the time the next one is going to be the type is already gone.
Thank you for the reply. Currently I have 15 Revit links loaded in and there are 21 unique link types picked up by the node. This means that I can’t list unique items to avoid the deletion of the same type twice. I tried to cycle through the list in python to check whether each of the elements exist at all before it gets deleted, but this didn’t solve my issue and returned the same error, as I guess with the unique Ids they are picked up as unique entities, even thought some of them are not…?
Sorry for the double post, I just realised the 6 additional types are coming from links within other links.
Even when I filter them out from the deletion process I still get the same error as before.
What I don’t understand is why if I append all of the Non-nested links to a list and connect it to Elements.Delete it works brilliantly well and when I try to do it within Python it is so unhappy.
The Delete node likely has a builtin attempt to delete and if it fails it continues and returns a Null. You could achieve this in python using try/except.