<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Re: Menu creation with API in Archicad C++ API</title>
    <link>https://community.graphisoft.com/t5/Archicad-C-API/Menu-creation-with-API/m-p/220493#M3700</link>
    <description>A menu in the API consists of a single title heading up a list of items. It can't contain another heading underneath it. So your intended menu structure could be achieved like this:
&lt;PRE&gt;&lt;I&gt;
&lt;/I&gt;'STR#' 32500	"JHP1 menu" {
/* [   ] */			"JHP"
/* [   ] */ 			"JHP1"
/* [  1] */ 				"JHP1A"
/* [  2] */ 				"JHP1B"
/* [  3] */ 				"JHP1C"
}
'STR#' 32501	"JHP2 menu" {
/* [   ] */			"JHP"
/* [   ] */ 			"JHP2"
/* [  1] */ 				"JHP2A"
}
'STR#' 32502	"JHP3 menu" {
/* [   ] */			"JHP"
/* [   ] */			"JHP3"
/* [  1] */ 				"JHP3A"
/* [  2] */ 				"JHP3B"
}
&lt;/PRE&gt;
Then register each successive menu in the same way as the original 32500, but using the relevant resource ID</description>
    <pubDate>Fri, 03 May 2019 09:09:15 GMT</pubDate>
    <dc:creator>Ralph Wessel</dc:creator>
    <dc:date>2019-05-03T09:09:15Z</dc:date>
    <item>
      <title>Menu creation with API</title>
      <link>https://community.graphisoft.com/t5/Archicad-C-API/Menu-creation-with-API/m-p/220488#M3695</link>
      <description>&lt;DIV class="actalk-migrated-content"&gt;WIN10 Pro | Archicad 22.5009 | VS 2017 with the 2015.3 toolset&lt;BR /&gt;&lt;BR /&gt;I am brand new to Archicad and the API. I am a pretty good Googler, but can't find or don't completely understand... I am trying to add a menu item for our company toolbox. See attached for what I want, what I am able to get, and the code that is making that.&lt;BR /&gt;
&lt;PRE&gt;'STR#' 32500	"Menu strings" {
/* [   ] */			"JHP"
/* [   ] */ 			"JHP1"
/* [  1] */ 				"JHP1A"
/* [  2] */ 				"JHP1B"
/* [  3] */ 				"JHP1C"
/* [   ] */ 			"JHP2"
/* [  1] */ 				"JHP2A"
/* [   ] */			"JHP3"
/* [  1] */ 				"JHP3A"
/* [  2] */ 				"JHP3B"
}
&lt;/PRE&gt;
&lt;BR /&gt;I would use the 2nd level [JHP1A, JHP1B, JHP1C] for executing commands and the 1st level [JHP1, JHP2, JHP3] for headings to organize these commands. I am successful with calling commands in the unorganized solution I have created. I am in search of the proper way to organize the cascading sets of submenus and commands.&lt;BR /&gt;&lt;BR /&gt;I have tried several interpretations of what I see in the documentation and forums without success, including the number between the commented [ ]s, the number of TAB indentations, and indexing the 'STR#' string resource with 32500, 32501, 32502, 32503.&lt;BR /&gt;&lt;BR /&gt;I have found this and suspect it is part of the "don't completely understand..."&lt;BR /&gt;&lt;S&gt;&lt;/S&gt;&lt;A href="http://download.Graphisoft.com/ftp/techsupport/documentation/developer_docs/APIDevKit51/APIHTMLLibrary/Functions/ACAPI_Register_Menu.html" target="_blank"&gt;http://download.Graphisoft.com/ftp/techsupport/documentation/developer_docs/APIDevKit51/APIHTMLLibrary/Functions/ACAPI_Register_Menu.html&lt;/A&gt;&lt;BR /&gt;&lt;BR /&gt;Can someone point me in the right direction?&lt;BR /&gt;&lt;BR /&gt;Please and thank-you...&lt;BR /&gt;Chris&lt;/DIV&gt;</description>
      <pubDate>Wed, 05 Oct 2022 11:28:09 GMT</pubDate>
      <guid>https://community.graphisoft.com/t5/Archicad-C-API/Menu-creation-with-API/m-p/220488#M3695</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2022-10-05T11:28:09Z</dc:date>
    </item>
    <item>
      <title>Re: Menu creation with API</title>
      <link>https://community.graphisoft.com/t5/Archicad-C-API/Menu-creation-with-API/m-p/220489#M3696</link>
      <description>I this case i ussualy do different menu with common root JPH. Keep on mind that you have to register them in main  of your addon.</description>
      <pubDate>Thu, 02 May 2019 19:52:42 GMT</pubDate>
      <guid>https://community.graphisoft.com/t5/Archicad-C-API/Menu-creation-with-API/m-p/220489#M3696</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2019-05-02T19:52:42Z</dc:date>
    </item>
    <item>
      <title>Re: Menu creation with API</title>
      <link>https://community.graphisoft.com/t5/Archicad-C-API/Menu-creation-with-API/m-p/220490#M3697</link>
      <description>Thanks for the quick reply kzaremba.&lt;BR /&gt;
