Change family parameter in mass

Hi,

Do you think we can create a script to add, modify or delete in mass some parameters in several families ?

For example I have 20 families in the same folder. I want to add the text parameter “my_parameter” with the value “hello” for each family.

Or maybe we need before to add this families in a revit project ?

If it possible it can be very useful for managing a company library.

Kind regards,
Yoann

Hi Yonann,

This is very possible and quite simple, do you have a starting script? Or are you looking for guidance?

Hi Helmy,

I’m just happy to know that is possible because I’m thiking to use it in the future.

But we can just have a small concept :

I found how to open it in the forum :

Open the family document

doc = revit.Application.OpenDocumentFile(family_path)

After with some .OS python library I can create a list of all the family files names.
So now I can open them all.
But for sure I will open them one by one → create the parameter → save the family → Close it and open the next one.

On Revit API website I found this command SaveAndClose().
This is the point were I’m not sure so I would try this one :
doc = revit.Application.SaveAndClose()
And maybe family path is not requiered because the family is open.

For the creation on the family parameter I found this :
doc.FamilyManager.AddParameter(self.definition, self.group.enum_member, self.is_instance)
Now I would try how I have to exactly write the name of the parameter.

And maybe for the value I need another command.

So what do you think ? Am I so far of the solution :slight_smile:

SaveAndClose() may prompt the user with a dialog (if changed). Probably not what you want for automation.

Close(saveModified = True) will save and close a document. But… it can’t be the active document. So you need to switch away to another document. You’ll probably want to put in some error checking to make sure everything is properly saved.

You can Save()/SaveAs() and then SaveAndClose() to avoid a dialog popping up. But that’s two saves and two backup files.

I have a script that bulk adds/updates parameters in a family (one at a time) from an Excel document. I built it to not just add “my_parameter”, but to also then assign it to the correct group, set the value, add a formula, and finally sort the parameters into a useful order. Also one of the updates it can do is to rename or replace family with shared or vice versa. It was built to expedite some content development so there is no documentation and it is alpha quality. If it is of use it can be found here: pyMAW-dev/maw-dev.extension/pyMAW.tab/Scripts.panel/LoadParametersToFamily.pushbutton at main · mawdesign/pyMAW-dev · GitHub. It could perhaps be automated to run over a list of families.