1

I am trying to import data from Excel to Revit Python Shell in order to verify if some parameters exist in the Revit file for selected categories of objects. But I am having some problems in the first 'for' loop (look into the first column of the excel sheet and get the categories). The first step to achieving what I wanted would be to get all the elements of the categories that I want to analyze. I've tried a lot of things, but I always end up in this error shown in the picture (got string instead of built-in category). I searched for a method to transform a string into builtincategories, but I did not find anything.

Does anyone know how to deal with it? Is there a way to transform a string into built-in category or is there another solution for this?

Thank you! picture - screenshot

avocadoLambda
  • 1,332
  • 7
  • 16
  • 33

2 Answers2

2

This question is more a C# than a Revit API one. Search for 'c# enum string convert', which turns up, e.g., convert a string to an enum in C#. In this case:

BuiltInCategory bic = BuiltInCategory.Parse( "some_string" );
Jeremy Tammik
  • 7,333
  • 2
  • 12
  • 17
  • Thank you for your appreciation. Glad it helped. You can upvote the answer to make it easier to find for others with the same question. – Jeremy Tammik Jun 19 '20 at 17:21
  • Actually this didn't work for me, but I managed with: `BuiltInCategory bic = (BuiltInCategory)Enum.Parse(typeof(BuiltInCategory), categoryString);` – Yafim Simanovsky Oct 10 '22 at 08:34
0

Looks like the problem is with these lines:

 fec = FilteredElementCollector(doc)
 cat = fec.OfCategory(i.Value2)

In this instance, i.Value2 is a string, but fec.OfCategory is wanting a BuiltInCategory as you've commented earlier.

Jeremy's answer will convert a string to a BuiltInCategory (thanks Jeremy, I had no idea you could do that!) like this: bic = BuiltInCategory.Parse(BuiltInCategory, "OST_PlumbingFixtures")

So in your example it would be:

fec.OfCategory(BuiltInCategory.Parse(BuiltInCategory, i.Value2.split('.')[1]))

Callum
  • 578
  • 3
  • 8