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

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

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

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

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

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

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

  • @kslifter1
    @kslifter1 2 ปีที่แล้ว +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  2 ปีที่แล้ว +1

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

  • @kristianbrango7711
    @kristianbrango7711 9 หลายเดือนก่อน +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  9 หลายเดือนก่อน

      Thanks, glad you liked them.

  • @toothbrush4022
    @toothbrush4022 2 ปีที่แล้ว +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  2 ปีที่แล้ว +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'] #

  • @digitallyaligned
    @digitallyaligned 9 หลายเดือนก่อน +1

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

    • @ErikFrits
      @ErikFrits  9 หลายเดือนก่อน +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

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

    Thank you very much bro for your videos!!!

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

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

  • @gdmbre
    @gdmbre 8 วันที่ผ่านมา +1

    great video! thank you so much!

    • @ErikFrits
      @ErikFrits  วันที่ผ่านมา

      Glad it was helpful!

  • @RyanMJohnston
    @RyanMJohnston 5 หลายเดือนก่อน +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  5 หลายเดือนก่อน

      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.

  • @muhammedrafi1831
    @muhammedrafi1831 9 หลายเดือนก่อน +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  9 หลายเดือนก่อน

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

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

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

    • @ErikFrits
      @ErikFrits  2 ปีที่แล้ว +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 2 ปีที่แล้ว

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

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

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

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

      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 ปีที่แล้ว +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  ปีที่แล้ว +1

      @@Rainquiller Happy to Help!

  • @AndrewHerbert-ho1ov
    @AndrewHerbert-ho1ov 8 หลายเดือนก่อน +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  8 หลายเดือนก่อน +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 8 หลายเดือนก่อน

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

  • @Maldemu343
    @Maldemu343 5 หลายเดือนก่อน +1

    Does this method work in the Python Node of Dynamo?

    • @ErikFrits
      @ErikFrits  5 หลายเดือนก่อน +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.

  • @Cokoladni
    @Cokoladni 2 ปีที่แล้ว +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  2 ปีที่แล้ว

      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!

  • @AndreaGhensi
    @AndreaGhensi ปีที่แล้ว +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  ปีที่แล้ว +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.

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

    very cool

  • @kimfei95
    @kimfei95 2 ปีที่แล้ว +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  2 ปีที่แล้ว

      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

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

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

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

      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!

  • @ghazaleheslami1986
    @ghazaleheslami1986 ปีที่แล้ว +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  ปีที่แล้ว

      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

  • @ВладЗайцев-г2и
    @ВладЗайцев-г2и ปีที่แล้ว +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  ปีที่แล้ว

      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.

    • @ВладЗайцев-г2и
      @ВладЗайцев-г2и ปีที่แล้ว +1

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

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

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

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

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

  • @HaiHoang-ks4hh
    @HaiHoang-ks4hh ปีที่แล้ว +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  ปีที่แล้ว

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

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

    Does anyone know where "get_Parameter" method came from? I can't find the documentation, and in Revit API the method is GetParameter()
    I'have found other function in PyRevit Documentation
    get_param_value(targetparam)
    anyone know the difference? Which is better?
    Thanx

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

      get_Parameter is mentioned in the remarks of Parameter Class and in Revit API Dev Guide.
      Haven't tried pyRevit function, but sometimes you get error in pyRevit if you try to get something like
      wall_type.Name (for some reason you can't get name property from types)
      But I avoid it using Element.Name.GetValue(wall_type)

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

      @@ErikFrits Thank you for your response.
      Regrets from Mexico City.

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

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

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

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

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

      @@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  2 ปีที่แล้ว

      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.

  • @yanirschneiderman5921
    @yanirschneiderman5921 ปีที่แล้ว +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  ปีที่แล้ว +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 ปีที่แล้ว +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  ปีที่แล้ว

      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 ปีที่แล้ว +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  ปีที่แล้ว +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!

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

    IN FLOOR IS THE BOUNDINGBOX A PARAMETER ?

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

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

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

    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  ปีที่แล้ว

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

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

      @@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 ปีที่แล้ว

      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  ปีที่แล้ว

      ​@@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 ปีที่แล้ว +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 :)

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

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

    • @ErikFrits
      @ErikFrits  2 ปีที่แล้ว +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 2 ปีที่แล้ว

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

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

      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 2 ปีที่แล้ว

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

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

  • @ceimirmaverick7231
    @ceimirmaverick7231 9 หลายเดือนก่อน +1

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

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

      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

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