Get project location name of Revit Links in Revit Links - Inception like question

Hi Dynamoers,

I am trying to get the ActiveProjectLocation.Name out of links in links (everybody thinks Inception right?):
I have a master file, which has several links (12), I can easily fetch the ActiveProjectLocation.Name for all of them. I can also get the Revit Instance Links (68) that are hosted in each and every links of my master file. From the latest, I can collect a fair amount of project information: shared location, file size, worksets, … but the same piece of python script that allows me to get the ActiveProjectLocation.Name of my ‘first level’ links, does not get the ‘2nd level’ ones.

The question is:

  1. Is it because the links in links info of the Active Project Location cannot be fetch @ a 2nd level / API limitation? - note that I have tried the python code inside a custom node to play with the lacing with the same results = null -
  2. is it just because of my bad coding skills or because of something that works differently @ the 2nd level fo links?

import clr

# clr.AddReference loads and imports .net assembly(dll) as python module
# load RevitAPI.dll and RevitServices.dll
clr.AddReference("RevitAPI")
clr.AddReference("RevitServices")

# import filtered element collector and revit link instance classes
from Autodesk.Revit.DB import FilteredElementCollector, RevitLinkInstance

# import document manager
from RevitServices.Persistence import DocumentManager

# collect link documents from current document
link_docs = UnwrapElement(IN[0])
#rvtLinks = link_docs.ToElements()

ProjectLocation = []

#Queries


for i in link_docs :

	projloc = i.GetLinkDocument().ActiveProjectLocation.Name

		
#Append Output Lists	

	ProjectLocation.Add(projloc)
	

OUT = ProjectLocation

from Czech Republic with love

You basically need to get each link as its own document then do a get these revit links from that linked document. I think this post will help you get towards your goal.

If you are after going even deeper then this i would suggest creating it in python and utilizing the “background Document Open” method, while creating a loop until all links of links has been got(maybe better as a python class/function).

When ever i utilize this background process i usually open a blank project(eg template) so you do not get any issues of opening a file that is within the original document error message.

Hi @Brendan_Cassidy,
Thanks for your reply

You basically need to get each link as its own document then do a get these revit links from that linked document

This bit, I think I got it right, I mean I fetched the Revit Instance links (2nd level (the 68 ones))

The main issue remains in the fact that when I iterate through the Revit link instances as I did with the 1st level one, I cannot fetch the GetDocument().ActiveProjectLocation
When I reduce to the GetDocument() only, I get nulls as well, it seems that I can get the Revit Link Instance but not the Revit Link Instance Document.

Not sure I follow, so I’m gonna give it some names.

You have file A, which has file B linked into it.
File B also has file C linked into it. You want to know the name of the location of file C?

If so I think you will have to open each of the items as nested links start to lose some information about the document. I believe this is a limitation of Revit (try and find the path via the UI of the attached links). There is a way though, as noted above by @Brendan_Cassidy you could open file B and get the linked document info from there.

Or, if background opening is creating issues, you could use Dynamo for Automation to write the location data for every file (he file itself - don’t go into links) to a CSV (Excel document might not close in either method).

Is this what you are after getting, if you are after going deeper into the other revit links, i think you should utilize the background open methods to open them files and get there links.

hi @jacob.small,
your description is right,
I don’t want to go down the way of opening in background as I feel this will greatly overload my script processing time for very little information in return. The rest of my script is big not to say huge, it runs for 2 min and export loads of information to gsheets _more on that soon by @vincent.cadoret :star_struck: _

I get everything I want so far from the C files without opening them in background: File name, instance name, Pinned status, design option, workset of instance, workset of type.

@Brendan_Cassidy not quite, that bit I have it already, that last bit I would need and don’t know why it is not working or even if it is possible is:
apply the .GetDocument.ActiveProjectLocation.Name to the resulting RevitLinkInstance in your script, that is what I am after

Also forgot to add that you may not be able to get the other links as documents because they are on a different directory as per the consultant server mapping for drives that they was received from.

yep, but I do not get any of them. I am not trying to get their filepath, but the shared loaction name, I think it remains in the project information storage of the revit file by default, but getting nulls makes me think it is more complicated than that.

If you select the nested instance in the Revit UI, do you see location info in the properties pallet?

The processing time won’t be any worse for opening the N items if you close all worksets on open consistently. Might actually be faster as you’d only have to open the B file N times and pull the data you are after - everything you listed is stored in the host, so you’re loading N B files. Currently you are opening the A file, which loads the N B files, and the N C files (I don’t believe attachments or C files load if you don’t load the workset the host link or the B file is on so not sure you would see a time increase by not loading the worksets).

Also, what time is lost if you borrow a CPU from a colleague who is out, and hit ‘run’ on the batch process while you do other work?

I cannot select the nested C files as they are in linked Overlay.

I am not going the road of opening files in background right now as this strategy is overkill with the script I work on. ‘A’ file opens with every worksets and links ‘ON’ so that I see everything @ A and B level, which suites my purpose: the info I fetch from the C files is not even 5% of the data I collect. The ActiveProjectLocation.Name might be 0.3%. I doubt it would not affect my script significantly. Also I would need to refact the script structure when everything else works very well. We digress.

C files aren’t loaded in revit, what is loaded is just the Project Information Data from what I guess. Does that include the ActiveProjectLocation or not? and If yes is it possible to fetch it without opening C files in background?

I’m not sure that is correct. Something to test:

  • Open an A file, set up a schedule view that shows only one of the elements in a C file - say isolate a single door.
  • Close the A file and open up the C file (not the B file), and delete the element. Sync and close the C file.
  • Reopen the A file.

If you can no longer see the element in the C files inside of a view, they are loaded. If it requires opening and syncing the B file, then it is unlikely that you will be able to get what you are after without processing the B or C files in the background.

As a side note, I used to actively avoid links set as attachments when I practiced as there are too many limitations around things like this, and they generally slow things down.

As a side note, I used to actively avoid links set as attachments when I practiced as there are too many limitations around things like this, and they generally slow things down.

same here

  • Open an A file, set up a schedule view that shows only one of the elements in a C file - say isolate a single door.
  • Close the A file and open up the C file (not the B file), and delete the element. Sync and close the C file.
  • Reopen the A file.

I hardly see how I could achieve that. All my links are in overlay. I don’t see the C files, I can list the Revitlinkinstances in Dynamo but cannot see them in Revit. If I delete a door in C, and reload B (the linked file that hosts C) in A without reopening and saving B it will still remain the “old” version of C (the project information data section)

it is probably a more dev’ question and highly relies on a complete knowledge of the Revit API behaviours, maybe @Jeremy_Tammik could help?

I am really interested in knowing what data is accessible on C level files / 2nd of imbrication

I tried on the API / Dev side of Revit :slightly_smiling_face:

Answered the StackOverflow thread on ActiveProjectLocation.Name of Revit links inside Revit links.

4 Likes