I started with the 'Hello World' example that ships with 22, thinking that most of the internal or behind the scene associations [like RegisterInterface] would be taken care of.  The pre-edit 'Hello World' version worked like a charm.  And thought an edit to the actual 'Menu strings' in the .grc file would be all that is needed to achieve the menu design I was looking for.&lt;BR /&gt;
&lt;BR /&gt;
I have confirmed this...&lt;BR /&gt;

&lt;PRE&gt;&lt;I&gt;
&lt;/I&gt;// -----------------------------------------------------------------------------
// RegisterInterface
//		Interface definitions
// -----------------------------------------------------------------------------

GSErrCode	__ACENV_CALL	RegisterInterface (void)
{
	GSErrCode err = ACAPI_Register_Menu (32500, 32510, MenuCode_UserDef, MenuFlag_Default);
	if (err != NoError)
		ACAPI_WriteReport ("RegisterInterface() ACAPI_Register_Menu failed\n", false);

	return err;
}		// RegisterInterface
&lt;/PRE&gt;

&lt;BR /&gt;
...and 32500, as seen above, is the resource ID used throughout.  According to the last example in the linked documentation in my original post, &lt;I&gt;&lt;/I&gt;&lt;S&gt;&lt;I&gt;&lt;I&gt;&lt;/I&gt;&lt;/I&gt;&lt;/S&gt;"the add-on inserts its own main menu with a submenu; menuPosCode should be MenuCode_UserDef"&lt;E&gt;&lt;/E&gt; and I think I am doing that in the code above.&lt;BR /&gt;
&lt;BR /&gt;
I believe the correct syntax for getting the cascading choices would be all that was required.  But I could be so wrong with that assumption, as well.&lt;BR /&gt;
&lt;BR /&gt;
Thanks for your interest,&lt;BR /&gt;
Chris</description>
      <pubDate>Thu, 02 May 2019 20:33:25 GMT</pubDate>
      <guid>https://community.graphisoft.com/t5/Archicad-C-API/Menu-creation-with-API/m-p/220490#M3697</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2019-05-02T20:33:25Z</dc:date>
    </item>
    <item>
      <title>Re: Menu creation with API</title>
      <link>https://community.graphisoft.com/t5/Archicad-C-API/Menu-creation-with-API/m-p/220491#M3698</link>
      <description>Apparently I am not THAT good of a Googler...&lt;BR /&gt;
