Python for Revit: Basics of collecting data from Revit database

Поделиться
HTML-код
  • Опубликовано: 28 янв 2025

Комментарии • 77

  • @katchupoy01
    @katchupoy01 6 лет назад +6

    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.

    • @pyRevit
      @pyRevit  6 лет назад +1

      Thank you! 😁

  • @tadeh1
    @tadeh1 5 лет назад +1

    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.

  • @JonnyD000
    @JonnyD000 6 лет назад +6

    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!

  • @ArsenSafaryan
    @ArsenSafaryan 7 лет назад +1

    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.

  • @martinspence406
    @martinspence406 7 лет назад +4

    Thank you so much for this, Ehsan. You are presenting this in an extremely informative, thorough and nicely paced manner :-)

  • @michaeljones1410
    @michaeljones1410 4 года назад

    Halfway through session #2, learning much and enjoying the process! Thank you so much.

  • @thomastakeuchi985
    @thomastakeuchi985 5 лет назад +1

    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!

  • @suvirsathick9793
    @suvirsathick9793 4 месяца назад

    thank you so much really helpful for me to get start pyrevit i am going to proud as a pyrevit Api Developer

  • @AlbrechtJ
    @AlbrechtJ 3 года назад

    Ehsan, thanks for explaining your masterpiece work.

  • @Thepeopleofsyria
    @Thepeopleofsyria 7 лет назад

    Thank you so much for this video. More and more, please, of these very usefull Python with Revit skills.

  • @leonardillerhaus4236
    @leonardillerhaus4236 7 лет назад

    Thank you so much for your great work! I really appreciate the way you explain how things work. Looking forward to the next sessions!

  • @mehdinourollah
    @mehdinourollah 7 лет назад +1

    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

  • @timetostudy6443
    @timetostudy6443 4 года назад

    This thing gave me a headache. Tho don’t know if I should continue, thanks you for the invaluable tutorial

  • @yuanlin4139
    @yuanlin4139 6 лет назад +1

    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!

    • @pyRevit
      @pyRevit  6 лет назад

      I use VisualStudio Code at the moment. But I don't use autocompletion for Revit API

  • @martinchen9667
    @martinchen9667 7 лет назад

    Thank you so much for this! A really good video for API newbie.

  • @throwaway3946
    @throwaway3946 5 лет назад +2

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

    • @throwaway3946
      @throwaway3946 5 лет назад +2

      Please ignore me. this is the correct result in Cubic feet!

  • @Shawshank08
    @Shawshank08 5 лет назад +1

    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 ?

    • @pyRevit
      @pyRevit  5 лет назад

      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

    • @Shawshank08
      @Shawshank08 5 лет назад

      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
      @pyRevit  5 лет назад

      Send me your code or a snippet please. It’s hard to debug without seeing 😁

    • @Shawshank08
      @Shawshank08 5 лет назад

      @@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)

    • @Shawshank08
      @Shawshank08 5 лет назад

      @@pyRevit Ehsan, it worked. I had to add "import Autodesk.Revit.DB.Mechanical"

  • @DinkeyMalcho
    @DinkeyMalcho 5 лет назад +1

    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?

    • @pyRevit
      @pyRevit  5 лет назад +2

      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"

    • @sepidehroohi3233
      @sepidehroohi3233 4 года назад

      hi, i have the same problem,did you solve that?

    • @HuyLeAEC
      @HuyLeAEC 4 года назад +2

      @@sepidehroohi3233 you can try
      cl = DB.FilteredElementCollector(doc)
      cl.OfCategory(DB.BuiltInCategory.OST_Walls)

  • @ganesankathiravan7710
    @ganesankathiravan7710 6 лет назад +1

    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?

    • @pyRevit
      @pyRevit  6 лет назад

      You need to filter for OST_Windows using OfCategory method on the FilteredElementCollector.
      www.revitapidocs.com/2018.1/ba1c5b30-242f-5fdc-8ea9-ec3b61e6e722.htm

    • @ganesankathiravan7710
      @ganesankathiravan7710 6 лет назад +1

      Thank you very much for your help. I got it and works perfect.

  • @tonyiommisg
    @tonyiommisg 4 года назад +1

    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!

    • @pyRevit
      @pyRevit  4 года назад

      FilteredElementCollector is under Autodesk.Revit.DB namespace

  • @ChristianJGentry
    @ChristianJGentry 6 лет назад +2

    Awesome video, does a lot of this information transfer over to Dynamo users as well?

    • @pyRevit
      @pyRevit  6 лет назад

      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

    • @ChristianJGentry
      @ChristianJGentry 6 лет назад +1

      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.

    • @pyRevit
      @pyRevit  6 лет назад +1

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

    • @ChristianJGentry
      @ChristianJGentry 6 лет назад

      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!

  • @alexandraleclerc4651
    @alexandraleclerc4651 7 лет назад +2

    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 ?

    • @pyRevit
      @pyRevit  7 лет назад

      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

    • @alexandraleclerc4651
      @alexandraleclerc4651 7 лет назад +1

      Thank you so much !

  • @eda4241
    @eda4241 4 года назад +2

    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)

    • @pyRevit
      @pyRevit  4 года назад +2

      Use this script as the RPS "init" script: gist.github.com/eirannejad/4e275166bf2015f4f844bb1d087ca4d6

    • @eda4241
      @eda4241 4 года назад

      @@pyRevit I embed script ın 'init.py' file. It works. Thanks.

  • @engahmedsalah
    @engahmedsalah 2 года назад

    you're simply Great 👏🏻👍🏻

  • @chandumadgula9424
    @chandumadgula9424 Год назад

    Hi..the video was insightful.. How to get the wall element out of the revit object in the pyrevit console...Thanks in advance

  • @titobandito6060
    @titobandito6060 6 лет назад

    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?

    • @pyRevit
      @pyRevit  6 лет назад

      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.

  • @TheMido688
    @TheMido688 3 года назад

    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

    • @abduls9316
      @abduls9316 2 года назад

      You could convert like this total_volume = (total_volume + vol_param.AsDouble())*0.0283

  • @billmoresso908
    @billmoresso908 7 лет назад

    Thank you so much! How to select elements of linked RVT document in current project?

  • @selincelen471
    @selincelen471 3 года назад +1

    Why don't we use "GetMaterialVolume" method? Thanks!

    • @pyRevit
      @pyRevit  3 года назад +1

      The intention was to talk about the underlying API and explaining how it works.

    • @selincelen471
      @selincelen471 3 года назад

      ​@@pyRevit Thank you for your explanation and great video. This helps me a lot.

  • @doodlslee
    @doodlslee 6 лет назад

    Thank you so much. That's very helpful for me.

  • @musalah1
    @musalah1 6 лет назад

    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?

    • @musalah1
      @musalah1 6 лет назад

      nevermind! figured it out lol

    • @bongbong26d
      @bongbong26d 5 лет назад

      Sorry to interrupt, but i face the same problem, may i ask how did you solve this problem?? Much thanks!!

  • @adryjanek
    @adryjanek 7 лет назад

    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?

    • @pyRevit
      @pyRevit  7 лет назад

      These are 4 pairs of prints for 4 elements being processed. Remember you're in a loop. Each loops isprinting AsValueString() and AsDouble() values

  • @stijncox8503
    @stijncox8503 6 лет назад

    I get an Exception "LookupParameter() takes exactly 2 arguments (1 given)". What did I wrong?

    • @pyRevit
      @pyRevit  6 лет назад

      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)

    • @mtbfun2960
      @mtbfun2960 6 лет назад

      I have this in my script "wall.LookupParameter('Volume')" and it didn't work?

    • @pyRevit
      @pyRevit  6 лет назад

      Not sure then. Please submit your test model and script in issues to I can take a look. github.com/eirannejad/pyRevit/issues

    • @stijncox8503
      @stijncox8503 6 лет назад +1

      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!

  • @titomoura7014
    @titomoura7014 5 лет назад

    Hi everyone,
    How could I create a command that calculate total weight of a scaffold according to the items selected?
    Thank you.

  • @konstantinshyshkin4314
    @konstantinshyshkin4314 6 лет назад

    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?

    • @pyRevit
      @pyRevit  6 лет назад

      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.

  • @andyoohhh2061
    @andyoohhh2061 7 лет назад

    Thank you Ehsan!!!

  • @jo199281
    @jo199281 6 лет назад

    vary helpful tutorial !

  • @thomas_lex_inc
    @thomas_lex_inc 6 лет назад

    Thank you so much sir :D

  • @jamiehutchings2869
    @jamiehutchings2869 3 года назад

    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!

  • @pochuncheung569
    @pochuncheung569 7 лет назад

    Very Good!!!!!!!!!!!

  • @feri4life177
    @feri4life177 2 года назад

    nice.

  • @sbr4897
    @sbr4897 Год назад

    Stop sayingg ammmmm ummmmm uhmmmmmm it sooo annoyinggggg

  • @feri4life177
    @feri4life177 2 года назад

    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)