We value your input!
Please participate in Archicad 28 Home Screen and Tooltips/Quick Tutorials survey

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

[newbie] how about 'hello world'

Anonymous
Not applicable
When I wrote my introduction to the forum, Karl said
Looking at the PDF link that you posted, I think you're in for some "fun", Tor Jørgen! Welcome!
I'm glad for the welcome, but I worry that maybe I'm in over my head - I guess thats where the fun starts...

I'll just wait with the questions connected with my project and start really simple;

- in most of the languages I've looked at, there's always an example of how to write the simple 'hello world'-snippet. How do I do that in an addon?
- and then how does the real workprocess go, I'm thinking of debugging and setting breakpoints and beeing able to step through the code to see what happens where, and why... and how is the interaction with ArchiCAD?

--
Regards,
Tor Jørgen
41 REPLIES 41
Anonymous
Not applicable
Thanks for all the answers, and special thanx to stefan for his step-by-step guide

I'll work through it and see if it works the same way on the mac.

I think one of the problems is really to recognize what goes where. I mean several of the examples have, in additions to the specific addon.cpp-file, several other files like CIOStub.cpp. Those starting with APISomething I guess I shouldn't bother with, but what is the logic to what goes where, or the recommendation?

And then I wonder, an addon must include CheckEnvironment(), RegisterInterface(), Initialize() and FreeData(). But then I read about the inout module, and it said that initialization and uninitialization of Location must happen inside the main() - where do I put that, and are there more things that happen in a predefined order than the beforemensioned functions? Maybe its all to be found in the documentation, but I have been reading a lot of it, and things kind of blur...

I'm thinking of how to expand 'hello world' to explain other functions, would it be possible to read the message from a file, and log that it has been done to another file? Would it be possible to have the 'hello' appear on the plan as a textblock or maybe written by walls? - or have a pallette show up that you have to click to get the greeting?

Is it possible to interact with the database through a webbrowser using sql and a service on a webserver?

--
Regards,
Tor Jørgen
Ralph Wessel
Mentor
Tor wrote:
I'll work through it and see if it works the same way on the mac.
The process is largely the same on the Mac - the biggest differences boil down to the IDEs (CodeWarrior vs VC++). However, compiling the .grc files is much easier on the Mac. Make sure the GRC compiler and preference panels are installed in the relevant CodeWarrior plugin folders. With these installed, CodeWarrior will automatically compile the .grc files with the same simplicity as the .c/.cpp/.r files.
Tor wrote:
I think one of the problems is really to recognize what goes where. I mean several of the examples have, in additions to the specific addon.cpp-file, several other files like CIOStub.cpp. Those starting with APISomething I guess I shouldn't bother with, but what is the logic to what goes where, or the recommendation?
If you start with the example projects, you won't have to worry about this to start with. All the examples include CodeWarrior project files (.mwp), so you can be up and running quickly. As others have mentioned, you need to fill in your MDID resources to ensure the add-on will be loaded by ArchiCAD.

Files included in the project like "ACAP_STAT.lib", "DGImp.lib", etc. are library files which directly or indirectly link the functionality of the ArchiCAD API into your add-on.

You will also see CarbonLib, which is linking your add-on to Mac OS functionality. And finally, there should be C/C++ runtime libraries. I use the MSL libraries, but there is a subtle trap here. ArchiCAD add-ons must have a special compiler option set - Enums always Int - which automatically sets the size of all enumerator values to 2 bytes. Data structures in the API must be compiled this way in order for your add-on to calculate the offsets and length of the binary data in the same way as ArchiCAD. However, the standard C/C++ libraries provided with CodeWarrior have not been compiled with this option set by default, so you must build alternate versions of the libraries to use with the ArchiCAD API. If you don't, it can result in some dreadful internal inconsistencies. Let me know if you don't know how to rebuild the MSL libraries.
Tor wrote:
And then I wonder, an addon must include CheckEnvironment(), RegisterInterface(), Initialize() and FreeData(). But then I read about the inout module, and it said that initialization and uninitialization of Location must happen inside the main() - where do I put that, and are there more things that happen in a predefined order than the beforemensioned functions?
Again, use the example projects as your guide. They will no doubt demonstrate most of the functionality you intend to use. Most of the initialisation is concerned with informing ArchiCAD of the services and requirements of your add-on.
Tor wrote:
Is it possible to interact with the database through a webbrowser using sql and a service on a webserver?
To an extent, you can interact with external services by whatever protocol you wish. For example, the GBS Energy add-on we developed for GeoPraxis interacts with their server via SOAP calls. The primary limitation is that your add-on must instigate all the communication - ArchiCAD will not invoke your add-on at the request of an external service.
Ralph Wessel BArch
Software Engineer Speckle Systems
stefan
Advisor
vannassen wrote:
Thanks for all the answers, and special thanx to stefan for his step-by-step guide