&lt;BR /&gt;
&lt;A href="https://archicad-talk.graphisoft.com/viewtopic.php?t=42309" target="_blank"&gt;&lt;/A&gt;&lt;S&gt;&lt;A href="https://archicad-talk.graphisoft.com/viewtopic.php?t=42309" target="_blank"&gt;&lt;/A&gt;&lt;A href="&amp;lt;/s&amp;gt;&amp;lt;LINK_TEXT text=&amp;quot;viewtopic.php?t=42309&amp;quot;&amp;gt;https://archicad-talk.graphisoft.com/viewtopic.php?t=42309&amp;lt;/LINK_TEXT&amp;gt;&amp;lt;e&amp;gt;"&gt;&lt;/A&gt;&lt;/S&gt;&lt;LINK_TEXT text="viewtopic.php?t=42309"&gt;https://archicad-talk.graphisoft.com/viewtopic.php?t=42309&lt;/LINK_TEXT&gt;&lt;E&gt;&lt;/E&gt;&lt;BR /&gt;
&lt;BR /&gt;
I just found this and suspect it will be a step in the right direction.  I think the RegisterInterface and and other behind the scenes workings of these menus will be self explanatory...</description>
      <pubDate>Thu, 02 May 2019 21:19:23 GMT</pubDate>
      <guid>https://community.graphisoft.com/t5/Archicad-C-API/Menu-creation-with-API/m-p/220491#M3698</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2019-05-02T21:19:23Z</dc:date>
    </item>
    <item>
      <title>Re: Menu creation with API</title>
      <link>https://community.graphisoft.com/t5/Archicad-C-API/Menu-creation-with-API/m-p/220492#M3699</link>
      <description>Check any example in API. For example elemettest at the end of main part of addon there is example of registeration seqence that you should follow and also resource file.</description>
      <pubDate>Fri, 03 May 2019 08:54:27 GMT</pubDate>
      <guid>https://community.graphisoft.com/t5/Archicad-C-API/Menu-creation-with-API/m-p/220492#M3699</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2019-05-03T08:54:27Z</dc:date>
    </item>
    <item>
      <title>Re: Menu creation with API</title>
      <link>https://community.graphisoft.com/t5/Archicad-C-API/Menu-creation-with-API/m-p/220493#M3700</link>
      <description>A menu in the API consists of a single title heading up a list of items. It can't contain another heading underneath it. So your intended menu structure could be achieved like this:
&lt;PRE&gt;&lt;I&gt;
&lt;/I&gt;'STR#' 32500	"JHP1 menu" {
/* [   ] */			"JHP"
/* [   ] */ 			"JHP1"
/* [  1] */ 				"JHP1A"
/* [  2] */ 				"JHP1B"
/* [  3] */ 				"JHP1C"
}
'STR#' 32501	"JHP2 menu" {
/* [   ] */			"JHP"
/* [   ] */ 			"JHP2"
/* [  1] */ 				"JHP2A"
}
'STR#' 32502	"JHP3 menu" {
/* [   ] */			"JHP"
/* [   ] */			"JHP3"
/* [  1] */ 				"JHP3A"
/* [  2] */ 				"JHP3B"
}
&lt;/PRE&gt;
Then register each successive menu in the same way as the original 32500, but using the relevant resource ID</description>
      <pubDate>Fri, 03 May 2019 09:09:15 GMT</pubDate>
      <guid>https://community.graphisoft.com/t5/Archicad-C-API/Menu-creation-with-API/m-p/220493#M3700</guid>
      <dc:creator>Ralph Wessel</dc:creator>
      <dc:date>2019-05-03T09:09:15Z</dc:date>
    </item>
    <item>
      <title>Re: Menu creation with API</title>
      <link>https://community.graphisoft.com/t5/Archicad-C-API/Menu-creation-with-API/m-p/220494#M3701</link>
      <description>&lt;BLOCKQUOTE&gt;Ralph wrote:&lt;BR /&gt;A menu in the API consists of a single title heading up a list of items. It can't contain another heading underneath it.&lt;/BLOCKQUOTE&gt;

Ralph's right, you have to create 3 different string table resources for this purpose.&lt;BR /&gt;
&lt;BR /&gt;
So in your GRC file you should write this (as Ralph said):
&lt;PRE&gt;'STR#' 32500	"JHP1 menu" {
/* [   ] */ 		"JHP"
/* [   ] */ 			"JHP1"
/* [  1] */ 				"JHP1A"
/* [  2] */ 				"JHP1B"
/* [  3] */ 				"JHP1C"
}

'STR#' 32501	"JHP2 menu" {
/* [   ] */ 		"JHP"
/* [   ] */ 			"JHP2"
/* [  1] */ 				"JHP2A"
}

