Edit Formula Value in Project Environment for Multiple Families at Once

See this post here :slight_smile:

The DanEDU Dynamo nodes should do just what you’re looking for. I’m nearly certain the set formula’s node should handle inputting a null value.

1 Like

Thanks for the heads up on this package!

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

If i try to input an empty string value what i get is ("") as the new formula.

it does that if i use code block or script node…seems inputting a “blank” string value for this is not the proper method

Script Delete Family Formula

This may help / is at least good to look at.

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 :slight_smile:

(the link @Steven shared is pretty much identical to what I linked above, there is a .dyn file attached)

Scratch this part that I said above:

You can obtain the loaded family documents via the DocumentUtilities.GetFamilyDocument node from the Beaker package:

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

This works on my end:

4 Likes

Hi @awilliams,

First of all, thanks for the edited python code :+1:
This workflow was also the solution for the below topic (as variation on the topic you mentioned in your first answer). https://forum.dynamobim.com/t/different-input-for-document-backgroundopen-node/15623/6

@William_Ruffenach Don’t forget to add the “DocumentUtilities.CloseDocument” (also Beaker) at the end to close the documents that were loaded in memory.

Kind regards,
Mark

2 Likes

nice edition of my code…

I dont know why I did change it to a string, I can see that the node “FamilyDocument.SetParameterByName” is taking the input in the “correct” way, so I must have forgotten to update the code in the “FamilyDocument.SetFormulaByName” node.

thanks for pointing this out :slight_smile:

The DanEDU Dynamo package is updated now…

2 Likes

Hi @William_Ruffenach,

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.

you cant edit formulas in project mode, that is not doable in revit at all. The only way is to open the family and edit the formula.

thats why I made the nodes for families and as @awilliams (and @MJB-online) describes, you must use a method to open and close the families. I use @john_pierson Rythm nodes since they do the job excellent (Beaker nodes is also @john_pierson).

3 Likes

Sorry to bring this up, am getting an error :

An error occured! Please verify setting

you did not say what the error was, so i tested and got this new error to me:"… expected Document got Document".

so i looked it up and maybe the solution is in this:

namely : doc = DocumentManager.Instance.CurrentDBDocument

hope that’s it

Hi I think in can read the documents, it’s the parameter and values that it cannot read/write or whatever…

anyway here is the error…
IN[0] - Document
IN[1] - params
IN[2] - values

ERROR

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

how to fix the “unwrap” thing? I have zero knowledge in phyton…

@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)

1 Like

Hi, it worked!
Is it possible to filter the family via “prefix” and it will write to all the families?

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.

1 Like

if you need to modify a lot of parameters, you can put them in an excel csv file and let dynamo do the work.

1 Like

hi if you have time, can you give me an example with the excel thing?
not sure how to do that…

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.

thanks

Revit_Noob_w_excel.pdf (344.2 KB) [Revit_Noob_wRevit_Noob_FamilySharedParameter.txt (501 Bytes) _Excel.dyn|attachment](upload://rj4QhDdtZXxTxcBL9n7j2llOAps.dyn) (46.8 KB) Revit_Noob_FamilySharedParameter.xlsx (9.8 KB)