I'll work through it and see if it works the same way on the mac. [...]
--
Regards,
Tor Jørgen
Don't forget to mail the differences back to this thread. That way, it can be a reference for others.

I am still hoping that some more experienced developers can take a quick peak at the step-by-step and see it there are things that are done completely wrong (or at least, that should have been done in a different way). They are not wrong enough to not get it working 😉
--- stefan boeykens --- bim-expert-architect-engineer-musician ---
Archicad28/Revit2024/Rhino8/Solibri/Zoom
MBP2023:14"M2MAX/Sequoia+Win11
Archicad-user since 1998
my Archicad Book
Anonymous
Not applicable
I've followed Stefans guide and done the following:

I've started from scratch using the IDE of CodeWarrior which resulted in the standard framework with sourcefiles, libraries and stuff, and I've copied my ID's to the .grc-file under the MDID section.

In the RegisterInterface() I've included this line
GSErrCode errorCode = ACAPI_Register_Menu (32500, 32520, MenuCode_Tools, MenuFlag_Default);
In the Initialize() I've included this line
GSErrCode errorCode = ACAPI_Install_MenuHandler (32500, CommandHandler);
Then I've copied the CommandHandler-function from Stefans code
GSErrCode __ACENV_CALL	CommandHandler (const API_MenuParams * /*params*/)
{
	ACAPI_WriteReport ("Hello World", true);
	return NoError;
}		// CommandHandler ()
It compiled without trouble but when I registered it in ArchiCAD nothing showed up...

Then I included these lines in the .grc file
'STR#' 32500 "Menu strings" {
/*[ 1] */			"Hello World"
}

'STR#' 32501 "Strings for the Menu" {
/* [  1] */			"Hello World"
}
I've now got a menu, but when I click it nothing shows up...
What's missing?
--
Regards,
Tor Jørgen
stefan
Advisor
vannassen wrote:
Then I included these lines in the .grc file
'STR#' 32500 "Menu strings" {
/*[ 1] */			"Hello World"
}

'STR#' 32501 "Strings for the Menu" {
/* [  1] */			"Hello World"
}
I've now got a menu, but when I click it nothing shows up...
What's missing?
--
Regards,
Tor Jørgen
Try to replace 32501 with 32520 in the second STR-resource.

And try to unload and remove your add-on, close the Add-On Manager. Re-open it and reload it. And if possible, try to modify the settings for the Add-on so it's placed in the Extra-menu and not the Tools-menu. That way, you're absolutely sure that the meny will be generated all over again.

When changing menu's, I had it happen a few times that the menu in ArchiCAD was not changing, although I had the impression that the code was modified.
--- stefan boeykens --- bim-expert-architect-engineer-musician ---
Archicad28/Revit2024/Rhino8/Solibri/Zoom
MBP2023:14"M2MAX/Sequoia+Win11
Archicad-user since 1998
my Archicad Book
Anonymous
Not applicable
I should have looked up the ACAPI_WriteReport function a little bit earlier - it writes to the reportwindow which I didn't view...
It has been working for a while...
I took away the 32520 string in the resouce, can't see that it did anything.

But the main thing is: I've got the 'Hello World' up and running thanx to you!
--
Regards,
Tor Jørgen
stefan
Advisor
ACAPI_WriteReport("Hello World", true) should also display a message box.
--- stefan boeykens --- bim-expert-architect-engineer-musician ---
Archicad28/Revit2024/Rhino8/Solibri/Zoom
MBP2023:14"M2MAX/Sequoia+Win11
Archicad-user since 1998
my Archicad Book
Anonymous
Not applicable
I've tried both true and false, but it behaves the same.
Wonder why...
--
Regards,
Tor Jørgen
Anonymous
Not applicable
Something add
A personal icona in menu

'STR#' 32500 "Menu strings" {
/* [  1] */		"Test ^32500"
}
.......

'GBMP'	32500	"Testico" {
	"Testico"
}
Icon is Testico.bmp 16x16
I am added to the \RFIX\images according to instruction, it malfunction
after added to the \Debug already compiled errorless
Akos Somorjai
Graphisoft
Graphisoft
vannassen wrote:
I've tried both true and false, but it behaves the same.
Wonder why...
--
Regards,
Tor Jørgen
The behavior of ACAPI_WriteReport depends on the "Write Report" switch in Imaging and Calculation preferences. If that one is off, then the dialog won't appear even if you pass true in the second parameter. If you want an alert box which appears in every case, use DGAlert, DGResAlert, or DGResAlertParam.

Good luck,

Akos