'STR#' 32502	"JHP3 menu" {
/* [   ] */ 		"JHP"
/* [   ] */ 			"JHP3"
/* [  1] */ 				"JHP3A"
/* [  2] */ 				"JHP3B"
}&lt;/PRE&gt;

In the C++ code you must register 3 menus in the RegisterInterface function (using MenuCode_UserDef flag) and you can initialize the same callback function for all of your menus in the Initialize function:
&lt;PRE&gt;GSErrCode __ACENV_CALL	RegisterInterface (void)
{
	GSErrCode err = NoError;

	err = ACAPI_Register_Menu (32500, 0, MenuCode_UserDef, MenuFlag_Default);
	err = ACAPI_Register_Menu (32501, 0, MenuCode_UserDef, MenuFlag_Default);
	err = ACAPI_Register_Menu (32502, 0, MenuCode_UserDef, MenuFlag_Default);

	return err;
}

GSErrCode __ACENV_CALL	Initialize (void)
{
	GSErrCode err = NoError;

	err = ACAPI_Install_MenuHandler (32500, MenuCommandHandler);
	err = ACAPI_Install_MenuHandler (32501, MenuCommandHandler);
	err = ACAPI_Install_MenuHandler (32502, MenuCommandHandler);

	return err;
}&lt;/PRE&gt;

Finally your menu command handler function should look something like this:
&lt;PRE&gt;GSErrCode	__ACENV_CALL MenuCommandHandler (const API_MenuParams* params)
{
	switch (params-&amp;gt;menuItemRef.menuResID) {
		case 32500: {
			switch (params-&amp;gt;menuItemRef.itemIndex) {
				case 1:		JHP1A ();		break;
				case 2:		JHP1B ();		break;
				case 3:		JHP1C ();		break;
			}
			break;
		}
		case 32501: {
			switch (params-&amp;gt;menuItemRef.itemIndex) {
				case 1:		JHP2A ();		break;
			}
			break;
		}
		case 32502: {
			switch (params-&amp;gt;menuItemRef.itemIndex) {
				case 1:		JHP3A ();		break;
				case 2:		JHP3B ();		break;
			}
			break;
		}
	}
	return NoError;
}&lt;/PRE&gt;</description>
      <pubDate>Fri, 03 May 2019 18:48:15 GMT</pubDate>
      <guid>https://community.graphisoft.com/t5/Archicad-C-API/Menu-creation-with-API/m-p/220494#M3701</guid>
      <dc:creator>Tibor Lorantfy</dc:creator>
      <dc:date>2019-05-03T18:48:15Z</dc:date>
    </item>
    <item>
      <title>Re: Menu creation with API</title>
      <link>https://community.graphisoft.com/t5/Archicad-C-API/Menu-creation-with-API/m-p/220495#M3702</link>
      <description>That was it!&lt;BR /&gt;
&lt;BR /&gt;
I neglected to make the edits in the Initialize function.  I can't wait until all the moving parts of this become second nature...&lt;BR /&gt;
&lt;BR /&gt;
Thanks for the help guys!&lt;BR /&gt;
&lt;BR /&gt;
Chris</description>
      <pubDate>Mon, 06 May 2019 22:46:51 GMT</pubDate>
      <guid>https://community.graphisoft.com/t5/Archicad-C-API/Menu-creation-with-API/m-p/220495#M3702</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2019-05-06T22:46:51Z</dc:date>
    </item>
    <item>
      <title>Re: Menu creation with API</title>
      <link>https://community.graphisoft.com/t5/Archicad-C-API/Menu-creation-with-API/m-p/220496#M3703</link>
      <description>Although I am still trying to get a handle on passing string arguments to the ShowMessage function, a final working solution is:&lt;BR /&gt;
&lt;BR /&gt;
Thanks to all!&lt;BR /&gt;

&lt;PRE&gt;&lt;I&gt;
&lt;/I&gt;// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
// in the .grc file
// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

/* Text appearing in the menu */

'STR#' 32500	"Menu strings" {
/* [   ] */			"JHP"
/* [   ] */ 			"JHP1"
/* [  1] */ 				"JHP1A"
/* [  2] */ 				"JHP1B"
/* [  3] */ 				"JHP1C"
}

