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
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.