cancel
Showing results for 
Search instead for 
Did you mean: 
cancel
Showing results for 
Search instead for 
Did you mean: 
Archicad C++ API
About Archicad add-on development using the C++ API.

Adding Icons to Sub‑Menu Items and Changing Them Dynamically

Corpora Geometrica
Participant

I have two questions about handling menu items through the Archicad API.

 

1. Icons for sub‑menu items
Is it possible to associate an icon with the "Sub-menu Item" provided in the following GRC file snippet?

'STR#' ID_ADDON_MENU "Add-On Menu Strings" {
/* [  ] */ "Main Menu Item"
/* [  ] */ "Sub-menu Item"
/* [ 1] */     "First Command Menu Item^E3^ES^EE^EI^ED^ET^10002"
/* [ 2] */     "Second Command Menu Item^E3^ES^EE^EI^ED^ET^10003"
}​

'STR#' ID_ADDON_MENU_PROMPT "Add-On Menu Strings" {
/* [  ] */ "Main Menu Item"
/* [  ] */ "Sub-menu Item"
/* [ 1] */     "First Command Menu Item"
/* [ 2] */     "Second Command Menu Item"
}​

Writing something like "Sub-menu Item^10001" (or using other escape sequences) has no effect during menu registration, at runtime the menu label simply shows the escape codes as plain text:

GSErrCode __ACDLL_CALL RegisterInterface (void)
{
	GSErrCode err = ACAPI_MenuItem_RegisterMenu (ID_ADDON_MENU, ID_ADDON_MENU_PROMPT, MenuCode_UserDef, MenuFlag_Default);

	return err;
}​

I noticed that Archicad itself shows sub-menu items with icons at the same nesting level as mine (even for other add-ons), but I cannot reproduce this through the API. Are those icons assigned internally?

 

2. Changing icons dynamically 

Is there a way to change dynamically the icons associated with the sub or at least with the command menu items at runtime?

11 REPLIES 11
  1. Your method for adding icons to menus in grc files looks ok to me - are the icon resources also present in the add-on, i.e. do you describe these icons in a grc file too? Certainly this is possible.
  2. I don't know of a function to change the icon. There are methods to set a menu item as ticked or disabled, or to change the text.
Ralph Wessel BArch
Central Innovation

First of all, thank you very much for taking the time and effort to look into my question — I really appreciate your support.


Yes — the icons are explicitly described in the Sources/AddOnResources/RFIX/AddOnFix.grc file. For example:

#include "ResourceIDs.hpp"

'MDID' 32500 "Add-On Identifier" {
    MDID_DEVELOPER_ID
    MDID_PRODUCT_ID
}

'GICN' 10001 "SubMenuItemIcon" {
    "SubMenuItemIcon"
}

'GICN' 10002 "FirstCommandMenuItemIcon" {
    "FirstCommandMenuItemIcon"
}

'GICN' 10003 "SecondCommandMenuItemIcon" {
    "SecondCommandMenuItemIcon"
}

The string identifiers ("SubMenuItemIcon", "FirstCommandMenuItemIcon", and "SecondCommandMenuItemIcon") correspond directly to the SVG filenames stored in Sources/AddOnResources/RFIX/Images:

  • SubMenuItemIcon_18x18.svg

  • FirstCommandMenuItemIcon_18x18.svg

  • SecondCommandMenuItemIcon_18x18.svg

Here, the suffix (_18x18) defines the base size of the icon.

 

During the successful build process, these SVGs are automatically converted into multiple rasterized formats, which can be located under Make/Build.Win.x64.28.0.0.INT/AddOnResourceObjects:

  • SubMenuItemIcon.png

  • SubMenuItemIcon&96.ico

  • SubMenuItemIcon&192.ico

  • SubMenuItemIcon@2.00x.png

(and similar file sets for FirstCommandMenuItemIcon and SecondCommandMenuItemIcon).

 

In addition, the intermediate and compiled resource files — AddOnFix.grc.i and AddOnResourceObjects.res — are also generated correctly as part of the build, confirming that the resource pipeline is working end‑to‑end.

 

One detail I have noticed: if I use the escape sequence ^10001 for the command menu items, the corresponding icon appears as expected. However, at the sub‑menu item level the same approach does not display the icon. At runtime, the sub-menu item label simply shows the escape codes as plain text: Sub-menu Item^10001. This suggests that while the resource is correctly defined and built, the sub‑menu items may not support icon references in the same way as command menu items.

 

