Cannot find Name of ColorFillSchemeEntry by API

Cannot find Name of ColorFillSchemeEntry by API

supportT7RUE
Explorer Explorer
1,285 Views
9 Replies
Message 1 of 10

Cannot find Name of ColorFillSchemeEntry by API

supportT7RUE
Explorer
Explorer

I'm looking into API to retrieve Color for given Area Type.

 

Quick search:

var schemes = new Autodesk.Revit.DB.FilteredElementCollector(doc)
.OfCategory(Autodesk.Revit.DB.BuiltInCategory.OST_ColorFillSchema)
.Select(s => s as ColorFillScheme);

var rentable = schemes
.Where(s => s.Name == "Rentable Area")
.FirstOrDefault();

List<ColorFillSchemeEntry> entries = rentable.GetEntries();

If I look on fields of each entry, I can find proper color, but not the name of given Area Type or any index. Entry.Caption or entry.GetStringValue() return empty string.

 

On GUI I clearly can see which color applies to which type, how can I find this relation by API?

 

supportT7RUE_0-1618432151521.png

 

0 Likes
Accepted solutions (1)
1,286 Views
9 Replies
Replies (9)
Message 2 of 10

Sean_Page
Collaborator
Collaborator

It looks like you just need to use .GetStringValue() method.

 

--Revit Lookup is invaluable--

spage_0-1618434067738.png

 

Sean Page, AIA, NCARB, LEED AP
Partner, Computational Designer, Architect
Message 3 of 10

Sean_Page
Collaborator
Collaborator

This was quick in Dynamo via Python, but it worked fine.

spage_0-1618434544977.png

 

Make sure you are getting a specific  entry to use the method on and not the list.

string name = entires[0].GetStringValue()

 

Sean Page, AIA, NCARB, LEED AP
Partner, Computational Designer, Architect
Message 4 of 10

mut9lu
Explorer
Explorer

GetStringValue() works for entries of Rooms color scheme, but not for Areas. Elements inside GetEntries() have empty values under GetStringValue(). That was first what I've tried (second after entry.Caption).

mut9lu_0-1618435357984.png

 

0 Likes
Message 5 of 10

Sean_Page
Collaborator
Collaborator

What if you use the ElementId value there to get the element?

Sean Page, AIA, NCARB, LEED AP
Partner, Computational Designer, Architect
0 Likes
Message 6 of 10

mut9lu
Explorer
Explorer

Ahhh, it was not element itself, but its GetDependentElements()

mut9lu_0-1618436090375.png

 

Thanks for pointing out RevitLookUp, I heard of it but didn't use previously.

 

0 Likes
Message 7 of 10

architect.bim
Collaborator
Collaborator
Accepted solution

One of the solutions could be getting all unique area types as parameter values of area objects. You can make a dictionary and use it to get proper area type names and colors:

# Python
area_types = {}
for area in FEC(doc).OfCategory(DB.BuiltInCategory.OST_Areas):
    area_type_parameter = area.get_Parameter(DB.BuiltInParameter.AREA_TYPE)
    area_type_id = area_type_parameter.AsElementId()
    area_type_name = area_type_parameter.AsValueString()
    if area_type_id not in area_types:
        area_types[area_type_id] = area_type_name

for scheme in FEC(doc).OfCategory(DB.BuiltInCategory.OST_ColorFillSchema):
    if scheme.Name == 'Rentable Area':
        scheme_entries = scheme.GetEntries()

entry_colors = {}
for entry in scheme_entries:
    entry_name = area_types[entry.GetElementIdValue()]
    if entry_name not in entry_colors:
        entry_colors[entry_name] = entry.Color

Maxim Stepannikov | Architect, BIM Manager, Instructor
0 Likes
Message 8 of 10

architect.bim
Collaborator
Collaborator

Is RevitLookup 2022 already available?


Maxim Stepannikov | Architect, BIM Manager, Instructor
0 Likes
Message 9 of 10

Sean_Page
Collaborator
Collaborator

Officially no, but since R22 has the same .Net version I assumed it would work and manually copied it to the add-ins folder. Works perfect.

Sean Page, AIA, NCARB, LEED AP
Partner, Computational Designer, Architect
Message 10 of 10

architect.bim
Collaborator
Collaborator

Very nice! I'll check it up 😃


Maxim Stepannikov | Architect, BIM Manager, Instructor
0 Likes