| API Development Kit Version: 5.1 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
API Migration Guide to ArchiCAD 8 and 8.1Summary: This document discusses the steps every developer should perform to port her/his add-on to ArchiCAD 8 and 8.1.
0. IntroductionIf you already have migrated to ArchiCAD 8, you will not have too much to do. The API interface is source compatible between these two versions, which means you have to re-compile your add-on with this DevKit, and it will run with ArchiCAD 8.1. In order to maintain the correct functionality please pay attention to the New Features and the Known and Fixed Bugs, and adjust your code if it is necessary. If you have not migrated to ArchiCAD 8 yet, then be prepared for a long and adventurous journey through the realms of the API for ArchiCAD 8 and 8.1. We felt it was time for a change. From its first appearance as such in ArchiCAD 6.0, through 6.5 up to the recent 7.0 version the API kept its backward compatibility, so you could get your 6.0 add-on running with 7.0 without any problem. Hey, we even kept the bugs which existed in the past versions, so that you shouldn't change your code... With the arrival of ArchiCAD 8, the vision of a new, more robust, more powerful API emerged. As ArchiCAD itself was cut neatly into many separate modules, so was the API changing. Things disappeared, many new possibilities opened up. This was also the reason why we dropped the idea of binary compatibility in a quite early stage of the development of ArchiCAD 8. We are also sure that many more small modifications will be necessary because of the restructuring of ArchiCAD; we'll try to cover as much as possible by extending this document, and later with additional technical notes. Let's see step-by-step what this means to YOU. 1. Areas of modificationBelow you'll find a short checklist of the issues you may encounter when using the new General API DevKit 4.x. 1.a Resources
1.b Code changes
Some of these changes are a simple matter of replacing the old function names with new ones, whereas some other changes require restructuring or rewriting parts of your code. Other subtle changes are also happening; this document will be extended with those issues when they become relevant to you. 1.c Module changes
2. Changes in detailLet's see these changes in detail. 2.a Add-on configuration
The functionality of the
Instead of one single entry point ( Your add-on also received project event notifications automatically whenever it chose to stay in memory. This is no longer the case; you'll have to register with ACAPI_Notify_CatchProjectEvent to receive these events as well. Installing a notification handler also means that your add-on is kept in memory, without calling ACAPI_KeepInMemory. Example: In the grc file:
In the source file:
2.b ACAPI_String_xxx is dead
These routines have been replaced by the
Beside these the 2.c ACAPI_xxxHandle is deadThis functionality is now available solely through the GSRoot package. In the 2.2 version of the API the use of the BMxxx routines was optional; those who made the transition back at that time spare some time now. The table below shows the old function names and their new equivalents.
Note: MacOS X is much more sensible to memory errors. See the Carbonization Guide for more details. 2.d ACAPI_File_xxx, ACAPI_Folder_xxx, ACAPI_FileDefRec_xxx are dead
The functionality of these functions are now available in the new
Also, the new file and folder dialogs in the DG module work with 2.e Macintosh-specific types and constants removedThe following Macintosh-specific constants and types were removed from the API interface, and were replaced by platform-independent types and constants.
Also, API error codes will be moved to their own namespace. 2.f Selection handling
In previous API versions you had to loop through the selection, retrieve each selected element one by one, then work on it.
In many cases this lead to two loops: in the first you collected the selected elements, then worked on this collection later somewhere else in your code.
Now the API contains an ACAPI_Selection_Get routine, which combines the Don't forget to dispose the allocated GSHandle! GSErrCode ACAPI_Selection_Get (API_SelectionInfo *selectionInfo, API_Neig*** selNeigs, bool onlyEditable); GSErrCode ACAPI_Element_Select (API_Neig **selNeig, long nItem, bool add); 2.g UndoYour add-on is now responsible telling ArchiCAD when and where it would like to perform an undoable step. This also means you'll have to provide a character string that appears in the Edit menu, after "Undo ". The two new functions which mark the beginning and the end of the undoable step are: GSErrCode ACAPI_OpenUndoableSession (const char* undoString); GSErrCode ACAPI_CloseUndoableSession ();
An add-on can only add one undoable step in one session. If you forget to call ACAPI_OpenUndoableSession
before database modifications (e.g. ACAPI_Element_Create, or
ACAPI_Element_Change), those API functions will return One more note about using undo and rebuild: please close the undoable session before you issue any rebuild command; if you do that in reverse order, you'll mess up the drawing update. 2.h Element linking and user data
The format of the APIElement_UserData structure has changed, new fields store the information which you had to set previously in the OWND resource. The limitation on the size of user data (128 bytes in previous API versions)
is completely removed, now the information is stored in a handle. The owner ID will be the same as the module ID, you'll also have to provide version and platform information.
A new function has been introduced, which removes the user data from an element:
So far the most widely used way of linking two elements was to store the unique IDs of the linked elements in every element as user data. The original purpose of introducing element based user data was to store information characteristic to that element, for example heat loss in a certain wall. The user data goes back to its original roots in 8; and the API provides new routines to link elements together. These are: GSErrCode ACAPI_Element_Link (unsigned long unId_linkFrom, unsigned long unId_linkTo, GSFlags linkFlags); GSErrCode ACAPI_Element_Unlink (unsigned long unId_linkFrom, unsigned long unId_linkTo); GSErrCode ACAPI_Element_GetLinks (unsigned long unId_linkFrom, unsigned long ***unId_linkTo, long *nLinks); GSErrCode ACAPI_Element_GetLinkFlags (unsigned long unId_linkFrom, unsigned long unId_linkTo, GSFlags *linkFlags); When two elements are linked together, you'll also have to install an element observer (with a callback function), which is then called whenever the observed element changes. The add-on then retrieves the element(s) linked to the observed element, and updates those elements accordingly. To reduce complexity, the add-on should provide only one single callback function for all observed elements. You can add some custom data to link in last parameter of the ACAPI_Element_Link function, and you can get that information back with ACAPI_Element_GetLinkFlags. 2.i Notifications
The notification mechanism has slightly changed. In 8 you'll have to register callback functions to those events you are interested in.
So instead of the original GSErrCode ACAPI_Notify_CatchProjectEvent (GSFlags eventTypes, APIProjectEventHandlerProc *handlerProc); GSErrCode ACAPI_Notify_CatchToolChange (APIToolChangeHandlerProc *handlerProc); GSErrCode ACAPI_Notify_CatchSelectionChange (APISelectionChangeHandlerProc *handlerProc); GSErrCode ACAPI_Notify_CatchChangeDefaults (const API_ToolBoxItem *elemType, APIDefaultsChangeHandlerProc *handlerProc); GSErrCode ACAPI_Notify_CatchNewElement (const API_ToolBoxItem *elemType, APIElementEventHandlerProc *handlerProc); GSErrCode ACAPI_Notify_InstallElementObserver (APIElementEventHandlerProc *handlerProc);The only new functionality here is the last routine, which switches the working method to an Observer model (see Design Patterns). You don't have to assign any user data or establish a link for a certain element to receive notifications when it is modified/deleted. This handler function will be called when you tell ArchiCAD you would like to monitor changes of a certain element with ACAPI_Element_AttachObserver. A new notification method for custom windows is also introduced, where you also have to provide a callback procedure when you create a new custom window. Notifications on library changes are also posted. 2.j Storing and retrieving preferences
Previously preferences-like data was passed onto your add-on as a parameter of the DoCommand function. As this single entry point vanished in 8, the API provides you two new functions (ACAPI_GetPreferences, ACAPI_SetPreferences) to achieve the same functionality. The GSErrCode ACAPI_SetPreferences (long version, GSSize nByte, const void* data); GSErrCode ACAPI_GetPreferences (long* version, GSSize* nByte, void* data); Example for retrieving the preferences:
Notes:
2.k DimensionsThe internal structure of API_DimElem has changed. 2.l ACAPI_ModelessInit dead
You have to use GSErrCode ACAPI_RegisterModelessWindow (long referenceID, APIPaletteControlCallBackProc* callBackProc, GSFlags controlFlags); GSErrCode ACAPI_UnregisterModelessWindow (long referenceID);
The flags which informed the API when and where you wanted your window appear now became the last parameter of the 2.m (Mac) extra entry points eliminated
On Macintosh, if you wrote your add-on in C++, special shared library entry and termination points were needed, otherwise all static and global
variable constructors and destructors were not called correctly. This code has been moved to the appropriate functions in ACAP_STAT.lib,
so you can remove this part of your code (these functions were usually called 2.n (Mac) CarbonizationIf you haven't done so, you should "carbonize" your add-on, i.e. make it work on MacOS X. The details of this process can be found in a separate Carbonization Guide (downloadable from the developers' web site). 2.o User controlsIn 7.0 you could use the attributes in the server application by simply specifying the appropriate constants in the grc file. This was implemented by using the default callback functions of the server application. These were removed in 8, but to help you we still provide default callbacks in API to set up the user controls with the actual attribute set. Example:
Also, the grc format of user control 257 and 261 has changed, those constants which describe the type, appearance and other characteristics of the popup were modified. Change your GRC file: the general rule for UC 257 is:
Example: Material control in 7.0:0 0 0 0x0704 0x3100becomes material control in 8:0x0004 0x3100 0 More examples:
2.p ACAPI_UseOwnResFile/ACAPI_ResetResFile has been renamed
Both of the functions has been renamed to be more consistent with the new interface.
Also, the type of the return value and the parameters were changed from
2.q Built-in library partsWith the new subtype system, you have a lot more control over library parts coming with your add-on. Actually these can be embedded into the add-on, and ArchiCAD can load the library parts directly from it. The only thing you'll have to do to call ACAPI_Register_BuiltInLibrary. You can also register new subtypes with ACAPI_Register_Subtype. 2.r Changes in elementsTwo new element types were introduced, API_PolyLineType
and API_DetailType, to handle the new elements in ArchiCAD 8. The
polyline data is very similar to that of the The dimension marker for windows and doors became library-part based. This means that form now on you'll have to access the dimension marker's parameters through the well-known API_AddParType structure. The ACAPI_Element_Change function has been turbocharged to handle all element types correctly. 2.s Creating library partsSet the 2.t Converting old format element user data
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Built on August 22, 2003 |