Python for Revit: Basics of collecting data from Revit database

Sdílet
Vložit
  • čas přidán 9. 09. 2024

Komentáře • 76

  • @katchupoy01
    @katchupoy01 Před 5 lety +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.

  • @tadeh1
    @tadeh1 Před 4 lety +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.

  • @michaeljones1410
    @michaeljones1410 Před 3 lety

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

  • @JonnyD000
    @JonnyD000 Před 5 lety +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 Před 6 lety +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 Před 7 lety +4

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

  • @thomastakeuchi985
    @thomastakeuchi985 Před 4 lety +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!

  • @AlbrechtJ
    @AlbrechtJ Před 3 lety

    Ehsan, thanks for explaining your masterpiece work.

  • @Thepeopleofsyria
    @Thepeopleofsyria Před 7 lety

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

  • @mehdinourollah
    @mehdinourollah Před 7 lety +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

  • @leonardillerhaus4236
    @leonardillerhaus4236 Před 6 lety

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

  • @timetostudy6443
    @timetostudy6443 Před 3 lety

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

  • @engahmedsalah
    @engahmedsalah Před 2 lety

    you're simply Great 👏🏻👍🏻

  • @martinchen9667
    @martinchen9667 Před 6 lety

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

  • @doodlslee
    @doodlslee Před 6 lety

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

  • @jo199281
    @jo199281 Před 6 lety

    vary helpful tutorial !

  • @andyoohhh2061
    @andyoohhh2061 Před 6 lety

    Thank you Ehsan!!!

  • @tonyiommisg
    @tonyiommisg Před 4 lety +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  Před 4 lety

      FilteredElementCollector is under Autodesk.Revit.DB namespace

  • @jamiehutchings2869
    @jamiehutchings2869 Před 2 lety

    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!

  • @thomas_lex_inc
    @thomas_lex_inc Před 6 lety

    Thank you so much sir :D

  • @throwaway3946
    @throwaway3946 Před 4 lety +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 Před 4 lety +2

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

  • @pochuncheung569
    @pochuncheung569 Před 6 lety

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

  • @chandumadgula9424
    @chandumadgula9424 Před rokem

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

  • @feri4life177
    @feri4life177 Před 2 lety

    nice.

  • @yuanlin4139
    @yuanlin4139 Před 5 lety +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  Před 5 lety

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

  • @eda4241
    @eda4241 Před 3 lety +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  Před 3 lety +2

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

    • @eda4241
      @eda4241 Před 3 lety

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

  • @DinkeyMalcho
    @DinkeyMalcho Před 4 lety +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  Před 4 lety +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 Před 4 lety

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

    • @HuyLeAEC
      @HuyLeAEC Před 3 lety +2

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

  • @Shawshank08
    @Shawshank08 Před 5 lety +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  Před 5 lety

      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 Před 5 lety

      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  Před 5 lety

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

    • @Shawshank08
      @Shawshank08 Před 5 lety

      @@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 Před 5 lety

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

  • @alexandraleclerc4651
    @alexandraleclerc4651 Před 6 lety +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  Před 6 lety

      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 Před 6 lety +1

      Thank you so much !

  • @ChristianJGentry
    @ChristianJGentry Před 6 lety +2

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

    • @pyRevit
      @pyRevit  Před 6 lety

      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 Před 6 lety +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  Před 6 lety +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 Před 6 lety

      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!

  • @billmoresso908
    @billmoresso908 Před 6 lety

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

  • @titomoura7014
    @titomoura7014 Před 4 lety

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

  • @selincelen471
    @selincelen471 Před 3 lety +1

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

    • @pyRevit
      @pyRevit  Před 3 lety +1

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

    • @selincelen471
      @selincelen471 Před 3 lety

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

  • @ganesankathiravan7710
    @ganesankathiravan7710 Před 6 lety +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  Před 6 lety

      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 Před 6 lety +1

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

  • @titobandito6060
    @titobandito6060 Před 6 lety

    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  Před 6 lety

      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 Před 3 lety

    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 Před 2 lety

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

  • @adryjanek
    @adryjanek Před 6 lety

    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  Před 6 lety

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

  • @konstantinshyshkin4314

    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  Před 6 lety

      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.

  • @musalah1
    @musalah1 Před 5 lety

    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 Před 5 lety

      nevermind! figured it out lol

    • @bongbong26d
      @bongbong26d Před 5 lety

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

  • @stijncox8503
    @stijncox8503 Před 5 lety

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

    • @pyRevit
      @pyRevit  Před 5 lety

      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 Před 5 lety

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

    • @pyRevit
      @pyRevit  Před 5 lety

      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 Před 5 lety +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!

  • @sbr4897
    @sbr4897 Před rokem

    Stop sayingg ammmmm ummmmm uhmmmmmm it sooo annoyinggggg

  • @feri4life177
    @feri4life177 Před rokem

    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)