1

I am trying to verify if a parameter exists or not in a document, and (if it exists) if it is empty or filled.

The problem is that the code always returns that the parameter is filled if it exists. Even if it exists but is empty. So lines 30 to 33 do not really work. I've tried many things already but I don't know what I'm doing wrong.

Does anybody know what is the mistake?

Thank you! enter image description here

... I'll have to add the code I was talking about in the comment here because I couldn't add a picture in there... enter image description here

Screen shot for the parameter IsExtendedWarranty: enter image description here

1 Answers1

2

You are calling the Element GetParameters method.

It returns a list of Parameter objects.

To check the value of a parameter, you need to add two more steps:

  • Pick one of the parameters from the list, e.g. by selecting the first element.
  • Retrieve its value. For instance, if it has a string data type, use AsString.
Jeremy Tammik
  • 7,333
  • 2
  • 12
  • 17
  • Thank you for answering! So, maybe in my case it would be better to use the LookupParameter method that gives me the first parameter with that name... I used the LookupParameter method and added the AsString and now it shows me when the parameter is empty! Thanks! – Tais Magalhaes Jul 01 '20 at 09:09
  • `GetParameters` is bad. `LookupParameter` also. They are stupid, because they search for a string. Much better: get the parameter using the built-in parameter enum value. – Jeremy Tammik Jul 02 '20 at 10:36
  • 1
    https://thebuildingcoder.typepad.com/blog/2020/05/compiling-the-revit-2021-sdk-samples.html#3 – Jeremy Tammik Jul 02 '20 at 10:37
  • 1
    Read Answer 2 in this discussion: https://thebuildingcoder.typepad.com/blog/2018/11/efficient-elegant-code-and-automatic-dashboard.html – Jeremy Tammik Jul 02 '20 at 10:39
  • Thank you for your attention! The problem is that none of the parameters I am working with are built-in parameters. They are IFC parameters located in the shared parameters file. The idea is to read the parameters that are listed in an excel worksheet (that will be several, one for each used IFC property set) and check if they exist in the model for each of the listed elements. I'm actually trying this now: – Tais Magalhaes Jul 02 '20 at 15:40
  • It's in the question in the top I found it in a dynamo blog post and it actually showed me the accurate result... But maybe it's not the best solution?! – Tais Magalhaes Jul 02 '20 at 15:56
  • 1
    Yes, for user defined family parameters and shared parameters, avoiding the string comparison is a bit trickier than with built-in parameters. If you are absolutely certain that only one parameter matches the search/target name, then `LookupParameter` will return it; it returns the first match it finds. From the `Parameter` object, you still need to extract the value, e.g., using `AsString`, `AsDouble`, `AsElementId`, etc. – Jeremy Tammik Jul 03 '20 at 17:29
  • Thank you again for your help! I'm sorry for asking so many questions, but I couldn't find a way to entirely solving the problem. I couldn't get the boolean parameters from the Revit model. Using the lookup tool, I saw that yes/no parameters are integer. So, they are assigned the values 0 and 1... But what about when this parameter exists but they are not filled (not 0 and not 1 as well). Do you know how I could identify if it is filled? I also tried to use the 'HasValue' for all the parameters, but it didn't work. – Tais Magalhaes Jul 06 '20 at 09:19
  • I am a beginner in Revit API and python as well. I didn't want to ask everything here, but I tried many things and I really can't find a solution. – Tais Magalhaes Jul 06 '20 at 09:19
  • There are only three options: `0`, `1` and `not set`. How do those three appear in RevitLookup? – Jeremy Tammik Jul 07 '20 at 10:41
  • Only 0 and 1 appear in Revit Lookup here. If it is not set, it shows 0. I took a screen shot, which I'll put in the question again. – Tais Magalhaes Jul 07 '20 at 13:19