Revit API Parameters: How to Get/Set Parameters with Python.

Sdílet
Vložit
  • čas přidán 9. 08. 2024
  • 📙 Get Free E-Book: Beginner's Guide to Revit API:
    learnrevitapi.com/ebook
    --------------------------------------------------
    📝 It's time to talk about RevitAPI Parameters. It's important to know how to get and set parameters when you create you custom Revit add-ins. There are different methods for getting built-in parameters and shared parameters, and I will walk you through them.
    Also we will create a new little tool together in the end of the video.
    💬 Links:
    - GitHub: github.com/ErikFrits/EF-Tools
    🎯Extra Tutorial: Set Group Names to its Members parameter
    / dev-diary-03-to-70273393
    💟 You can support my channel by:
    - 🔔 Subscribing
    - 👍 Liking
    - ⌨ Leaving a comment.
    ❤️ Thank you for watching!
    🎥Chapters:
    00:00 Intro
    00:30 Look inside with RevitLookup
    02:20 Create pyRevit button
    03:30 Get all Parameters
    06:50 Get Built-In Parameters
    09:40 Get Shared Parameters
    12:00 Get Type Parameters
    14:00 Set Parameter Value
    18:10 Revit Internal Units
    19:40 Me from the Future
    20:00 Create a new Custom Tool
    21:50 Outro + Homework
    22:30 Homework Solution
    🎵 StreamBeats - In 4k
    Tags: #LearnRevitAPI #RevitAPI

