Does anyone know if it is possible to add shared parameters to loadable families inside a central model from an existing shared parameters file?.. There is probably not a straight forward solution since loadable families need to by edited separately. But, is it possible for a script to open the family in a separate tab (same session) and then add the parameters, leaving the family open? It does not necessarily has to be loaded back to the central model, but if it possible that will be great too.
I only have experience doing this sort of thing with Dynamo, but if you can do it in Dynamo, you should be able to do it through the API. Using Dynamo, I was able to open families from a folder, add a shared parameter, set value, save the family, then close it.
It looks like you could use Document.EditFamily() to open the family (probably in the background, without UI), then add your parameter, then use Document.LoadFamily() to load it back in.
I can confirm you can use document.editfamily and document.load methods to achieve this outcome.
All operations relating to family management are accessed via the familymanager class which is accessed as a document property of the same name.
The code is in c#, but ive written the required revit api to achieve these steps here. They are basically the same as python logic for the most part:
These are what we call extension methods in c#, so leave out the word ‘this’ in the function arguments and it acts like a static function.
I store the outcomes of my functions to a special class that can hold onto multiple possible objects and stores an enumeration of possible outcomes to catch failures. This is potentially overkill in Python where you can return different object types for a function.
Note that the load family methods require an interface (IFamilyLoadOptions) to be used which does not work in Cpython3 so i recommend using ironpython to get around that, which is pyrevits default engine.
This video shows how to do it via a directory which might help in managing the add parameters step. You will need to put some thought into how the user specifies which parameters to add as well as if they are instance based and the group they go under. Note that in revit 2024+ you should use grouptypeids vs parametergroups in the API which my c# covers, but this video does not.