API Database_control example Error
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
2018-08-25
01:09 AM
- last edited on
2022-11-30
10:45 AM
by
Daniel Kassai
static void Do_ExportWallsToExcel (void) { DBPrintf ("Exporting walls to Excel document...\n"); libxl::Book* book = xlCreateXMLBook (); libxl::Sheet* sheet = book->addSheet (UNISTR_TO_LIBXLSTR (GS::UniString("Walls exported from Archicad"))); libxl::Font* guidFormatFont = book->addFont (); guidFormatFont->setSize (6); guidFormatFont->setColor (libxl::COLOR_GRAY50); libxl::Format* guidFormat = book->addFormat (); guidFormat->setFont (guidFormatFont); GS::Array<GS::UniString> titles; titles.Push ("GUID"); titles.Push ("Height"); titles.Push ("BeginCoordX"); titles.Push ("BeginCoordY"); titles.Push ("EndCoordX"); titles.Push ("EndCoordY"); for (UIndex i = 0; i < titles.GetSize (); ++i) { sheet->writeStr (0, i, UNISTR_TO_LIBXLSTR (titles)); } GS::Array<API_Guid> apiguids; ACAPI_Element_GetElemList (API_WallID, &apiguids); for (UIndex i = 0; i < apiguids.GetSize (); ++i) { GS::Guid gsguid = APIGuid2GSGuid (apiguids); API_Element element = {}; element.header.guid = apiguids; GSErrCode err = ACAPI_Element_Get (&element); if (err != NoError) { DBPrintf ("ACAPI_Element_Get returned error (%d) for GUID '%s'\n", err, gsguid.ToUniString ().ToCStr ().Get ()); continue; } API_WallType& wall = element.wall; //DBPrintf ("GUID '%s'\n", gsguid.ToUniString ().ToCStr ().Get ()); sheet->writeStr (i + 1, 0, UNISTR_TO_LIBXLSTR (gsguid.ToUniString ()), guidFormat); sheet->writeNum (i + 1, 1, wall.height); sheet->writeNum (i + 1, 2, wall.begC.x); sheet->writeNum (i + 1, 3, wall.begC.y); sheet->writeNum (i + 1, 4, wall.endC.x); sheet->writeNum (i + 1, 5, wall.endC.y); } IO::Location location; IO::fileSystem.GetSpecialLocation (IO::FileSystem::UserDocuments, &location); location.AppendToLocal (IO::Name ("export.xlsx")); GS::UniString filepath; location.ToPath (&filepath); DBASSERT (book->save (UNISTR_TO_LIBXLSTR(filepath))); book->release (); DBPrintf ("Export operation finished\n"); }
Solved! Go to Solution.
- Labels:
-
Add-On (C++)
Accepted Solutions

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
2018-08-27 10:56 AM
This example code saves the excel file into the user's documentation folder. Of course you can configure it as you want.
This part of the code gets the documents folder and sets the excel filename to "export.xlsx":
IO::Location location; IO::fileSystem.GetSpecialLocation (IO::FileSystem::UserDocuments, &location); location.AppendToLocal (IO::Name ("export.xlsx"));Don't you find the "export.xlsx" file in you documentation folder after executing this operation?

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
2018-08-27 10:56 AM
This example code saves the excel file into the user's documentation folder. Of course you can configure it as you want.
This part of the code gets the documents folder and sets the excel filename to "export.xlsx":
IO::Location location; IO::fileSystem.GetSpecialLocation (IO::FileSystem::UserDocuments, &location); location.AppendToLocal (IO::Name ("export.xlsx"));Don't you find the "export.xlsx" file in you documentation folder after executing this operation?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
2018-08-28 09:15 AM
DBASSERT (book->save (UNISTR_TO_LIBXLSTR(filepath)));
book->release ();
after
bool aaaa= book->save (UNISTR_TO_LIBXLSTR(filepath))
book->release();
After making the above changes, an Excel file was created in the Documents folder.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
2018-08-28 09:42 AM
park wrote:I'm glad that you solved the issue and you can continue the AddOn development!
DBASSERT (book->save (UNISTR_TO_LIBXLSTR(filepath)));

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
2018-08-28 07:31 PM
Tibor wrote:This is an excellent reason for anyone posting here in the Developer Forum to make clear if they are experimenting with the API using ARCHICAD in Demo mode - or if they have an API license key and are testing in a production license.
Yes, you're absolutely right. The code inside DBASSERT runs only if you built your AddOn using Debug configuration.park wrote:I'm glad that you solved the issue and you can continue the AddOn development!
DBASSERT (book->save (UNISTR_TO_LIBXLSTR(filepath)));
A reminder to all - without a valid developer ID, your add-on can only operate in Demo mode - which has save, print and other features disabled ... including the normal creation of files as seen here. Mr Park's workaround for saving information while in demo mode is an intriguing tip that may help others.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
2018-09-11 12:13 PM


- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
2018-12-01 07:01 AM
park wrote:I get the following errors when the change mentioned is made, any suggestions why?
before
DBASSERT (book->save (UNISTR_TO_LIBXLSTR(filepath)));
book->release ();
after
bool aaaa= book->save (UNISTR_TO_LIBXLSTR(filepath))
book->release();
After making the above changes, an Excel file was created in the Documents folder.
Severity Code Description Project File Line Suppression State
Warning C4189 'aaaa': local variable is initialized but not referenced Database_Control C:\Program Files\GRAPHISOFT\API Development Kit 22.3004\Examples\Database_Control\Src\Database_Control.cpp 1458
Severity Code Description Project File Line Suppression State
Error (active) E0028 expression must have a constant value Database_Control C:\Program Files\GRAPHISOFT\API Development Kit 22.3004\Support\Modules\GSRoot\GSException.hpp 62
Severity Code Description Project File Line Suppression State
Error (active) E0028 expression must have a constant value Database_Control C:\Program Files\GRAPHISOFT\API Development Kit 22.3004\Support\Modules\GSRoot\GSException.hpp 62
Severity Code Description Project File Line Suppression State
Error (active) E0145 member "GS::GSException::AlignOfUniString" may not be initialized Database_Control C:\Program Files\GRAPHISOFT\API Development Kit 22.3004\Support\Modules\GSRoot\GSException.hpp 56
Severity Code Description Project File Line Suppression State
Error (active) E0145 member "GS::GSException::SizeOfUniString" may not be initialized Database_Control C:\Program Files\GRAPHISOFT\API Development Kit 22.3004\Support\Modules\GSRoot\GSException.hpp 57
Severity Code Description Project File Line Suppression State
Error C2220 warning treated as error - no 'object' file generated Database_Control C:\Program Files\GRAPHISOFT\API Development Kit 22.3004\Examples\Database_Control\Src\Database_Control.cpp 1458