Get and Set parameters of a Linked File

Hello again,

I’m still trying to figure out how to solve the problem that is described in the link below:

From my researches I perceived that it’s well known the method to Get the parameters from a Linked File in Revit using Dynamo:

However I didn’t find any solution to the following problem: getting those parameters and subsequently setting these parameters into another parameter inside the Link. Anyone can help me? For God’s sake!

(Sorry about the gramatical mistakes. English isn’t my native language)

Hello,

You can’t change anything in a linked document, unless you close the host document and open the link as the active document.

The issue is: I want to use some instances of a Link, but set diferent values
to the parameters of the elements inside those links based on the link parameter called “Name”. However the links come from the same project.

Could you try to illustrate the issue with some screenshots or other figures? You understand that you can’t edit parameters or anything else in elements inside links, right?

@Einar_Raknes that’s almost accurate. You don’t have to close the current document, so long as you open the other one. You can have multiple documents open at the same time. Now, there are no OOTB nodes in Dynamo that allow this type of manipulation of linked models. You would need to script that kind of functionality with Python/C# etc. I know that @john_pierson has a node in his package that allows for opening the model. I am not sure how that would fit into what the OP wants to do though.

1 Like

So you want to link one Revit file into your document and set elements to have varying parameter values based on the name you give the one file?

I may be wrong, but I don’t think that is a thing. You can have one family with various types but there is no such thing as ‘project types’ which allow multiple instances of the same document to have differing values for the elements inside them. Need multiple projects instead, which I would wager is not conductive to your overall workflow. If I knew more maybe I could help better. Perhaps design options or maybe project parameters? What element types and parameters are you trying to vary?

@Konrad_K_Sobon I believe you will get an error as long as you have a linked file in memory in the same Revit session. It’s probably possible to unload the link temporarily, or work around it by changing the name:

@Einar_Raknes reading an excerpt from that same post:

Luckily we can work around the current limitations when the linked files needed for editing are workshared. We can in fact achieve this in the same session without unloading or requiring the user to open a separate Revit session by following these simple steps:

  1. Make sure to not use the right-click option shown above (obviously!)
  1. Navigate to the original linked central file and open through Revit’s Open dialog in the same session. If it is a valid Central File, Revit will automatically create a Local File by appending your username to it and happily open it for editing.

This is exactly what Document.Open() method would do. You can set the options to create new local and if what David is saying in his post is true that would not Unload the link.

It’s probably better to unload and reload the link to make it work for non-workshard files as well.

# Code by Einar Raknes, 2017
import clr
# Import List ( ICollection(ElementId) = List[ElementId]() )
clr.AddReference('System')
from System.Collections.Generic import List

# Import Revit API
clr.AddReference('RevitAPI')
from Autodesk.Revit.DB import *
from Autodesk.Revit.DB.Structure import *

clr.AddReference('RevitAPIUI')
from Autodesk.Revit.UI import *

# Import ToDSType(bool) extension method
clr.AddReference('RevitNodes')
import Revit
clr.ImportExtensions(Revit.GeometryConversion)
clr.ImportExtensions(Revit.Elements)

# Import DocumentManager and TransactionManager
clr.AddReference('RevitServices')
import RevitServices
from RevitServices.Persistence import DocumentManager
from RevitServices.Transactions import TransactionManager

doc = DocumentManager.Instance.CurrentDBDocument
uidoc = DocumentManager.Instance.CurrentUIApplication.ActiveUIDocument
app = DocumentManager.Instance.CurrentUIApplication.Application

link = UnwrapElement(IN[0])
comment = IN[1]

linkPath = link.GetLinkDocument().PathName
linkType = doc.GetElement(link.GetTypeId())

TransactionManager.Instance.ForceCloseTransaction()
linkType.Unload(None)

linkDoc = app.OpenDocumentFile(linkPath)
el = FilteredElementCollector(linkDoc).OfCategory(BuiltInCategory.OST_Site).WhereElementIsNotElementType().ToElements()[0]

