Great video! I’m currently learning Python and these videos are helping make the connection with how to use it in Revit. I downloaded the snoop tool after watching one of your other videos and I love it. It’s so handy!
Awesome videos Erik, my favorites. I am trying to get my Dynamo scripts into pyRevit addins. So I am obviously mostly new to Python and the Revit API. Dynamo makes it so easy. I am struggling with filtering elements by a shared parameter value and would really appreciate seeing it from your angle. Trying to learn and work full time as an EE is not easy and I could use a nudge in the right direction.
Thank you, I appreciate that! Keep practicing and it will get much easier, I also do this in my spare time after work mostly. 👀 Check a video about FilteredElementCollector. You would need to get all elements you need with Class or category and filter elements with a shared parameter value and there are 2 ways. 1️⃣ Simple List comprehension filtered_elements = [el for el in all_elements if el.LookupParameter('param_name').AsString() == 'keyword'] #
You can iterate through a list of elements and change the parameter value for each of them. Also make sure you keep Transaciton outside of transaction so it runs quicker
I need to know those keyboard shortcuts you use in your videos. Aligning = marks, selecting multiple lines and commenting them out. Would save a beginner a ton of time! Great content though! Thanks for making them
Maybe I should do a video about pyCharm shortcuts. I used to mention shortcuts more often, but then I got the feeling I was doing it too much. I will try to mention them again.
Hi Thanks, yes, you just need to create another doc variable for your linked model and use it to get elements. The rest is the same. Here is a snippet to get all documents. (it will return all open and linked models in your Active Revit app) app = __revit__.Application all_docs = app.Documents for doc in all_docs: print(doc.Title)
It's not in Revit API Docs on its own for some reason, but if you look in LookupParameter method, in remarks it says that we can use get_Parameter method for BuiltInParameters. Have a look here www.revitapidocs.com/2023/4400b9f8-3787-0947-5113-2522ff5e5de2.htm P.S. I was also wondering for a long time where it comes from before 😅
@@ErikFrits thank you very much for this! I'm upskilling myself, will join your patreon soon. I was the one who messaged you on LinkedIn the other day for the FEC handout. Keep up the good work!
I'm a little late to this video but it's extremely helpful. How do you access a shared parameter that is a type parameter? The best that I've come up with is to iterate through type parameters and look for Definition.Name == "my shared type parameter" but it seems like there should be an easier way.
You can get the type object of the element first and then look at its parameters so you can see Type Parameters. There is a property called .IsShared (or something along these lines) and you can iterate and check what's available. pyRevit has some forms for getting parmaeter input from elements, I think you can choose between Instance and Type.
Revit API is pretty much the same in pyRevit and Dynamo. Just a few differences with how you handle Transactions, define doc,uidoc but the main functionality is the same. Check Dynamo vs pyRevit video to see the differences.
Hey Erik, as of Revit 2022, the way of getting BuiltInParameter and units is changed to use ForgeTypeId , i would be good to include it somewhere in this video. I think this way of getting builtins is getting depraceted. People might get confused when they try following this video in the coming years. To get the same output with forge id use GetParameter(ParamterTypeId.####) for builtins.
They have depreciated a method to convert Units, but I I don't think they are going to depreciate the method to get built-in parameters soon, but if they do, I will make sure to cover this in a separate video. Thanks for the input!
Hi Erik, may I ask you why you don’t take advantage of the pyrevit python library to simplify the code? pyrevit.revit module and its submodules has most of the things needed for these examples (get elements by class, get/set parameters, transaction handling via context manager, etc)
For tutorials I try to avoid using pre-written functions so even people who use python nodes in Dynamo can also follow my code and apply it. Also good to know how to do it with plain code, before using someone's functions. When I create my own tools I reuse a lot of code + I have my own context managers for Transactions... But for tutorials I keep it simple so all the code shown in 1 file.
Hi Erik, I would like to ask a question. I've tried getting all parameters as taught in the video, however I realise some parameters are missed out when I loop through and print them in RPS. These parameters are shared parameters. I've also tried Revit Lookup to snoop the objects, but they do not appear in Parameters or ParametersMap. Any idea what I'm doing wrong?
If parameters are not appearing in Revit Lookup then they are not associated with the element as instance parameters. My best guess is that you are trying to get Type parameter using Instance object. Usually you need to get Type first and then look for type Parameters . Getting types is quite easy, depending if it's loadable family or built-in category. wall_type = wall.WallType # Built-In Categories like walls, floors, roofs... regular_family_type = element.Symbol Use Revit Lookup first to find the right parameters then you will know how to get them with python ⌨ Happy Coding
Material in Wall Types are not parameters but an object 'CompoundStructure' Have a look with Lookup as following: Wall -> WallType -> GetCompoundStructure in Revit API there is a method SetCompoundStructure ( writing of the top of my head, double check it) Tip: 1. First you need to get CompoundStructure. 2. Then you can modify by changing materials or adding new layers, 3. and then you need to set your modified CompoundStructure to the WallType. I am sure you will find some examples in Google, I don't remember where is my Snippet on modifying it ;) Happy Coding!
Hi Erik, Great video. Do you know why I can not change my parameter? I am not receiving any error but the value also not changing. floor_id = ElementId(23230886) floor = doc.GetElement(floor_id) param = floor.get_Parameter(BuiltInParameter.PHASE_CREATED) t = Transaction (doc, "change param") t.Start() param.Set("New Phase") t.Commit()
Do you get any error? I don't have Revit open at the moment, but something tells me that this parameter has StorageType of ElementId. If that's the case then it means you need to provide ElementId of the phase you are trying to set instead of providing a string with its name. Remember we need to Set using values with the same data type as parameter. Otherwise Revit doesn't make any errors and just ignores our attemp at modifying the value
You are dealing with 2 parameters, so you need to get them first. #Read BuiltIn Parameter Value p1 = el.get_Parameter(BuiltInParameter.ALL_MODEL_INSTANCE_COMMENTS) p1_value = p1.AsDouble() #TODO Start Transaction Here # Set SharedParameter Value p2 = el.LookupParameter('P_NAME') p2.Set(p1_value) #TODO Commit Transaction Here Note that both parameters should be numerical, because we are using AsDobule and setting this value.
Hello! "I want to convert shared parameter of the family into family parameter. However, I'm encountering issues with shared parameters that have interdependent formulas. How can I resolve this problem?"
I didn't make a lot of tools in Family editor, so I am not sure if converting parameter from shared to family parameter is allowed with Revit API. If you managed to convert parameter without formulas, then you probably need to save formula, then make it blank before you convert parameter. And then place formula back for converted parameter. If that's the case have a look at TransactionGroups to Assimilate() multiple transaction into 1 ;)
Does anyone know where "get_Parameter" method came from? I can't find the documentation, and in Revit API the method is GetParameter() I'have found other function in PyRevit Documentation get_param_value(targetparam) anyone know the difference? Which is better? Thanx
get_Parameter is mentioned in the remarks of Parameter Class and in Revit API Dev Guide. Haven't tried pyRevit function, but sometimes you get error in pyRevit if you try to get something like wall_type.Name (for some reason you can't get name property from types) But I avoid it using Element.Name.GetValue(wall_type)
@@ErikFrits yes I watched that all videos.can u make 10 mins video for how to work pycharm with revit.already you uploaded setup video.but I asked how to connect pycharm with revit
You don't need to connect pyCharm with Revit. I use pyCharm to edit .py files and then I place these files in my pyRevit extension folder. You can also setup Autocomplete in pyCharm for Revit API, I have a video about it too.
How can i create a project parameter by using python(and not prepare it manually before the execution(as this tutorial))? I've searched everywhere, and cant find the suitable method.. Thanks
Do you mean adding Shared Parameters, or actually creating Project Parmaeters? I am going to cover this in one of the next videos. Feel free to drop more questions on this topic!
@@ErikFrits Actually creating project parameter. (And in another code I’ll give it values(as this video)). I want the code create project parameter, and not the user. Thanks, it would be helpful.
Creating Project parameter (Not Shared) seems to be not possible with Revit APi. There is some workaround where you can create temp SharedParameterFile, then add parameter and delete that temp SharedParmaeterFile. But I feel like parameter is going to be Shared anyway, needs some testing. Why do you need Project Parmaeters and not Shared Parameter?
@@ErikFrits I didn’t know the meaning of shared parameters, and thought its not good for me. But shared parameter are good enough for the plug-in I created. Shared parameter just make the process little bit complicated, and not clean as project parameter. But as you say, we don’t have any choice,
@@yanirschneiderman5921 Glad you found alternative solution! btw, I shared some snippets about Shared parameters in my latest newsletter if you still need some examples: preview.mailerlite.io/preview/52352/emails/88796908852610625 Happy Coding!
Hi Erick, Thanks for the great content!, Do you know why I'm getting this error when I try to set a new value for any parameter? "revit api script gives me this error: Exceptions.InvalidOperationException: Cannot modify the document for either a read-only"
@@ErikFrits Thanks for answering me Erick, sure this the lines of code I'm using # Collect Mech equipment in the model mech = FilteredElementCollector(doc).\ OfClass(FamilyInstance).\ ToElements()
t = Transaction(doc, "n") t.Start() # Itering each element in mech list for m in mech: # Getting INSTANCE parameter param_m = m.get_Parameter(BuiltInParameter.ALL_MODEL_INSTANCE_COMMENTS) # Setting instance parameter param_m.Set("hey")
and it is giving me this error: "Exception : Autodesk.Revit.Exceptions.InvalidOperationException: Cannot modify the document for either a read-only external command is being executed, or changes to the document are temporarily disabled"
@@gilbertogranados2959 1. You are actually getting all loadable families, and not only mechanical equipment. Maybe you are encountering an issue with another element. add try/except statements when you are trying to modify parameter, and print more information about the element that causing issue so you can investigate further. If you want only mechanical equip, you can add OfCategory(BuiltInCategory.OST_...)
@@ErikFrits Thank You Erik, I will still checking that, it is strange because in my home PC the same code works correctly, and here in the office lap top it is just giving me that weird error, I will let you know if I can find the issue :)
This one is for adding parameter to a Family. I think in Project we need to bind Shared parameter quite differently, because we need to specify which categories it covers and so on
We have to set parameters with the same StorageType. So if parameter is a StorageType.String then you need to provide a text string. Here is example: param.Set(1.0) # Double param.Set(1) # Integer param.Set('1') # String param.Set(el_id) #ElementId
🎯Extra Tutorial: Set Group Names to its Members parameter
www.patreon.com/posts/dev-diary-03-to-70273393
I think that after a long time searching for a source to learn Revit API, I have found the best way :)
Glad you found me ;)
Happy Coding!
❤@@ErikFrits
Great video! I’m currently learning Python and these videos are helping make the connection with how to use it in Revit.
I downloaded the snoop tool after watching one of your other videos and I love it. It’s so handy!
Thanks!
I am really happy to break down coding for people in AEC.
oh yeah, SnoopDB Tool is a must have🔥!
Erik, thanks for providing these tutorials. Doing a great job and I'm thankful.
Planing on joining your traning session but need to feel more secure.
Thanks, glad you liked them.
Awesome videos Erik, my favorites. I am trying to get my Dynamo scripts into pyRevit addins. So I am obviously mostly new to Python and the Revit API. Dynamo makes it so easy. I am struggling with filtering elements by a shared parameter value and would really appreciate seeing it from your angle. Trying to learn and work full time as an EE is not easy and I could use a nudge in the right direction.
Thank you, I appreciate that! Keep practicing and it will get much easier, I also do this in my spare time after work mostly.
👀 Check a video about FilteredElementCollector. You would need to get all elements you need with Class or category and filter elements with a shared parameter value and there are 2 ways.
1️⃣ Simple List comprehension
filtered_elements = [el for el in all_elements if el.LookupParameter('param_name').AsString() == 'keyword'] #
hi, is it possible to set parameter for all selected elements ?
You can iterate through a list of elements and change the parameter value for each of them.
Also make sure you keep Transaciton outside of transaction so it runs quicker
Thank you very much bro for your videos!!!
My pleasure! I hope you learn something new and useful!
great video! thank you so much!
Glad it was helpful!
I need to know those keyboard shortcuts you use in your videos. Aligning = marks, selecting multiple lines and commenting them out. Would save a beginner a ton of time! Great content though! Thanks for making them
Maybe I should do a video about pyCharm shortcuts.
I used to mention shortcuts more often, but then I got the feeling I was doing it too much. I will try to mention them again.
Your Videos are awesome,you presentation is greate.can you show how to deal with subelements like points and lines on floors and roofs
Thanks, appreciate that.
Can you give an example of what you want to do with them?
@Erik Frits another great video! Question: I can i get a parameter value from an object in a linked model? Thanks!
Hi Thanks,
yes, you just need to create another doc variable for your linked model and use it to get elements. The rest is the same.
Here is a snippet to get all documents. (it will return all open and linked models in your Active Revit app)
app = __revit__.Application
all_docs = app.Documents
for doc in all_docs:
print(doc.Title)
@@ErikFrits Fantastic, i will give it a try soon, thanks again Eric!
hi Erik, question, where did the get_Parameter method come from?
It's not in Revit API Docs on its own for some reason, but if you look in LookupParameter method, in remarks it says that we can use get_Parameter method for BuiltInParameters.
Have a look here
www.revitapidocs.com/2023/4400b9f8-3787-0947-5113-2522ff5e5de2.htm
P.S.
I was also wondering for a long time where it comes from before 😅
@@ErikFrits thank you very much for this! I'm upskilling myself, will join your patreon soon. I was the one who messaged you on LinkedIn the other day for the FEC handout. Keep up the good work!
@@Rainquiller Happy to Help!
I'm a little late to this video but it's extremely helpful. How do you access a shared parameter that is a type parameter? The best that I've come up with is to iterate through type parameters and look for Definition.Name == "my shared type parameter" but it seems like there should be an easier way.
You can get the type object of the element first and then look at its parameters so you can see Type Parameters.
There is a property called .IsShared (or something along these lines) and you can iterate and check what's available.
pyRevit has some forms for getting parmaeter input from elements, I think you can choose between Instance and Type.
@@ErikFrits Thanks, checking .IsShared first sounds a bit more efficient than what I'm doing!
Does this method work in the Python Node of Dynamo?
Revit API is pretty much the same in pyRevit and Dynamo.
Just a few differences with how you handle Transactions, define doc,uidoc but the main functionality is the same.
Check Dynamo vs pyRevit video to see the differences.
Hey Erik, as of Revit 2022, the way of getting BuiltInParameter and units is changed to use ForgeTypeId , i would be good to include it somewhere in this video. I think this way of getting builtins is getting depraceted. People might get confused when they try following this video in the coming years. To get the same output with forge id use GetParameter(ParamterTypeId.####) for builtins.
They have depreciated a method to convert Units, but I I don't think they are going to depreciate the method to get built-in parameters soon, but if they do, I will make sure to cover this in a separate video.
Thanks for the input!
Hi Erik, may I ask you why you don’t take advantage of the pyrevit python library to simplify the code? pyrevit.revit module and its submodules has most of the things needed for these examples (get elements by class, get/set parameters, transaction handling via context manager, etc)
For tutorials I try to avoid using pre-written functions so even people who use python nodes in Dynamo can also follow my code and apply it. Also good to know how to do it with plain code, before using someone's functions.
When I create my own tools I reuse a lot of code + I have my own context managers for Transactions...
But for tutorials I keep it simple so all the code shown in 1 file.
very cool
Thanks
Hi Erik, I would like to ask a question. I've tried getting all parameters as taught in the video, however I realise some parameters are missed out when I loop through and print them in RPS. These parameters are shared parameters. I've also tried Revit Lookup to snoop the objects, but they do not appear in Parameters or ParametersMap. Any idea what I'm doing wrong?
If parameters are not appearing in Revit Lookup then they are not associated with the element as instance parameters.
My best guess is that you are trying to get Type parameter using Instance object. Usually you need to get Type first and then look for type Parameters .
Getting types is quite easy, depending if it's loadable family or built-in category.
wall_type = wall.WallType # Built-In Categories like walls, floors, roofs...
regular_family_type = element.Symbol
Use Revit Lookup first to find the right parameters then you will know how to get them with python
⌨ Happy Coding
how do i set parameter, to change material, inside wall type? i cant find it in properties(revit look up)..
Material in Wall Types are not parameters but an object 'CompoundStructure'
Have a look with Lookup as following:
Wall -> WallType -> GetCompoundStructure
in Revit API there is a method SetCompoundStructure ( writing of the top of my head, double check it)
Tip:
1. First you need to get CompoundStructure.
2. Then you can modify by changing materials or adding new layers,
3. and then you need to set your modified CompoundStructure to the WallType.
I am sure you will find some examples in Google, I don't remember where is my Snippet on modifying it ;)
Happy Coding!
Hi Erik,
Great video. Do you know why I can not change my parameter? I am not receiving any error but the value also not changing.
floor_id = ElementId(23230886)
floor = doc.GetElement(floor_id)
param = floor.get_Parameter(BuiltInParameter.PHASE_CREATED)
t = Transaction (doc, "change param")
t.Start()
param.Set("New Phase")
t.Commit()
Do you get any error?
I don't have Revit open at the moment, but something tells me that this parameter has StorageType of ElementId. If that's the case then it means you need to provide ElementId of the phase you are trying to set instead of providing a string with its name.
Remember we need to Set using values with the same data type as parameter. Otherwise Revit doesn't make any errors and just ignores our attemp at modifying the value
Please help me) how to transfer the value( example 6’ 10 1/2”)from the built-in parameter to the shared parameters?
You are dealing with 2 parameters, so you need to get them first.
#Read BuiltIn Parameter Value
p1 = el.get_Parameter(BuiltInParameter.ALL_MODEL_INSTANCE_COMMENTS)
p1_value = p1.AsDouble()
#TODO Start Transaction Here
# Set SharedParameter Value
p2 = el.LookupParameter('P_NAME')
p2.Set(p1_value)
#TODO Commit Transaction Here
Note that both parameters should be numerical, because we are using AsDobule and setting this value.
@@ErikFrits Thank you so much for your help, Eric You're the best!
How to relate an Excel file in this Python, excel data set to the Revit parameter value.
I made a video a while back, but I never finished editing it. I might write a blog article in the future ;)
Hello! "I want to convert shared parameter of the family into family parameter. However, I'm encountering issues with shared parameters that have interdependent formulas. How can I resolve this problem?"
I didn't make a lot of tools in Family editor, so I am not sure if converting parameter from shared to family parameter is allowed with Revit API.
If you managed to convert parameter without formulas, then you probably need to save formula, then make it blank before you convert parameter. And then place formula back for converted parameter. If that's the case have a look at TransactionGroups to Assimilate() multiple transaction into 1 ;)
Does anyone know where "get_Parameter" method came from? I can't find the documentation, and in Revit API the method is GetParameter()
I'have found other function in PyRevit Documentation
get_param_value(targetparam)
anyone know the difference? Which is better?
Thanx
get_Parameter is mentioned in the remarks of Parameter Class and in Revit API Dev Guide.
Haven't tried pyRevit function, but sometimes you get error in pyRevit if you try to get something like
wall_type.Name (for some reason you can't get name property from types)
But I avoid it using Element.Name.GetValue(wall_type)
@@ErikFrits Thank you for your response.
Regrets from Mexico City.
Hi @Erik frits thank u for ur explanation.is any possible for can u make revit api tutorial?
Hi,
What do you mean exactly ? I have a playlist of around 10 videos related to Revit API
@@ErikFrits yes I watched that all videos.can u make 10 mins video for how to work pycharm with revit.already you uploaded setup video.but I asked how to connect pycharm with revit
You don't need to connect pyCharm with Revit.
I use pyCharm to edit .py files and then I place these files in my pyRevit extension folder. You can also setup Autocomplete in pyCharm for Revit API, I have a video about it too.
How can i create a project parameter by using python(and not prepare it manually before the execution(as this tutorial))?
I've searched everywhere, and cant find the suitable method..
Thanks
Do you mean adding Shared Parameters, or actually creating Project Parmaeters?
I am going to cover this in one of the next videos. Feel free to drop more questions on this topic!
@@ErikFrits
Actually creating project parameter. (And in another code I’ll give it values(as this video)).
I want the code create project parameter, and not the user.
Thanks, it would be helpful.
Creating Project parameter (Not Shared) seems to be not possible with Revit APi.
There is some workaround where you can create temp SharedParameterFile, then add parameter and delete that temp SharedParmaeterFile. But I feel like parameter is going to be Shared anyway, needs some testing.
Why do you need Project Parmaeters and not Shared Parameter?
@@ErikFrits I didn’t know the meaning of shared parameters, and thought its not good for me. But shared parameter are good enough for the plug-in I created. Shared parameter just make the process little bit complicated, and not clean as project parameter. But as you say, we don’t have any choice,
@@yanirschneiderman5921 Glad you found alternative solution!
btw, I shared some snippets about Shared parameters in my latest newsletter if you still need some examples:
preview.mailerlite.io/preview/52352/emails/88796908852610625
Happy Coding!
IN FLOOR IS THE BOUNDINGBOX A PARAMETER ?
There is a method to get BoundingBox
el.get_BoundingBox(view)
Hi Erick, Thanks for the great content!, Do you know why I'm getting this error when I try to set a new value for any parameter? "revit api script gives me this error: Exceptions.InvalidOperationException: Cannot modify the document for either a read-only"
What kind of parameter are you changing? Can you send the line of code where you get parameter and set value.
@@ErikFrits Thanks for answering me Erick, sure this the lines of code I'm using
# Collect Mech equipment in the model
mech = FilteredElementCollector(doc).\
OfClass(FamilyInstance).\
ToElements()
t = Transaction(doc, "n")
t.Start()
# Itering each element in mech list
for m in mech:
# Getting INSTANCE parameter
param_m = m.get_Parameter(BuiltInParameter.ALL_MODEL_INSTANCE_COMMENTS)
# Setting instance parameter
param_m.Set("hey")
t.Commit()
and it is giving me this error: "Exception : Autodesk.Revit.Exceptions.InvalidOperationException: Cannot modify the document for either a read-only external command is being executed, or changes to the document are temporarily disabled"
@@gilbertogranados2959
1. You are actually getting all loadable families, and not only mechanical equipment. Maybe you are encountering an issue with another element.
add try/except statements when you are trying to modify parameter, and print more information about the element that causing issue so you can investigate further. If you want only mechanical equip, you can add OfCategory(BuiltInCategory.OST_...)
@@ErikFrits Thank You Erik, I will still checking that, it is strange because in my home PC the same code works correctly, and here in the office lap top it is just giving me that weird error, I will let you know if I can find the issue :)
⌨ - great video! :) Is it possible to create some kind of parameter by revit API?
yes There is definitely a way to create and add parameters to Revit.
I Don't have any snippets to share at the moment
@@ErikFrits okay, I found it. ;) Method AddParameter (www.revitapidocs.com/2021.1/fb4f8475-440f-6454-768f-777388a7fdd4.htm) - thanks!
This one is for adding parameter to a Family.
I think in Project we need to bind Shared parameter quite differently, because we need to specify which categories it covers and so on
@@ErikFrits you are right, I will try diffrent.
⌨
Hi, idk how to use a interger value for change a value of parameter. Is using “ “??? I does not work 🥲 HELP
We have to set parameters with the same StorageType. So if parameter is a StorageType.String then you need to provide a text string.
Here is example:
param.Set(1.0) # Double
param.Set(1) # Integer
param.Set('1') # String
param.Set(el_id) #ElementId
⌨