Robot API - Get section color

Robot API - Get section color

geralA8ZZM
Participant Participant
175 Views
6 Replies
Message 1 of 7

Robot API - Get section color

geralA8ZZM
Participant
Participant

I have a VBA code to export bar data to excel. I'm trying to add a feature to color the cell with the same color as the section, but I'm having trouble with it.

 

I've managed to get the weight/m before, with barsecdata.GetValue(I_BSDV_WEIGHT)

but there seems to be no label to get the color of the section...

0 Likes
Accepted solutions (1)
176 Views
6 Replies
Replies (6)
Message 2 of 7

Stephane.kapetanovic
Mentor
Mentor

HI @geralA8ZZM 

There is no Color property in IRobotBarSectionData.

Best Regards

Stéphane Kapetanovic

Did you find this post helpful? If it gave you one or more solutions,
don't forget to click the Accept Solution button and leave a < like !
EESignature
0 Likes
Message 3 of 7

geralA8ZZM
Participant
Participant

And no workaround? No way to check what color is assigned to a section via API? 

0 Likes
Message 4 of 7

Stephane.kapetanovic
Mentor
Mentor

There is no documented method for this, so you are essentially on your own.

If you are creating a collection of sections from scratch, you could use an iterator to increment the color for each new section.

The colors (AppSec_) are defined in the preference files according to the selected theme (e.g. Color.ini)

There are other approaches by OCR and pixel-scanning of the legend image, but they are more verbose and complex to explain here.

Stéphane Kapetanovic

Did you find this post helpful? If it gave you one or more solutions,
don't forget to click the Accept Solution button and leave a < like !
EESignature
0 Likes
Message 5 of 7

Stephane.kapetanovic
Mentor
Mentor
Accepted solution

Hi @geralA8ZZM,

As a follow-up to this thread, I put together a small demo tool that solves this the "hard way" reading the color directly from the rendered legend, since there's no API property for it.

Stephanekapetanovic_0-1787243851497.pngStephanekapetanovic_1-1787243892824.png

How it works

  1. Open a Robot project containing bars with sections
  2. Open the attached Excel workbook and click the "Run" button.
  3. The program captures the active view as an image, locates the color legend in the bottom-right corner, and calibrates the scan width from the detected color swatches.
  4. It runs OCR on that calibrated legend area to read each section name, then writes a CSV (section name + RGB values) to your temp folder.
  5. The Excel macro reads that CSV back and lists each section with its color.

Before running it

The .exe is unsigned, so most antivirus software will flag or quarantine it on first run, this is a not an actual detection. You'll need to add the extracted folder to your antivirus exclusion list before running it (Windows Security → Virus & threat protection → Manage settings → Exclusions → add the folder).

Current limitation

The software automatically detects the active theme, font, and text color. If the legend does not fit in the available space, as many views as necessary are created.

With font sizes below 8 pt, some entries may be omitted if OCR cannot read them reliably or if they fail to meet the 7/15-character matching threshold.

Using it in your own workflow

The macro is meant as a starting point, not a finished tool, since the CSV gives you the section name and its RGB color side by side, you can match it against your own bar export by section name, and apply the color to whichever cell/column makes sense for your export.

Extra option (advanced)

The tool also supports extracting materials or member types instead of section colors, via a command-line flag:

/s — bar sections (default, used by the demo workbook)
/m — materials
/t — member types

If you want to try one of these from the macro, just append the flag to the Run call

ws.Run """" & exePath & """ /t", 0, True

Honest caveat

This is a prototype built to solve the simple, common case, not a general-purpose solution for every theme, every view configuration, or very large models. If you run into a case it doesn't handle, feel free to reach out and I'll see what can be done.

Workbook + tool attached below. Updated 26/08/26

Best Regards

Stéphane Kapetanovic

Did you find this post helpful? If it gave you one or more solutions,
don't forget to click the Accept Solution button and leave a < like !
EESignature
Message 6 of 7

Stephane.kapetanovic
Mentor
Mentor

What's new

Faster, more robust, and theme-independent: the active theme, font, and text color are automatically detected from Robot's configuration files.

Parallel processing: OCR and image analysis run in parallel on captured images while Robot continues capturing the next batches.

Large legends are handled automatically: items are split into batches, captured successively, and the results are then merged.

Result: reliable color extraction across any theme, with support for large models and no manual configuration required.

Workbook + tool attached to msg #5

Stéphane Kapetanovic

Did you find this post helpful? If it gave you one or more solutions,
don't forget to click the Accept Solution button and leave a < like !
EESignature
Message 7 of 7

bhavani_sankuratri
Autodesk
Autodesk

Hi @geralA8ZZM ,

 

Hope you are doing good! We wanted to follow up and see if you had a chance to review Stéphane Kapetanovic's reply. Did the information provided answer your question? If you need any further clarification or are still working through the issue, please let us know. We look forward to hearing from you.

Bhavani Sankuratri | Community Manager
0 Likes