Komentáře • 78

  • @ErikFrits
    @ErikFrits  Před 2 lety +1

    🎯Extra Tutorial: Set Group Names to its Members parameter
    www.patreon.com/posts/dev-diary-03-to-70273393

  • @mahmoudfawzy8354
    @mahmoudfawzy8354 Před 11 měsíci +1

    I think that after a long time searching for a source to learn Revit API, I have found the best way :)

  • @kristianbrango7711
    @kristianbrango7711 Před 4 měsíci +1

    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.

    • @ErikFrits
      @ErikFrits  Před 4 měsíci

      Thanks, glad you liked them.

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

    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!

    • @ErikFrits
      @ErikFrits  Před 2 lety +1

      Thanks!
      I am really happy to break down coding for people in AEC.
      oh yeah, SnoopDB Tool is a must have🔥!

  • @RyanMJohnston
    @RyanMJohnston Před měsícem +1

    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

    • @ErikFrits
      @ErikFrits  Před měsícem

      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.

  • @toothbrush4022
    @toothbrush4022 Před rokem +2

    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.

    • @ErikFrits
      @ErikFrits  Před rokem +2

      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'] #

  • @filea94
    @filea94 Před rokem +1

    Thank you very much bro for your videos!!!

    • @ErikFrits
      @ErikFrits  Před rokem

      My pleasure! I hope you learn something new and useful!

  • @muhammedrafi1831
    @muhammedrafi1831 Před 4 měsíci +1

    Your Videos are awesome,you presentation is greate.can you show how to deal with subelements like points and lines on floors and roofs

    • @ErikFrits
      @ErikFrits  Před 4 měsíci

      Thanks, appreciate that.
      Can you give an example of what you want to do with them?

  • @atanooniell4180
    @atanooniell4180 Před rokem +1

  • @AndrewHerbert-ho1ov
    @AndrewHerbert-ho1ov Před 4 měsíci +1

    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.

    • @ErikFrits
      @ErikFrits  Před 4 měsíci +1

      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.

    • @AndrewHerbert-ho1ov
      @AndrewHerbert-ho1ov Před 4 měsíci

      @@ErikFrits Thanks, checking .IsShared first sounds a bit more efficient than what I'm doing!

  • @feri4life177
    @feri4life177 Před rokem +1

    very cool

  • @digitallyaligned
    @digitallyaligned Před 4 měsíci +1

    hi, is it possible to set parameter for all selected elements ?

    • @ErikFrits
      @ErikFrits  Před 4 měsíci +1

      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

  • @kimfei95
    @kimfei95 Před rokem +1

    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?

    • @ErikFrits
      @ErikFrits  Před rokem

      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

  • @HaiHoang-ks4hh
    @HaiHoang-ks4hh Před rokem +1

    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?"

    • @ErikFrits
      @ErikFrits  Před rokem

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

  • @Cokoladni
    @Cokoladni Před rokem +1

    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.

    • @ErikFrits
      @ErikFrits  Před rokem

      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!

  • @yanirschneiderman5921
    @yanirschneiderman5921 Před rokem +1

    how do i set parameter, to change material, inside wall type? i cant find it in properties(revit look up)..

    • @ErikFrits
      @ErikFrits  Před rokem

      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!

  • @daveotis7016
    @daveotis7016 Před 2 lety +2

    @Erik Frits another great video! Question: I can i get a parameter value from an object in a linked model? Thanks!

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

      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)

    • @daveotis7016
      @daveotis7016 Před 2 lety

      @@ErikFrits Fantastic, i will give it a try soon, thanks again Eric!

  • @rezwanulhoque117
    @rezwanulhoque117 Před 8 měsíci +1

    How to relate an Excel file in this Python, excel data set to the Revit parameter value.

    • @ErikFrits
      @ErikFrits  Před 7 měsíci

      I made a video a while back, but I never finished editing it. I might write a blog article in the future ;)

  • @user-xo4km3re9d
    @user-xo4km3re9d Před rokem +1

    Please help me) how to transfer the value( example 6’ 10 1/2”)from the built-in parameter to the shared parameters?

    • @ErikFrits
      @ErikFrits  Před rokem

      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.

    • @user-xo4km3re9d
      @user-xo4km3re9d Před rokem +1

      @@ErikFrits Thank you so much for your help, Eric You're the best!

  • @ghazaleheslami1986
    @ghazaleheslami1986 Před 8 měsíci +1

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

    • @ErikFrits
      @ErikFrits  Před 8 měsíci

      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

  • @Maldemu343
    @Maldemu343 Před 24 dny +1

    Does this method work in the Python Node of Dynamo?

    • @ErikFrits
      @ErikFrits  Před 24 dny +1

      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.

  • @Rainquiller
    @Rainquiller Před 10 měsíci +1

    hi Erik, question, where did the get_Parameter method come from?

    • @ErikFrits
      @ErikFrits  Před 10 měsíci

      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 😅

    • @Rainquiller
      @Rainquiller Před 10 měsíci +1

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

    • @ErikFrits
      @ErikFrits  Před 10 měsíci +1

      @@Rainquiller Happy to Help!

  • @yanirschneiderman5921
    @yanirschneiderman5921 Před rokem +1

    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

    • @ErikFrits
      @ErikFrits  Před rokem +1

      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!

    • @myriamschneiderman1186
      @myriamschneiderman1186 Před rokem +1

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

    • @ErikFrits
      @ErikFrits  Před rokem

      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?

    • @yanirschneiderman5921
      @yanirschneiderman5921 Před rokem +1

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

    • @ErikFrits
      @ErikFrits  Před rokem +1

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

  • @gilbertogranados2959
    @gilbertogranados2959 Před rokem

    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
      @ErikFrits  Před rokem

      What kind of parameter are you changing? Can you send the line of code where you get parameter and set value.

    • @gilbertogranados2959
      @gilbertogranados2959 Před rokem

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

    • @gilbertogranados2959
      @gilbertogranados2959 Před rokem

      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"

    • @ErikFrits
      @ErikFrits  Před rokem

      ​@@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_...)

    • @gilbertogranados2959
      @gilbertogranados2959 Před rokem +1

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

  • @ghassenmhmh7988
    @ghassenmhmh7988 Před rokem

    IN FLOOR IS THE BOUNDINGBOX A PARAMETER ?

    • @ErikFrits
      @ErikFrits  Před rokem

      There is a method to get BoundingBox
      el.get_BoundingBox(view)

  • @alwinbro2523
    @alwinbro2523 Před rokem

    Hi @Erik frits thank u for ur explanation.is any possible for can u make revit api tutorial?

    • @ErikFrits
      @ErikFrits  Před rokem

      Hi,
      What do you mean exactly ? I have a playlist of around 10 videos related to Revit API

    • @alwinbro2523
      @alwinbro2523 Před rokem

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

    • @ErikFrits
      @ErikFrits  Před rokem

      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.

  • @michabrya5153
    @michabrya5153 Před rokem

    ⌨ - great video! :) Is it possible to create some kind of parameter by revit API?

    • @ErikFrits
      @ErikFrits  Před rokem +1

      yes There is definitely a way to create and add parameters to Revit.
      I Don't have any snippets to share at the moment

    • @michabrya5153
      @michabrya5153 Před rokem

      @@ErikFrits okay, I found it. ;) Method AddParameter (www.revitapidocs.com/2021.1/fb4f8475-440f-6454-768f-777388a7fdd4.htm) - thanks!

    • @ErikFrits
      @ErikFrits  Před rokem

      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

    • @michabrya5153
      @michabrya5153 Před rokem

      @@ErikFrits you are right, I will try diffrent.

  • @ceimirmaverick7231
    @ceimirmaverick7231 Před 5 měsíci +1

    Hi, idk how to use a interger value for change a value of parameter. Is using “ “??? I does not work 🥲 HELP

    • @ErikFrits
      @ErikFrits  Před 5 měsíci

      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

  • @AndreaGhensi
    @AndreaGhensi Před rokem +1

    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)

    • @ErikFrits
      @ErikFrits  Před rokem +1

      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.

  • @danielsellam-kazoula9970