'STR#' 32501	"Menu strings" {
/* [   ] */			"JHP"
/* [   ] */ 			"JHP2"
/* [  1] */ 				"JHP2A"
}

'STR#' 32502	"Menu strings" {
/* [   ] */			"JHP"
/* [   ] */			"JHP3"
/* [  1] */ 				"JHP3A"
/* [  2] */ 				"JHP3B"
}

// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
// in the main.cpp file
// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

// -----------------------------------------------------------------------------
// Command executed by menu choices
// -----------------------------------------------------------------------------
void ShowMessage(char argv[])
{
	MessageBox(0, argv, "Menu choice made is...",  MB_OK);
}

// -----------------------------------------------------------------------------
// Handles menu commands
// -----------------------------------------------------------------------------
GSErrCode __ACENV_CALL MenuCommandHandler(const API_MenuParams *menuParams)
{
	switch (menuParams-&amp;gt;menuItemRef.menuResID) {
		case 32500: {
			switch (menuParams-&amp;gt;menuItemRef.itemIndex) {
			case 1:		ShowMessage("1A");			break;
			case 2:		ShowMessage("1B");			break;
			case 3:		ShowMessage("1C");			break;
			}
			break;
		}
		case 32501: {
			switch (menuParams-&amp;gt;menuItemRef.itemIndex) {
			case 1:		ShowMessage("2A");			break;
			}
			break;
		}
		case 32502: {
			switch (menuParams-&amp;gt;menuItemRef.itemIndex) {
			case 1:		ShowMessage("3A");			break;
			case 2:		ShowMessage("3B");			break;
			}
			break;
		}
	}
	return NoError;
}
// MenuCommandHandler

// -----------------------------------------------------------------------------
// RegisterInterface
//		Interface definitions
// -----------------------------------------------------------------------------
GSErrCode __ACENV_CALL	RegisterInterface(void)
{
	GSErrCode err = NoError;

	err = ACAPI_Register_Menu(32500, 0, MenuCode_UserDef, MenuFlag_Default);
	err = ACAPI_Register_Menu(32501, 0, MenuCode_UserDef, MenuFlag_Default);
	err = ACAPI_Register_Menu(32502, 0, MenuCode_UserDef, MenuFlag_Default);

	return err;
}
// RegisterInterface

// -----------------------------------------------------------------------------
// Initialize
//		Called when the Add-On has been loaded into memory
//		to perform an operation
// -----------------------------------------------------------------------------
GSErrCode __ACENV_CALL	Initialize(void)
{
	GSErrCode err = NoError;

	err = ACAPI_Install_MenuHandler(32500, MenuCommandHandler);
	err = ACAPI_Install_MenuHandler(32501, MenuCommandHandler);
	err = ACAPI_Install_MenuHandler(32502, MenuCommandHandler);

	return err;
}
// Initialize
&lt;/PRE&gt;</description>
      <pubDate>Thu, 09 May 2019 20:50:48 GMT</pubDate>
      <guid>https://community.graphisoft.com/t5/Archicad-C-API/Menu-creation-with-API/m-p/220496#M3703</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2019-05-09T20:50:48Z</dc:date>
    </item>
    <item>
      <title>Re: Menu creation with API</title>
      <link>https://community.graphisoft.com/t5/Archicad-C-API/Menu-creation-with-API/m-p/220497#M3704</link>
      <description>For anyone that stumbles on to this in the future:&lt;BR /&gt;
&lt;BR /&gt;
The only modification I made to Tibor's proposed solution above was to add a 'break;' to the  first level case labels [case 32500:, case 32501:, case 32502:] of the nested switch statements.&lt;BR /&gt;
&lt;BR /&gt;
Easily overlooked, but otherwise a complete and spot on solution.  Thanks Tibor.</description>
      <pubDate>Fri, 10 May 2019 17:35:59 GMT</pubDate>
      <guid>https://community.graphisoft.com/t5/Archicad-C-API/Menu-creation-with-API/m-p/220497#M3704</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2019-05-10T17:35:59Z</dc:date>
    </item>
  </channel>
</rss>

