Thank you. I know how hard to create videos like yours, and I am so grateful that you did this classes for pyrevit. You are awesome. I hope you keep doing these tutorials. I just started, and I have a lot to learn.
Thank you!!! This is the most user friendly video to get started with Revit and Python for someone who knows Revit well and knows the basics of Python!! I would really like to see more similar videos from you on this channel discussing different challenges such as PartUtils. etc.
I dont know how to thank uou more then liking all your videos and subscribe! Thank you very much! Alos, your didatic is very good ! Keep up the good work!
Thanks a lot for the video!!! One newbie question, what's the editor you use to type out script before running in Python Shell? (its convenient to be able to reference to Revit API) Thanks a lot!
Hello, I have followed your tutorial. It has been incredibly helpful! However, following the method used the total volume printed is incorrect? The volume being printed is 1712, when manually calculated the result is: 48.4 m^3. I am commenting here as a last resort, please can somebody assist? thank you in advance. wall_collect = FilteredElementCollector(doc).OfCategory(BuiltInCategory.OST_Walls).WhereElementIsNotElementType() total_volume = 0.0 for wall in wall_collect: vol = wall.LookupParameter('Volume') if vol: total_volume = total_volume + vol.AsDouble()
Hi Ehsan, just getting started with this series. I am trying to do the same example but instead with ducts (total length of all ducts). But the builtincategory has "ost_ductsystem" which returns a null value when looking up the length parameter. There is no ost_duct or pipe. Any other way ?
I haven't worked with ducts but seems like you are collecting Duct Systems instead of duct instances. Draw a Duct in Revit and check its Category.Name and Category.Id to see what Builtin Category you need to specify. You can also use the .OfClass filter on the FilteredElementCollector to collect by the duct element class instead
Hi Ehsan, this might be a stupid question. So i used OfClass filter but it still won't work on ducts. I get "Exception : IronPython.Runtime.UnboundNameException: name 'Duct' is not defined". I checked on RevitApiDocs and Duct Class inherits class MEPCurve. Could that be a reason ?
@@pyRevit Oh Yeah ! sorry about that. Here is the code and error Code: from Autodesk.Revit.DB import * length_collector=FilteredElementCollector(doc).OfClass(Duct) #iterate over ducts and collect total length total_length=0 for le in length_collector: length_param=le.LookupParameter('Length') if length_param: total_length= total_length + length_param.AsDouble() print(total_length) Error: Exception : IronPython.Runtime.UnboundNameException: name 'Duct' is not defined at IronPython.Runtime.Operations.PythonOps.GetVariable(CodeContext context, String name, Boolean isGlobal, Boolean lightThrow) at IronPython.Compiler.LookupGlobalInstruction.Run(InterpretedFrame frame) at Microsoft.Scripting.Interpreter.Interpreter.Run(InterpretedFrame frame) at Microsoft.Scripting.Interpreter.LightLambda.Run2[T0,T1,TRet](T0 arg0, T1 arg1) at IronPython.Compiler.PythonScriptCode.RunWorker(CodeContext ctx) at Microsoft.Scripting.Hosting.ScriptSource.Execute(ScriptScope scope) at Microsoft.Scripting.Hosting.ScriptSource.ExecuteAndWrap(ScriptScope scope, ObjectHandle& exception)
Hi, I kind of got stuck around 33 - I keep getting a message: 'Exception : IronPython.Runtime.UnboundNameException: name 'FilteredElementCollector' is not defined' Could it be that there is something wrong with the 'rps_init.py' startup script?
FilteredElementCollector is in the Autodesk.Revit.DB namespace. Make sure to import that first. "from Autodesk.Revit import DB" then use it like "DB.FilteredElementCollector"
You need to filter for OST_Windows using OfCategory method on the FilteredElementCollector. www.revitapidocs.com/2018.1/ba1c5b30-242f-5fdc-8ea9-ec3b61e6e722.htm
When I try to run CL, I get the error stating that FilteredElementCollector is not defined. If I make it DB.FilteredElementCollector, it works. Same with BuiltInCategory. Why is that? Thank you!
Definitely specially if you're using the python node in Dynamo. pyRevit and Dynamo with the same Revit API. Dynamo however has built in collectors for different categories as well as many other collectors and addons
Very cool! What features does pyRevit offer that Dynamo doesn't? I am not trying to downplay pyRevit's capabilities, I am just genuinely curious about the differences.
There is no direct comparison honestly. Dynamo is a visual programming platform that brings programming to people with no actual programming experience. pyRevit is a rapid-prototyping platform in IronPython for Revit. pyRevit helps with creating powerful tools and distributing them to your company teams very quickly since it does not need compilation. It's a better platform if you're building a toolbar of tools and don't want to use C#.
Thanks for the info! I will definitely try to get well versed in pyRevit then. I have been using Dynamo for a while, but after learning a bit of Python I can feel Dynamo encouraging bad habits and holding me back. Thanks again, great work!
In this example I'm using the parameter name directly. If this parameter is called something else in your language you should use the proper name. But for all Revit standard parameters you can use BuiltInParameter enum. This way no matter what the language is, Revit will always return the correct parameter. See www.revitapidocs.com/2018.1/fb011c91-be7e-f737-28c7-3f1e1917a0e0.htm
i am very excited, but it doesnt work 'el'. i do all step correct. but 'el' says: >>> el Traceback (most recent call last): File "", line 1, in NameError: name 'el' is not defined how can ı defıne 'el'? or sth else?(vers.2018)
When importing modules what is the most efficient way to know which modules to import? Do you write your code and then go back and look for the modules they are contained within?
Not really. overtime you learn slowly which modules to use by looking at their documentation a lot and testing them. But for tasks that I don't know there is a module, I generally do a search on Stackoverflow or Pypi to see if there is anything available and read their docs.
Thank you so much for this session , Ehsan. I tried the code in the session but the result of the volume is in cubic feet , i asking if there is a method to represent the volume in cubic meter as the Revit model is in metric unit
Thanks, I have been enjoying going through this. When I do the for loop to print (for el in cl:...etc) I dont get anything back. no errors but nothing is printed either. I do have a couple of walls modeled. Any idea what Im doing wrong?
Hi! Thanks for great tutorials! I'm having problem with unit conversion in that example. When I add to this loop additional prints I get something like this: for wall in wall_collector: vol_param=wall.LookupParameter('Volume') if vol_param: total_volume = total_volume + vol_param.AsDouble() print(vol_param.AsValueString()) print(vol_param.AsDouble()) Output: 36.80 m³ 1299.57973535 21.28 m³ 751.496107833 18.40 m³ 649.789867675 10.64 m³ 375.748053917 Do you know what can be cause of that?
The first parameter is the object instance. LookupParameter is a method on the type Element. So call that from the element instance. e.g el.LookupParameter(param_name)
Hello. Thank you for your tutorial. Trying recode it, but have one trouble. In my system i use m3 units, but when i get values by AsDouble, system return to me Volume in CF not in m3, but if i try get values by string, i got it in m3 but in string format. Please help me, is it possible get Volume in m3 by method AsDouble?
No. AsDouble() always returns values in internal API units. You need to do a quick CF to m3 conversion obviously. The AsValueString() however returns the string value with representing unit sign based on the model unit settings. That is good for quickly displaying pre-formatted results.
Here's a stupid error I made that might be tripping up someone else: please note that it's "OfCategory", not "ofCategory" ... I'm not used to method names beginning with an uppercase letter, and of course in English, "of" is almost never capitalized in titles, so I mistyped it and it took me forever to find my error!
Hi, i got the following error. >>> Exception : IronPython.Runtime.UnboundNameException: name 'BuildInCategory' is not defined bei IronPython.Runtime.Operations.PythonOps.GetVariable(CodeContext context, String name, Boolean isGlobal, Boolean lightThrow) bei IronPython.Compiler.LookupGlobalInstruction.Run(InterpretedFrame frame) bei Microsoft.Scripting.Interpreter.Interpreter.Run(InterpretedFrame frame) bei Microsoft.Scripting.Interpreter.LightLambda.Run2[T0,T1,TRet](T0 arg0, T1 arg1) bei IronPython.Compiler.PythonScriptCode.RunWorker(CodeContext ctx) bei Microsoft.Scripting.Hosting.ScriptSource.Execute(ScriptScope scope) bei Microsoft.Scripting.Hosting.ScriptSource.ExecuteAndWrap(ScriptScope scope, ObjectHandle& exception)
Thank you. I know how hard to create videos like yours, and I am so grateful that you did this classes for pyrevit. You are awesome. I hope you keep doing these tutorials. I just started, and I have a lot to learn.
Thank you! 😁
I was not expecting to get an intro to Revit API class out of this. Thanks for the information it helped a lot in my understanding of the API.
This lecture has been super helpful, you're very good at explaining this stuff. Now I'm excited to watch the rest of the Python for Revit Course!
Thank you!!! This is the most user friendly video to get started with Revit and Python for someone who knows Revit well and knows the basics of Python!! I would really like to see more similar videos from you on this channel discussing different challenges such as PartUtils. etc.
Thank you so much for this, Ehsan. You are presenting this in an extremely informative, thorough and nicely paced manner :-)
Halfway through session #2, learning much and enjoying the process! Thank you so much.
I dont know how to thank uou more then liking all your videos and subscribe!
Thank you very much!
Alos, your didatic is very good !
Keep up the good work!
thank you so much really helpful for me to get start pyrevit i am going to proud as a pyrevit Api Developer
Ehsan, thanks for explaining your masterpiece work.
Thank you so much for this video. More and more, please, of these very usefull Python with Revit skills.
Thank you so much for your great work! I really appreciate the way you explain how things work. Looking forward to the next sessions!
Thank you so much for this tool and for these AWESOME videos and tutorials that you provide ...Thx Again and Dame Shoma ham garm :D
This thing gave me a headache. Tho don’t know if I should continue, thanks you for the invaluable tutorial
Thanks a lot for the video!!! One newbie question, what's the editor you use to type out script before running in Python Shell? (its convenient to be able to reference to Revit API) Thanks a lot!
I use VisualStudio Code at the moment. But I don't use autocompletion for Revit API
Thank you so much for this! A really good video for API newbie.
Hello, I have followed your tutorial.
It has been incredibly helpful! However, following the method used the total volume printed is incorrect?
The volume being printed is 1712, when manually calculated the result is: 48.4 m^3.
I am commenting here as a last resort, please can somebody assist? thank you in advance.
wall_collect = FilteredElementCollector(doc).OfCategory(BuiltInCategory.OST_Walls).WhereElementIsNotElementType()
total_volume = 0.0
for wall in wall_collect:
vol = wall.LookupParameter('Volume')
if vol:
total_volume = total_volume + vol.AsDouble()
print("Total volume is: {}".format(total_volume))
Please ignore me. this is the correct result in Cubic feet!
Hi Ehsan, just getting started with this series. I am trying to do the same example but instead with ducts (total length of all ducts). But the builtincategory has "ost_ductsystem" which returns a null value when looking up the length parameter. There is no ost_duct or pipe. Any other way ?
I haven't worked with ducts but seems like you are collecting Duct Systems instead of duct instances. Draw a Duct in Revit and check its Category.Name and Category.Id to see what Builtin Category you need to specify. You can also use the .OfClass filter on the FilteredElementCollector to collect by the duct element class instead
Hi Ehsan, this might be a stupid question. So i used OfClass filter but it still won't work on ducts. I get "Exception : IronPython.Runtime.UnboundNameException: name 'Duct' is not defined". I checked on RevitApiDocs and Duct Class inherits class MEPCurve. Could that be a reason ?
Send me your code or a snippet please. It’s hard to debug without seeing 😁
@@pyRevit
Oh Yeah ! sorry about that. Here is the code and error
Code:
from Autodesk.Revit.DB import *
length_collector=FilteredElementCollector(doc).OfClass(Duct)
#iterate over ducts and collect total length
total_length=0
for le in length_collector:
length_param=le.LookupParameter('Length')
if length_param:
total_length= total_length + length_param.AsDouble()
print(total_length)
Error:
Exception : IronPython.Runtime.UnboundNameException: name 'Duct' is not defined
at IronPython.Runtime.Operations.PythonOps.GetVariable(CodeContext context, String name, Boolean isGlobal, Boolean lightThrow)
at IronPython.Compiler.LookupGlobalInstruction.Run(InterpretedFrame frame)
at Microsoft.Scripting.Interpreter.Interpreter.Run(InterpretedFrame frame)
at Microsoft.Scripting.Interpreter.LightLambda.Run2[T0,T1,TRet](T0 arg0, T1 arg1)
at IronPython.Compiler.PythonScriptCode.RunWorker(CodeContext ctx)
at Microsoft.Scripting.Hosting.ScriptSource.Execute(ScriptScope scope)
at Microsoft.Scripting.Hosting.ScriptSource.ExecuteAndWrap(ScriptScope scope, ObjectHandle& exception)
@@pyRevit Ehsan, it worked. I had to add "import Autodesk.Revit.DB.Mechanical"
Hi, I kind of got stuck around 33 - I keep getting a message:
'Exception : IronPython.Runtime.UnboundNameException: name 'FilteredElementCollector' is not defined'
Could it be that there is something wrong with the 'rps_init.py' startup script?
FilteredElementCollector is in the Autodesk.Revit.DB namespace. Make sure to import that first. "from Autodesk.Revit import DB" then use it like "DB.FilteredElementCollector"
hi, i have the same problem,did you solve that?
@@sepidehroohi3233 you can try
cl = DB.FilteredElementCollector(doc)
cl.OfCategory(DB.BuiltInCategory.OST_Walls)
Thank you very much for the very informative tutorial. If i want to count total number of windows in the model, what filter need to be used?
You need to filter for OST_Windows using OfCategory method on the FilteredElementCollector.
www.revitapidocs.com/2018.1/ba1c5b30-242f-5fdc-8ea9-ec3b61e6e722.htm
Thank you very much for your help. I got it and works perfect.
When I try to run CL, I get the error stating that FilteredElementCollector is not defined. If I make it DB.FilteredElementCollector, it works. Same with BuiltInCategory. Why is that? Thank you!
FilteredElementCollector is under Autodesk.Revit.DB namespace
Awesome video, does a lot of this information transfer over to Dynamo users as well?
Definitely specially if you're using the python node in Dynamo. pyRevit and Dynamo with the same Revit API. Dynamo however has built in collectors for different categories as well as many other collectors and addons
Very cool! What features does pyRevit offer that Dynamo doesn't? I am not trying to downplay pyRevit's capabilities, I am just genuinely curious about the differences.
There is no direct comparison honestly. Dynamo is a visual programming platform that brings programming to people with no actual programming experience. pyRevit is a rapid-prototyping platform in IronPython for Revit. pyRevit helps with creating powerful tools and distributing them to your company teams very quickly since it does not need compilation. It's a better platform if you're building a toolbar of tools and don't want to use C#.
Thanks for the info! I will definitely try to get well versed in pyRevit then. I have been using Dynamo for a while, but after learning a bit of Python I can feel Dynamo encouraging bad habits and holding me back. Thanks again, great work!
Thank you so much for this video ! You called the parameter with a STR ("Volume"), but if my Revit got another langage, it can't find this parameter ?
In this example I'm using the parameter name directly. If this parameter is called something else in your language you should use the proper name. But for all Revit standard parameters you can use BuiltInParameter enum. This way no matter what the language is, Revit will always return the correct parameter. See www.revitapidocs.com/2018.1/fb011c91-be7e-f737-28c7-3f1e1917a0e0.htm
Thank you so much !
i am very excited, but it doesnt work 'el'. i do all step correct. but 'el' says:
>>> el
Traceback (most recent call last):
File "", line 1, in
NameError: name 'el' is not defined
how can ı defıne 'el'? or sth else?(vers.2018)
Use this script as the RPS "init" script: gist.github.com/eirannejad/4e275166bf2015f4f844bb1d087ca4d6
@@pyRevit I embed script ın 'init.py' file. It works. Thanks.
you're simply Great 👏🏻👍🏻
Hi..the video was insightful.. How to get the wall element out of the revit object in the pyrevit console...Thanks in advance
When importing modules what is the most efficient way to know which modules to import? Do you write your code and then go back and look for the modules they are contained within?
Not really. overtime you learn slowly which modules to use by looking at their documentation a lot and testing them. But for tasks that I don't know there is a module, I generally do a search on Stackoverflow or Pypi to see if there is anything available and read their docs.
Thank you so much for this session , Ehsan. I tried the code in the session but the result of the volume is in cubic feet , i asking if there is a method to represent the volume in cubic meter as the Revit model is in metric unit
You could convert like this total_volume = (total_volume + vol_param.AsDouble())*0.0283
Thank you so much! How to select elements of linked RVT document in current project?
Why don't we use "GetMaterialVolume" method? Thanks!
The intention was to talk about the underlying API and explaining how it works.
@@pyRevit Thank you for your explanation and great video. This helps me a lot.
Thank you so much. That's very helpful for me.
Thanks, I have been enjoying going through this. When I do the for loop to print (for el in cl:...etc) I dont get anything back. no errors but nothing is printed either. I do have a couple of walls modeled. Any idea what Im doing wrong?
nevermind! figured it out lol
Sorry to interrupt, but i face the same problem, may i ask how did you solve this problem?? Much thanks!!
Hi! Thanks for great tutorials!
I'm having problem with unit conversion in that example. When I add to this loop additional prints I get something like this:
for wall in wall_collector:
vol_param=wall.LookupParameter('Volume')
if vol_param:
total_volume = total_volume + vol_param.AsDouble()
print(vol_param.AsValueString())
print(vol_param.AsDouble())
Output:
36.80 m³
1299.57973535
21.28 m³
751.496107833
18.40 m³
649.789867675
10.64 m³
375.748053917
Do you know what can be cause of that?
These are 4 pairs of prints for 4 elements being processed. Remember you're in a loop. Each loops isprinting AsValueString() and AsDouble() values
I get an Exception "LookupParameter() takes exactly 2 arguments (1 given)". What did I wrong?
The first parameter is the object instance. LookupParameter is a method on the type Element. So call that from the element instance. e.g el.LookupParameter(param_name)
I have this in my script "wall.LookupParameter('Volume')" and it didn't work?
Not sure then. Please submit your test model and script in issues to I can take a look. github.com/eirannejad/pyRevit/issues
It works! 😀 Thanks a lot, I wrote everything of the beginning on my own and it works. I have also convert it to cubic meters!
Hi everyone,
How could I create a command that calculate total weight of a scaffold according to the items selected?
Thank you.
Hello. Thank you for your tutorial. Trying recode it, but have one trouble. In my system i use m3 units, but when i get values by AsDouble, system return to me Volume in CF not in m3, but if i try get values by string, i got it in m3 but in string format. Please help me, is it possible get Volume in m3 by method AsDouble?
No. AsDouble() always returns values in internal API units. You need to do a quick CF to m3 conversion obviously. The AsValueString() however returns the string value with representing unit sign based on the model unit settings. That is good for quickly displaying pre-formatted results.
Thank you Ehsan!!!
vary helpful tutorial !
Thank you so much sir :D
Here's a stupid error I made that might be tripping up someone else: please note that it's "OfCategory", not "ofCategory" ... I'm not used to method names beginning with an uppercase letter, and of course in English, "of" is almost never capitalized in titles, so I mistyped it and it took me forever to find my error!
Very Good!!!!!!!!!!!
nice.
Stop sayingg ammmmm ummmmm uhmmmmmm it sooo annoyinggggg
Hi, i got the following error. >>>
Exception : IronPython.Runtime.UnboundNameException: name 'BuildInCategory' is not defined
bei IronPython.Runtime.Operations.PythonOps.GetVariable(CodeContext context, String name, Boolean isGlobal, Boolean lightThrow)
bei IronPython.Compiler.LookupGlobalInstruction.Run(InterpretedFrame frame)
bei Microsoft.Scripting.Interpreter.Interpreter.Run(InterpretedFrame frame)
bei Microsoft.Scripting.Interpreter.LightLambda.Run2[T0,T1,TRet](T0 arg0, T1 arg1)
bei IronPython.Compiler.PythonScriptCode.RunWorker(CodeContext ctx)
bei Microsoft.Scripting.Hosting.ScriptSource.Execute(ScriptScope scope)
bei Microsoft.Scripting.Hosting.ScriptSource.ExecuteAndWrap(ScriptScope scope, ObjectHandle& exception)