Adding shared parameters to loadable families (original) (raw)
Hi,
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.
Thank you
Frank_L (Frank Loftus) May 9, 2025, 8:50pm 2
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.
GavinCrump (Gavin Crump) May 10, 2025, 7:29am 3
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.
Thank you. Definitely, if it possible in Dynamo, it is with PyRevit as well. I just wanted to get an idea so I know it is worth spending my time on it. By any chance, Do you remember if you used a specific package in Dynamo for this?
Thank you for the extended and detailed response. At this point, I just want to know which path to take, since with these topics you can go down the wrong rabbit whole sometimes, and it can be time consuming… For instance, I asked ChatGPT about this, and it told be that I should use Cpython for a better “FamilyManger” class support. I was not sure about going that route since from what I read IronPhyton is more stable through all version when using it with PyRevit. Also, I did not want to add another layer of complexity to it… In my short experience working with PyRevit, I have learned to trust more what I read in this forum than what ChatGPT tells me. At least for a start. I think it is the same with all niche topics.
There is a lot of info to digest here, at least for me. I saw some of the video, it is a great video by the way, but I think I will have to watch it a couple of times to really understand some concepts. I really like that excel script, It comes in handy for many other tasks one might need… Again, I really appreciate all the help !..will keep you posted
Jean-Marc (Jean-Marc Couffin) May 12, 2025, 2:57pm 6
@reliable_bim do not waste your time with chatgpt if don’t knwo what you are doing and how you are doing it within pyRevit/Revit API.
More often than not, you will end up wasting time.
But if you are dangerous engouh with the Revit API, then, it can help you.
Total BS
From what Gavin provided you with, you have everything to get started with your issue, but it is a fairly big bite.
Find a smaller, achievable goal to get started. Small bite, one at a time, chew it well ;p
GavinCrump (Gavin Crump) May 12, 2025, 3:25pm 7
+1 to small bites.
If youre new to pyrevit do consider trying it in dynamo/python as well if you need to break it down into steps as well.
Bulk family processing isnt a fun thing to test and build as you will often need to reboot revit if it locks down documents or doesnt close documents in background successfully. Personally i dread building and testing scalable family editing workflows due to this as well as the rather complex transaction requirements (usually you need to call new transactions in the host/edited documents and it can get a bit confusing).
Dynamo can help a bit there as you can hold documents in memory during session and close them later by connecting nodes that do that at the end. Once it all works, you can port the code over to pyrevit - this is often how i prototype python code more roughly vs throwing it at the interpreter to see the errors each time.
Frank_L (Frank Loftus)
May 12, 2025, 6:31pm 8
I would just do it in dynamo, personally. If you find that it’s useful, then you can code it into a pyRevit button. I used the package Orchid. It looks like you can find relevant nodes for your task:
Jean-Marc (Jean-Marc Couffin) May 12, 2025, 7:13pm 9
Yeah, loved the nodes, but closed sources last time I checked. So you do not see the insides… Then you have to retro engineer it (or understand the Revit api)
GavinCrump (Gavin Crump) May 12, 2025, 10:35pm 10
Indeed it is.
I added a bunch of nodes in the Crumple package written in Python in light of this. Not as extensive as Orchid but might help people trying to understand the API associated with familymanager.
reliable_bim (Amaru Rios) May 13, 2025, 12:24pm 11
Thanks everyone for the input. @Jean-Marc Yes, I was looking to maybe reverse engineer some of the nodes, but if they are close source maybe I wont be able to do much… @Frank_L I prefer to stay away from Dynamo for now and invest more of my time taking stabs at more Python scripts and understanding the API… I had mix results with Dynamo, It is also a lot of work sometimes trying to figure out the packages and nodes and from what I heard a lot of the packages are not being updated lately. But, I agree with @GavinCrump is a good stepping stone for developing python scripts. The other thing, I find more user friendly deploying a PyRevit button for others to use than a Dynamo script…However, @GavinCrump I will look at your Crumple package. It sounds interesting.
This is for a long term solution so I am not in a big hurry to finish this. First, we have to come up with the standard workflow, then I will try to automate some of the work, but I just wanted to make sure it is possible before I propose anything. Definitely, there is some planning that has to be done in order to break down this into steps… That is a project of it’s own.
GavinCrump (Gavin Crump) May 13, 2025, 2:46pm 12
Im 99% sure that orchid and my approach will not differ greatly + even if you could see the source for orchid it would be in c#, whereas I use native python. You’ll likely be surprised by how much code is in Crumple id say, enjoy!
On an unrelated note, ill also leave this here… its a very odd repo and id love to know the story behind it. Enjoy also: