Archicad C++ API
About Archicad add-on development using the C++ API.
SOLVED!

Add-On Template

poco2013
Mentor
The Xcode Add On Template is great to get started but lacks the menu 'hook-up' necessary to start a project. This kind of defeats the propose of a quick start template.

Would like to see a template that includes a simple test menu with say one item/function and the standard 'Hello World' WriteReport message.

Are there any instruction available as how to create my own template in xcode to do this?
Gerry

Windows 11 - Visual Studio 2022; ArchiCAD 27
1 ACCEPTED SOLUTION

Accepted Solutions
Solution
Akos Somorjai
Graphisoft
Graphisoft
Hai wrote:
Hi Ralph,
Thank you so much but I'm a beginner and sorry I don't understand where menu handler is.
So, in your RegisterInterface() function:

GSErrCode	__ACENV_CALL	RegisterInterface (void)
{
	ACAPI_Register_Menu (32500, 0, MenuCode_UserDef, MenuFlag_Default);

	return NoError;
}		// RegisterInterface
Here 32500 is the ID of the string resource that appears in the menu; add this to the .grc file:

'STR#' 32500 "Strings for the Menu" {
/* [  1] */  "Hello world"
}
Then in your Initialize() function add the following:

GSErrCode __ACENV_CALL	Initialize (void)
{
    GSErrCode err = ACAPI_Install_MenuHandler (32500, MenuCommandHandler);
    // other stuff
}
Last, in your MenuCommandHandler function call Do_CreateHelloWord():

GSErrCode	__ACENV_CALL	MenuCommandHandler (const API_MenuParams *params)
{
    if (params->menuItemRef.itemIndex == 1) {
        Do_CreateHelloWord ();
    }
}

View solution in original post

8 REPLIES 8
Anonymous
Not applicable
It would be good to have one for Visual Studio as well. So you can start project instantly on custom path.
Anonymous
Not applicable
kzaremba wrote:
It would be good to have one for Visual Studio as well. So you can start project instantly on custom path.
I'm using VS 2017 but I don't know how to start with Hello World Blog. How can I use that code and necessary resource to get Hello World in AC. Could you show me how to do it step by step? Thanks for your kind.
Ralph Wessel
Mentor
I suggest copying one of the example projects with a single menu item, e.g. AddOnObject_Manager and replace the code in the menu handler:
// -----------------------------------------------------------------------------
// DoCommand
//		called to perform the user-asked command
// -----------------------------------------------------------------------------

GSErrCode	__ACENV_CALL	MenuCommandHandler (const API_MenuParams *params)
{
	if (params->menuItemRef.itemIndex == 1) {
		//Your code here
	}

	return NoError;
}		// MenuCommandHandler
Ralph Wessel BArch
Anonymous
Not applicable
Hi Ralph,
Thank you so much but I'm a beginner and sorry I don't understand where menu handler is.
Ralph Wessel
Mentor
Hai wrote:
Thank you so much but I'm a beginner and sorry I don't understand where menu handler is.
Search the project for MenuCommandHandler. For that particular project, it's in the file AddOnObject_Manager.cpp
Ralph Wessel BArch
Solution
Akos Somorjai
Graphisoft
Graphisoft
Hai wrote:
Hi Ralph,
Thank you so much but I'm a beginner and sorry I don't understand where menu handler is.
So, in your RegisterInterface() function:

GSErrCode	__ACENV_CALL	RegisterInterface (void)
{
	ACAPI_Register_Menu (32500, 0, MenuCode_UserDef, MenuFlag_Default);

	return NoError;
}		// RegisterInterface
Here 32500 is the ID of the string resource that appears in the menu; add this to the .grc file:

'STR#' 32500 "Strings for the Menu" {
/* [  1] */  "Hello world"
}
Then in your Initialize() function add the following:

GSErrCode __ACENV_CALL	Initialize (void)
{
    GSErrCode err = ACAPI_Install_MenuHandler (32500, MenuCommandHandler);
    // other stuff
}
Last, in your MenuCommandHandler function call Do_CreateHelloWord():

GSErrCode	__ACENV_CALL	MenuCommandHandler (const API_MenuParams *params)
{
    if (params->menuItemRef.itemIndex == 1) {
        Do_CreateHelloWord ();
    }
}
Anonymous
Not applicable
Ralph wrote:
Search the project for MenuCommandHandler. For that particular project, it's in the file AddOnObject_Manager.cpp
Thank you very much. I will learn it and reply for result as soon.
Anonymous
Not applicable
Hi Akos,
Thank you very much for the detailed guide for me. It's very helpful for the beginner like me.

P/S: Thanks for Ralph, I can build more example without any errors and maybe I knew how API work and folder structure. Thank so much for supporting. I will do something by myself ^.^