Create pyRevit Template for Revit API + python

แชร์
ฝัง
  • เผยแพร่เมื่อ 8 พ.ย. 2024

ความคิดเห็น • 48

  • @kiriblender
    @kiriblender 2 ปีที่แล้ว +4

    Thank you for the effort you put in those videos! Those tutorials are great

    • @ErikFrits
      @ErikFrits  2 ปีที่แล้ว

      Glad you like them! Thanks

  • @dimitarzhelev1572
    @dimitarzhelev1572 2 ปีที่แล้ว +3

    Can you please make an in depth explanation of the revit FilteredElementCollector(doc), please? It would be very helpful. Thanks!

    • @ErikFrits
      @ErikFrits  2 ปีที่แล้ว +2

      I will see what I can do, these tutorials usually take way more time than I expect.
      I will need to focus on EF-Tools for a while, but I will try to start preparing for that video.

  • @danielsellam-kazoula9970
    @danielsellam-kazoula9970 2 ปีที่แล้ว +1

    Awesome ! Thank you ! I must still have typos because the replacement between brackets doesn't work , but I will find the issue ...

    • @ErikFrits
      @ErikFrits  2 ปีที่แล้ว +1

      Try to print the result of your function. If it's empty, maybe you forgot to return a value.
      I do a lot of print statements while developing especially when something does not work as it should.
      I have just realized I haven't published resulting code of this video to the GitHub, my Bad. I have just published it.
      Check out the link in Pinned comment, I hope it will help you.

    • @danielsellam-kazoula9970
      @danielsellam-kazoula9970 2 ปีที่แล้ว +2

      @@ErikFrits if it's not already on your list of videos, maybe you can show how you check your code all along the process ? I think I spend 3 hours only on your 16 minutes video in 0.75 speed it's so complete and dense !

    • @ErikFrits
      @ErikFrits  2 ปีที่แล้ว +1

      Thanks, I think this will naturally come from more coding tutorials.
      I hope you liked this format. I know that I heavily edit my videos to cut out or speed up all the boring parts, because anyway people watch, pause and then code themselves but I think it's better than 1 hr video with lots of pauses..
      I might experiment and make some raw videos of me coding as well. It will be much longer and less quality, but it is way faster to create and publish them, maybe people want it too.

  • @jedsanford7879
    @jedsanford7879 ปีที่แล้ว +1

    This is super helpful but I am finding I am a bit lost in the Python, I need a bit more on how to work with classes, methods, and attributes.

    • @ErikFrits
      @ErikFrits  ปีที่แล้ว

      Thanks, glad you loved it!
      Yeah basics of OOP is really good since we constantly work with Classes from Revit API. But luckily using them is much simpler than creating our own classes!
      Happy Coding!

  • @kiriblender
    @kiriblender 2 ปีที่แล้ว +3

    Are you going to make python tutorials as well? I love your tutorials, they are so easy to understand

    • @ErikFrits
      @ErikFrits  2 ปีที่แล้ว +2

      I think eventually I will make a series of python tutorials for beginners, but at the moment I want to focus more on making more tools and checking other technologies that might be beneficial in BIM workflows.

  • @antoinelevert5394
    @antoinelevert5394 ปีที่แล้ว +1

    Hi, thanks again for your video
    I got the code on Github, only when I run the code on Revit, I have an error message that appears: ImportError: cannot import _convert from Snippets
    When I decide to delete the line in question (line 45 of your code) I have a new error message which appears, this time from Revit: "A transaction or sub-transaction was opened but not closed. All changes to the active document made by External Command will be discarded"
    Thank you very much for your help

    • @ErikFrits
      @ErikFrits  ปีที่แล้ว

      👋Hi Antoine.
      1⃣ So the first error is because it's a custom import and I have a lib folder in the root of my extension and inside I had Snippets folder and there is _convert.py file from where I was bringing some functions. You can check my lib folder structure in GitHub to better understand it. It was just an example how to do custom imports so it's fine that you got an error because probably you didn't have the same lib folder as I do.
      2⃣Second error you get from Transaction which is necessary for making any changes in your Revit projects. Maybe it happened because you used Start and Commit as I wrote, but nothing has changed in between these 2 lines. so you can remove Transaction as well, unless you are modifying a document (Creating or Modifying elements). It was also an example on how to create Transactions, but I didn't make any changes in the project.
      I don't remember everything I said in the video, but maybe I didn't explain these 2 points well enough.
      🤷‍♂Sorry for inconveniences.

  • @bogdanpopa2978
    @bogdanpopa2978 ปีที่แล้ว +1

    Hi. Great video!
    I'm new to RevitAPI. Currently I'm getting a warning '__revit__' is not defined and Import "pyrevit" could not be imported. I've already added paths to settings.json and to Environment Variables. Still can't make them load Any ideas?

    • @ErikFrits
      @ErikFrits  ปีที่แล้ว

      I assume that you got these errors in your IDE, right?
      IDE is just a super NotePad where it's easier to code, but code has to be executed from Revit using pyRevit, RevitPythonShell or Python Node in Dynamo. __revit__ will work just fine in pyRevit and RevitPythonShell, however there is another method for Python Node in Dynamo. You can find an example in Dynamo Primer.
      I like to reference the following in paths:
      1. Revit Stubs for Autocomplete
      2. pyRevit lib for all additional imports
      3. custom library (lib folder in your .extension)
      This video is focused more about writing the template code, I have another one to set up your Development Environment. Have a look there as well, I think it might help you more with the question.

  • @camilosierraaranguren9994
    @camilosierraaranguren9994 11 หลายเดือนก่อน +1

    hi Erik, i follow all tutorial but in the last part of tutorial i see the "except" text but i dont see the changes in the doc

    • @ErikFrits
      @ErikFrits  11 หลายเดือนก่อน

      I would need to see an error statement to tell you for sure why it's happening.
      Can you remove try/except blocks and just leave the code under try block to get an error message? (don't forget to move it left since it won't be part of try/except block anymore).
      I assume that you are trying to set Level Name with forbidden symbol or not unique name. It will get clear once you manage to get an error message ;)

  • @blancarochag.8323
    @blancarochag.8323 2 ปีที่แล้ว +1

    Awesome! Thank you very much

    • @ErikFrits
      @ErikFrits  2 ปีที่แล้ว

      Glad it was helpful!

  • @siavashghorbany499
    @siavashghorbany499 2 ปีที่แล้ว +2

    Hey, please make some tutorials about using dynamic xaml in pyrevit. I mean for gathering and storing data from user and using it later. PyRevit official has stopped their tutorials but we are waiting for this specific tutor for years now! Thanks a lot

    • @ErikFrits
      @ErikFrits  2 ปีที่แล้ว

      Hi, I know what you mean. WPF is quite advanced topic especially when working with IronPython. Not so many resources available and you always need to look for solutions online and translate from C#.
      The workflow quite often requires to work with .NET classes if you want to customize certain things and that might be an overkill for many people. A simple change to make an element with rounded corners might take hours to make for unfamiliar with xaml. (I talk from experience 😅)
      I have some thoughts to make a series of tutorials to help people get started with it, but majority of my channel subscribers at the moment are beginners, and it might scare them away from coding.
      I am planning to cover pyRevit.forms and output in the near future because it provides a simpler approach to get inputs and control outputs and might be sufficient for many who is just starting out and does not need fancy custom GUI.
      I will see what I can do, but I have a list of videos planned already for the next few months. ⌨️

    • @siavashghorbany499
      @siavashghorbany499 2 ปีที่แล้ว +1

      @@ErikFrits Yup, you are absolutely right. Thanks. Actually, I am trying to develop an add-in in PyRevit, which needs a GUI to receive some information from users and store it in a SQL file. I found nothing related to python and XAML, and I am absolutely confused. Do you have any recommendations for me? Any substitute for XAML or any descent tutorial about it would be perfect. Honestly, I tried PyQt5 in PyRevit, it works perfectly in Pycharm and Visual Studio, but in the Revit, I get this annoying error: no module named 'pyqt5.sip'. And I don't know what to do with it.
      I would appreciate it if you have any recommendations.

    • @ErikFrits
      @ErikFrits  2 ปีที่แล้ว +1

      I am going to warn you that GUI with xaml have a steep learning curve and you might need to get comfortable reading C# code and translate it into IronPython. I mainly learnt about it from tutorials about WPF + C# and then I recreated similar thing with IronPython. There is going to be a lot of Trial and Errors!
      So the error you are getting is due to missing package in dependencies. You can have a look in pyrevit GitHub repo in 'pyRevit/site-packages/' to see all the packages that are shipped with pyRevit. In your case you would need to add this PyQt5 module to pyRevit somehow. I saw that you can declare dependencies = [] in extension.json file that you create for your extension. Maybe it will automatically install this package and then the issue is solved. I never tried it.
      Have a look here: www.notion.so/Share-Your-Extensions-48ff84d4eae846f4aa9567fca32ff4fe
      The bad and dirty way that might work is to add package folder next to a script or in lib folder. I would try it until I find a better way, but it's definetely not recommended way of doing it!
      If you need just a few simple inputs, have a look at pyrevit.forms in pyrevit docs. There should be plenty of examples for simple inputs, maybe it's good to use them until you find a way to create your own GUI. Alternatively rpw module had some predefined inputs too and its shipped with previt, so should not be any import issues. It might have more UI options, but I have never used it either. (revitpythonwrapper.readthedocs.io/en/latest/ui/forms.html#taskdialog) They have some sort of FlexForm.

  • @ErikFrits
    @ErikFrits  2 ปีที่แล้ว +3

    Source Code:
    github.com/ErikFrits/EF-Tutor/blob/main/EF-Tutor.tab/Tutorials.panel/TH-camLessons.pulldown/01_LevelsElevation.pushbutton/script.py

    • @Apsis0215
      @Apsis0215 2 ปีที่แล้ว +1

      dead lnk?

    • @ErikFrits
      @ErikFrits  2 ปีที่แล้ว +1

      ​@@Apsis0215 Thanks, I updated the link.

  • @yanirschneiderman5921
    @yanirschneiderman5921 2 ปีที่แล้ว +1

    thanks a lot! very useful

    • @ErikFrits
      @ErikFrits  2 ปีที่แล้ว

      Glad to hear that!

  • @mostafamahmoud-pw3ue
    @mostafamahmoud-pw3ue ปีที่แล้ว

    Great job, I already installed pyrevit as in video no.2 in this series. But when i write in a python script like this "import pyrevit", it could not be recognized!
    could you please help me how to define, install pyrevit to be used in pycharm python scripts ?

    • @ErikFrits
      @ErikFrits  ปีที่แล้ว

      pyCharm does not know where to look for pyRevit modules, so you need to add it in path refferences, same as I showed how to add Revit API stubs for autocomplete.
      pyRevit library is usually in AppData, like this:
      C:\Users\USERNAME\AppData\Roaming\pyRevit-Master\pyrevitlib
      But some people have it in programm files, depends how you installed it.
      P.S. Also pyCharm is just a helping tool to write the code, but it will never execute it because it's necessary 'to be connected' to Revit Application. So we write all the code in pyCharm, but then to execute we need to run it via pyRevit, RevitPythonShell or Python Node in Dynamo (also has a few differences)
      Hope it helps,
      Happy Coding!

    • @mostafamahmoud-pw3ue
      @mostafamahmoud-pw3ue ปีที่แล้ว +1

      @@ErikFrits thank you so much for the kind reply

  • @youssefchebel9400
    @youssefchebel9400 ปีที่แล้ว +1

    thanks for the video , but can i export all materials of revit to an excel file or .csv file ... if there is a method to get the dataset of all materials tell me please , i need help. and thank you so much :)

    • @ErikFrits
      @ErikFrits  ปีที่แล้ว +1

      Yes, you can if you know some python and Revit API
      1. Get all materials with FilteredElementCollector
      2. Iterate through and collect all the information
      3. Export to Excel while you iterating through materials
      I would also export ElementId, in case you will want to create a back link from excel eventually.

    • @youssefchebel9400
      @youssefchebel9400 ปีที่แล้ว

      @@ErikFrits thanks for your response , i will trying to do that because i learned python but Revit API no

  • @ne8325
    @ne8325 2 ปีที่แล้ว +1

    Hello,
    I have the following error: "Exception: Name cannot include prohibited characters."
    How can I fix it ?
    Thanks Erik for your work.

    • @ErikFrits
      @ErikFrits  2 ปีที่แล้ว

      It depends on characters that you are using and where...
      There are 2 options:
      1. You need to add the following line as the first line in your script file to use utf-8 encoding
      # -*- coding: utf-8 -*-
      2. You might try to use characters that Revit does not allow to use. For example we can't use '%' in View.Name...
      Try checking these 2 points, if error persists, I need an error message to tell you more

    • @ne8325
      @ne8325 2 ปีที่แล้ว +1

      @@ErikFrits
      # -- coding: utf-8 -- is already the first line of my script.
      I don't think that I am trying to use not allowed characters (only letters, numbers, brackets).
      IronPython Traceback:
      Traceback (most recent call last):
      File "G:\#########.tab\Naming.panel\LevelsElevations.pushbutton\script.py", line 129, in
      Exception: Name cannot include prohibited characters.
      Parameter name: name
      Script Executor Traceback:
      Autodesk.Revit.Exceptions.ArgumentException: Name cannot include prohibited characters.
      Parameter name: name
      à Autodesk.Revit.DB.Element.set_Name(String name)
      à CallSite.Target(Closure , CallSite , Object , Object )
      à System.Dynamic.UpdateDelegates.UpdateAndExecute2[T0,T1,TRet](CallSite site, T0 arg0, T1 arg1)
      à Microsoft.Scripting.Interpreter.DynamicInstruction`3.Run(InterpretedFrame frame)
      à Microsoft.Scripting.Interpreter.Interpreter.Run(InterpretedFrame frame)
      à Microsoft.Scripting.Interpreter.LightLambda.Run2[T0,T1,TRet](T0 arg0, T1 arg1)
      à IronPython.Compiler.PythonScriptCode.RunWorker(CodeContext ctx)
      à PyRevitLabs.PyRevit.Runtime.IronPythonEngine.Execute(ScriptRuntime& runtime)
      Thanks

    • @ErikFrits
      @ErikFrits  2 ปีที่แล้ว

      Hi sorry, I just noticed your message being held for review in TH-cam... I guess it didn't like the log message...
      If #########.tab is the real name of the folder, that could be an issue.
      Otherwise, you need to check what kind of value are you trying to pass when you set a name of something.
      Just print the value before you try to change name of something, and then try setting this value manually, I am sure you will get a warning from revit as well.
      There are bunch of symbols that Revit does not allow to use in names

  • @KervinCalero
    @KervinCalero ปีที่แล้ว +1

    ⌨ got stuck along the way but barely made it, ie. couldnt get the pyrevit module to be found

    • @ErikFrits
      @ErikFrits  ปีที่แล้ว

      Glad you made it!
      What was the issue?
      Do you mean autocomplete for pyRevit in pyCharm, or it actually didn't import when you ran your script in Revit ?

    • @KervinCalero
      @KervinCalero ปีที่แล้ว +1

      @@ErikFrits Thanks for your reply. As you show, when I use the pyrevit import statement "from pyrevit import revit, forms" I get pyrevit exception "CPython Traceback: KeyNotFoundException : KeyError......pyRevitLabs.PythonNet..." so then I changed to "from pyrevit import DB, UI, PyRevitException, PyRevitIOError, HOST_APP, EXEC_PARAMS". Then this works in my case.

    • @ErikFrits
      @ErikFrits  ปีที่แล้ว

      @@KervinCalero That's quite unusual.
      Glad you found alternative that worked for you!

    • @KervinCalero
      @KervinCalero ปีที่แล้ว +1

      @@ErikFrits Thank you again. On a different subject, I searched your blog and vids for anything on Worksets but did not find anything. Is it possible you can point me in the right direction: I'd like to get all the workset names and their visibility status (show or hide or whatever) for all PlanViews in a list? Is this possible for a single view? I have used GetWorksetVisibility but going nowhere 🤦‍♂Ultimately I like to set the workset visibility for that view also.

    • @ErikFrits
      @ErikFrits  ปีที่แล้ว +1

      Hi Kervin,
      I have a tool in EF-Tools - Create Workset View. Have a look at source code i think you will find what you need.
      Hover over the button and ALT+Click to open its folder where script is located.
      This tool creates 3D views for each workset and hides all except 1
      Happy coding!

  • @marceloromero8896
    @marceloromero8896 2 ปีที่แล้ว +1

    ⌨😉

    • @ErikFrits
      @ErikFrits  2 ปีที่แล้ว +1

      💪🖥 keep it up!