Hey I’m using a couple of archi-lab nodes to try an remove all rvt links in a project.
This is the result when it’s run the first time.
However, after it’s run the links still appear in the project browser and the manager. When the Dynamo graph is run again the below is the result. (the python script has just been copied and pasted out of the node to show the error message)
Does anyone have any ideas about how to remove the links?
Cheers.
1 Like
The archi-lab node is giving you ‘unwrapped’ raw Revit API information, the other node probably wants the ‘wrapped’ Element list. You can use a node in Bakery to get a list of all linked instances as Elements.
Thanks for your help Luke but it’s throwing back the same error. “The referenced object is not valid, possibly because it has been deleted from the database, or its creation was undone.”
On the first run it says it’s successfully deleted the elements (rvt links), then unplugging the nodes and running just to refresh it so dynamo actually processes the graph on the next run, then plug them back in and I get the error.
Interestingly if I undo the dynamo script command in revit then run the graph again I get the same results as running it for the first time (the delete node says it has successfully deleted the elements). And if I save the model after the graph has been run then close it and reopen it running the graph throws the same error. So somewhere in the database revit thinks the elements have been deleted.
dude, did you even read what you wrote? you said that on the first run it successfully deleted all of the links specified. they are gone. then you are wondering why you can’t delete them again? what did you expect? ability to infinitely keep deleting the same thing over and over again?
1 Like
Sorry it says they’re deleted but they still remain in the project in the project browser and in the manager and I can see the links in any view. The identical problem to the OP
The point I was trying to make (unsuccessfully) is that even though dynamo reports that it’s deleted the element, then says it can’t deleted it because it’s been deleted, that the links don’t actually get deleted out of the revit model. I have tested this across multiple models with the same results.
so that’s because you are going after the link instance. its not the same as the link document that still remains behind. see how the archi lab node returns a linked doc and instance? there is two objects associated with a link so you need to delete them both,
Ah makes sense. It’s still returning an error, saying that the document has no ID attribute (it seems as though the linked document doesn’t have an element ID which seems strange). And obviously the delete method requires an element ID so does that mean you can’t delete the linked doc through the API?
Hi Guys,
I am quite new to coding in python please could you check what I have done is correct?
But i believe I have solved this problem by doing this. As this give all of the Revit imported/linked elements
import clr
# Import RevitAPI
clr.AddReference("RevitAPI")
import Autodesk
from Autodesk.Revit.DB import *
# Import DocumentManager and TransactionManager
clr.AddReference("RevitServices")
import RevitServices
from RevitServices.Persistence import DocumentManager
doc = DocumentManager.Instance.CurrentDBDocument
element = [Autodesk.Revit.DB.RevitLinkInstance, Autodesk.Revit.DB.RevitLinkType, Autodesk.Revit.DB.ImportInstance]
linktype = Autodesk.Revit.DB.FilteredElementCollector(doc).OfClass(Autodesk.Revit.DB.RevitLinkType)
importedlinks = Autodesk.Revit.DB.FilteredElementCollector(doc).OfClass(Autodesk.Revit.DB.ImportInstance)
linkelements = []
for t in linktype:
linkelements.append(t)
for i in importedlinks:
linkelements.append(i)
OUT = linkelements
Are you aware that you can just use built-in nodes to achieve the same outcome?
4 Likes
I completely forgotten about the Element Types, so now there are 2 ways of doing the same thing.
Personally coding it is a lot more fun