Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Resolving API name/type changes in different versions #33

Closed
camnewnham opened this issue Apr 10, 2024 · 2 comments
Closed

Resolving API name/type changes in different versions #33

camnewnham opened this issue Apr 10, 2024 · 2 comments

Comments

@camnewnham
Copy link

camnewnham commented Apr 10, 2024

Hello! Thanks for this template. It's been very useful to get started on a plugin.

I started with this template, then have copied in most of the BrowserControl example. I noticed when doing this that the builds started failing for Archicad 25 and 26. This appears to be for a few reasons, but all of them seem to be namespace or function name changes.

For example, ACAPI_Register_Menu in AC26 vs. ACAPI_MenuItem_RegisterMenu in AC27.
Similarly, the JS object classes were formerly DG::JSValue and are now JS::Value.

I am relatively new to C++. Is there a technique for using different names based on AC version? It would be convenient to be able to target multiple out of one project.

Coming from C# the equivalent would be:

#if ARCHICAD_26
using JSValue = DG.JSValue;
#else
using JSValue = JS.Value
#endif

Edit: Looking at this again it seems like quite a bit of work to manage multiple versions as the API seems to have changed a reasonable amount (at least by naming convention) between AC26 and AC27

@camnewnham
Copy link
Author

I've worked around this by adding the following to CMakeLists.txt

if (DEFINED ADDITIONAL_COMPILE_DEFINITIONS)
	add_compile_definitions(${ADDITIONAL_COMPILE_DEFINITIONS})
endif()

Subsequently if using the python build tools, it can be used in the following way:
python Tools/BuildAddOn.py --configFile config.json --acVersion 27 --additionalCMakeParams ADDITIONAL_COMPILE_DEFINITIONS='PLUGIN_VERSION="1.2.3.4";ARCHICAD_27'

And then in code as

#if ARCHICAD_27
...
#endif

@vhorvath-gs
Copy link
Contributor

vhorvath-gs commented Jan 23, 2025

Sorry for the late reply.

We cannot at the moment provide source level compatibility between API versions. We have things in the API that in retrospect shouldn't have been exposed, so we are slowly cleaning up the API.

One recommendation or best practice here would be to create a wrapper around required parts of the API in a way that decouples your addon logic from the API or at least makes the addon logic not tightly coupled to the API.

To detect the API version in the addon source, you may set the appropriate definition and compile conditionally using that:

# In CMakeLists.txt
GenerateAddOnProject (CMakeTarget ...)
target_compile_definitions (CMakeTarget PRIVATE "ARCHICAD_API=${AC_VERSION}")
/* In a C++ file */
#if ARCHICAD_API == 24
// Code for only Archicad 24
#elif ARCHICAD_API == 25 || ARCHICAD_API == 26
// Code for Archicad 25 and 26
#elif ARCHICAD_API == 27
// Code for only Archicad 27
#endif

Once a new Archicad version's Release Candidate is made available, you will also have a new devkit that you can use to port your addon if necessary.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants