I have seen several posts on the forum solving the issue of setting formula values inside Revit Families using python.
We use quite a bit of manufacturers models especially when it comes to plumbing fixtures. The majority of these families have information in lowercase or CamelCase. We need everything in UPPERCASE.
I wrote a script that will extract the parameter values change them to uppercase and set the value back to the parameter.
While this node set does allow me to get to the formula of the family it brings up 2 more questions.
First,
This doesn’t allow you to edit the family from the project environment. This is more of a workflow concern, since i could save the families out to a folder and reload them once the formula is updated.
I could also not be understanding how to pass families inside the current document into the DanEDU.FamilyDocument.SetFormulaByName Node…
Second,
This one is the real issue, (fingers crossed there is a method for this)
When i open a family and simply delete the formula, what is left in the value field is what was written as the formula
Check the first image in the link I shared above - the package has a “Load Into Project” node, it appears this workflow should work from the project environment and background opens/modifies/closes the family documents, then reloads it into the current document
With the workflow I shared above, you wouldn’t be pulling the family documents from inside the current document, rather, plugging in the file contents of the directory where all the families are located into the Document.BackgroundOpen node
Try inputting a code block that says null with no quotes (not a string) and see if that works
(the link @Steven shared is pretty much identical to what I linked above, there is a .dyn file attached)
I just had a look at the Python code within the DanEDU.FamilyDocument.SetFormulaByName node, and it converts the values into strings so inputting a null value doesn’t seem to work. If you paste this into a Python script node, it will accept a null value (removed the quotes around values[idx] in line 39)
#Copyright(c) 2014-2017, DanEDU Dynamo
#Erik Falck Jørgensen, Technical University of Denmark (DTU)
import clr
clr.AddReference('RevitAPI')
from Autodesk.Revit.DB import*
clr.AddReference('RevitServices')
from RevitServices.Persistence import DocumentManager
from RevitServices.Transactions import TransactionManager
uiapp = DocumentManager.Instance.CurrentUIApplication
app = uiapp.Application
#log builder, only for testing
#log = []
#input assigned the IN variable
docs = IN[0]
params = IN[1]
values = IN[2]
#wrap input inside a list (if not a list)
if not isinstance(docs, list): docs = [docs]
if not isinstance(params, list): params = [params]
if not isinstance(values, list): values = [values]
#default document set to DocumentManager.Instance.CurrentDBDocument
if docs[0] == 'Current.Document':
docs = [DocumentManager.Instance.CurrentDBDocument]
else: pass
#core data processing
for doc in docs:
TransactionManager.Instance.EnsureInTransaction(doc)
try:
for idx, item in enumerate(params):
param = doc.FamilyManager.get_Parameter(item)
doc.FamilyManager.SetFormula(param, values[idx])
log = 'Formula set successfully'
#only for testing
#log.append('Formula set successfully')
except:
log = 'An error occurred! Please veryfy setting'
#only for testing
#log.append('An error occurred! Please veryfy setting')
TransactionManager.Instance.ForceCloseTransaction()
#output assigned the OUT variable
OUT = docs, log
@William_Ruffenach Don’t forget to add the “DocumentUtilities.CloseDocument” (also Beaker) at the end to close the documents that were loaded in memory.
I think I am using a concoction of the code you are using and code from other post, and reading and writing using setformula works for me as long as I am writing strings.
But the first thing that I noticed in the code that you are using is that it is missing the unwrapelement.
I know you said that you can read the doc, but per link below, it will cause you trouble at the end if you don’t unwrap it.
Give it a shot. https://dynamopythonprimer.gitbook.io/dynamo-python-primer/4-revit-specific-topics/unwrapping-revit-elements
@Revit_Noob So i am not sure how to fix your code… i 've tried all i know with no results…
but if all you want is to add text value to a parameter, they you can use the code attached… the only catch here is that you have to load your family into some project, then run dynamo from within that project. so you cannot run it on the family itself.
if this works for you and you have a bunch of parameters to change, i can send you the code to load them from excel. Revit_Noob.dyn (25.1 KB) Revit_Noob.pdf (107.6 KB)
Yes, you can.
In step 2, in the pdf that sent, you can put the prefix there instead of “family…add to”.
You will find this in the “string contains” node.
Just put any value that is unique to the families that you want to modify.
pleas see attached… i think it is clear. if not, please ask.
i attached the excel in both formats, since for what i am doing now, i setup the data using .xlsx and when i am done with that i export the sheet as .csv. i do that since i can preserve any formulas i have written while setting up the data.
The Dynamo Node i have now is expecting xlsx file. you will have to specify the sheet that you want within that xlsx file.
One final thing, can you please mark this as solved.