So yes — all icons are declared in the .grc file and provided as SVG resources, with the build system generating the required PNG/ICO variants automatically.

 

Looks like this is a Windows project. If so, have you defined a .rc file for the add-on resources? And does that include the output from converting the images?

For example, if I define images in a file called "AddonImagesFix.grc", this results in an output file called "AddonImagesFix.ro" from the resource conversion. I then include that in the Addon.rc file like this:

#include "AddonImagesFix.ro"
Ralph Wessel BArch
Central Innovation

Yes, this is indeed a Windows project. I also have a folder at: Sources/AddOnResources/RFIX.win, which contains an AddOn.rc2 file with the following content:

#include "AddOn.grc.rc2"
#include "AddOnFix.grc.rc2"

1   ICON    LOADONCALL MOVEABLE IMPURE  ACAP.ico

 

Both AddOn.grc.rc2 and AddOnFix.grc.rc2 exist and are generated in the build output under: Make\Build.Win.x64.28.0.0.INT\AddOnResourceObjects, where the AddOnFix.grc.rc2 file includes valid references to the icons. For example:

I10001&96   ICON "SubMenuItemIcon&96.ico"
I10001&192  ICON "SubMenuItemIcon&192.ico"

 

So, the resource conversion step is producing the expected .rc2 files, and they are properly included in the project’s resource script.

 

If instead of the original .grc file I use the following simplified variant — where the sub‑menu item is treated as a single command menu item and no additional command menu items are declared:

'STR#' ID_ADDON_MENU "Add-On Menu Strings" {
/* [  ] */ "Main Menu Item"
/* [  ] */ "Sub-menu Item^E3^ES^EE^EI^ED^ET^10001"
}

the expected icon is displayed correctly.

 

The issue arises as soon as I introduce grouped command menu items under the sub-menu item (i.e., when the submenu points with a right arrow to its child items). In that case, instead of rendering the icon, the label itself is shown as plain text, including all the escape sequences, for example: Sub-menu Item^E3^ES^EE^EI^ED^ET^10001.

 

Hi,

 

I've also tried this a while ago (~3 years ago from my notes) and found the same restriction as you did. I vaguely remember that I even found the restriction documented but couldn't find anything about it again. So it might not actually be documented anywhere.

 

Hope that helps,

Bernd

Automating Archicad with Add-Ons, GDL-Objects & Python Archi-XT.com

Sorry, I misread your original question. You want an icon associated with the child menu within the parent menu. I've never tried to do this. Your resources etc all look fine so I can only assume that this isn't supported.

Ralph Wessel BArch
Central Innovation
Akos Somorjai
Graphisoft
Graphisoft

Hi,

 

I've just trid it on macOS with the Archicad 29 SDK, and it works for me.

I added the MoreOptions_16x16.svg icon from DG_Test to the Interface_Functions/RFIX/Images folder, then modified the Interface_FunctionsFix.grc resource:

 

'GICN' 32222 "More options" {
"MoreOptions"
}
 
'STR#' 32501 "Strings for the Menu" {
/* [ ] */ "Test"
/* [ ] */ "Interface Functions (AutoState)"
/* [ 1] */ "2D, 3D, Section, Elevation, Interior Elevation^ES^EE^EI^E3^32222"
...
 
After building the add-on, the icon appeared in the menu:
 
Add-on submenu with icon.png

 

Could you please check this?

 

Best, Akos

Hi Ákos,

 

Thank you for your reply.

 

This setup works for me as well (I tried to outline a very similar configuration earlier). However, in the example you described, I would like to assign an icon not to the "2D, 3D, Section, Elevation, Interior Elevation" command menu item, but to its parent sub-menu item: "Interface Functions (AutoState)".

 

There are also precedents for this in the factory Archicad setup. For instance, take a look at "Design/Connect/Triming bodies", or "Files/Interoperability/IFC/IFC Project Manager"... — in these cases, the bolded menu items already have icons assigned to them. I assume that the icon associated with the Connect menu item is handled internally, whereas the icon assigned to IFC should be coming from an add‑on.

Thanks for clarifying — that matches what I suspected as well. I am still hoping someone might know of a workaround or undocumented option, so any further insights would be much appreciated.

Didn't find the answer?

Check other topics in this Forum

Back to Forum

Read the latest accepted solutions!

Accepted Solutions

Start a new conversation!