TransactionManager.Instance.EnsureInTransaction(linkDoc)
el.get_Parameter(BuiltInParameter.ALL_MODEL_INSTANCE_COMMENTS).Set(comment);
TransactionManager.Instance.TransactionTaskDone()
TransactionManager.Instance.ForceCloseTransaction()
linkDoc.Close()
linkType.Reload()

Without linkType.Unload() I get the message mentioned above:

2 Likes

Hi @Einar_Raknes
Your python code above i think will solve my python code issue having on a totally different purpose. I just want to ask if its correct to assume that your code above saves the linked document as i can see you are closing the linked file but no saving code before that. Also this also assume that its only 1 linked file at a time is that correct coz you are actively selecting it (the linked model) can i unload all linked file in one go? Apologies i am not hijacking the topic just admiring your code coz i think this will solve a lot of my unanswered topics. Thanks…

Assumtion 1: Yes the document will be saved:
http://www.revitapidocs.com/2018/da2f27b9-7255-4950-82a2-86e1432ff9f0.htm

Closes the document, save the changes if there are.

Assumtion 2: Yes the code above only works for a single link, but you can always create a loop and iterate throug several links.

1 Like

Tusen takk!

I will try to explain with the images. Imagine that you have only one model of a house. You link this model twice in an empty Revit file. However you need to make them different by setting different values to the parameter “WBS” wich is inside of the elements (like walls, floors) of each link. So, you use the parameter “Name” (in my case, it’s “Nome”), which is a parameter of the linked files, and type “10” to the first file and “20” to the second. Once you have finished you try to set the parameter “Name” inside the elements of each linked file what will make them different. I have been thinking about this and I’m starting to realize that this sounds unreasonable because in fact in the moment that you set the different values to the parameter WBS (using the paramater “Name”) inside of the same linked file, you are creating new files! In my opinion this is the big mistake of my method.

I have been thinking also about a way to circumvent this problem and I don’t know if Dynamo can to this. In the moment that you set different values to the parameter WBS, would be possible to save this “new file” in an specific directory on your computer? What do you think?

PS.: Probably this text has a lot of grammar mistakes. Sorry, English is not my native language. However I’m trying to do my best alone.

Please, see my last post.

I’m more lost than before. Is the Nome file a global parameter? Even if so I’m still not sure if/how this would ever work… You’d need separate files for each link not a single file…

Can you upload your Revit file? Assuming it’s 2017 or older I may be able to better understand what you’re after here.

If you select an element (a wall) that is inside of any linked file, you will find a parameter called “EAP” which is the same of WBS (Work Breakdown System). The value of this parameter is created by a sum of others parameters (Dynamo) which are also inside of the element that you selected before. This parameter (EAP) is used to indicate the task of the construction like Concrete Wall, Ceramic Floor, etc and is linked with a Planned Start Date and a Finish End Date that are in a Planning Schedule. However, in my Planning Schedule there are more than one “house” which differ by their “Number”.

Nowadays I do the following: I run the Dynamo script and the House “258” is created. After that I save it. This number comes from a Project Parameter. Then I change this Project Parameter to “260”, run the Dynamo script again and the save it again. This process is effective but it is not efficient.

With this problem in my hands what I have imagined: If one selects a linked file it will be possible to see the parameter “Name”, which is an instance parameter of each Linked File (probably in your case it will be Name. In my case is “Nome”, because my language is Portuguese).

My proposal is to change the “location” of the parameter that contains the number of the Houses from that Project Parameter (that I can change when the model of a single House is open) to this parameter “Name” of the Linked file. These linked files come from the same model that in the file that I’m sharing with you is the House “258”. I have already changed the value of the instance parameter “Name” to 258 in a model and 260 in other.

To finish I’m trying to create a Dynamo script that takes this parameter “Name” in each instance of linked file and set to the elements inside of each linked files what would create elements of the house 258 and elements of the house 260.

This is the maximun that I can do to explain to you. With Dynamo I could get the parameters from the lonked files, but in the moment that I make a routine to send back the summed parameter with different values it shows an error message.

Speaking of link files. I think that may be my problem right now. I am trying to batch upgrade files and my graph works when the files does not include link files. But when I run it with files that has multiple links it does not work. please help me

How can i create a loop? I’ve been having the same problems