The Global ARCHICAD Community

Stay informed. Get help. Share your knowledge.

Discussions about using GRAPHISOFT's tools (API DevKit) for independent software developers

Moderators: Barry Kelly, Karl Ottenstein, LaszloNagy, ejrolon, gkmethy, Tibor Lorántfy, MOREH Tamas, Akos Somorjai, Ed Brown, Mihály Palenik

User avatar
By park ki hyun
#285596
I am practicing database control to practice the addon which outputs element attribute value to excel file in ArchiCAD. (Static void Do_ExportWallsToExcel (void) function )There is problem that it is not saved in the place where Excel file is saved in executable file.
Code: Select all
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[i]));
	}

	GS::Array<API_Guid> apiguids;
	ACAPI_Element_GetElemList (API_WallID, &apiguids);
	for (UIndex i = 0; i < apiguids.GetSize (); ++i) {
		GS::Guid gsguid = APIGuid2GSGuid (apiguids[i]);

		API_Element element = {};
		element.header.guid = apiguids[i];
		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");
}
#285644
Hi,

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":
Code: Select all
	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?
User avatar
By park ki hyun
#285683
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.
#285685
Yes, you're absolutely right. The code inside DBASSERT runs only if you built your AddOn using Debug configuration.
park ki hyun wrote:
Tue Aug 28, 2018 8:15 am
DBASSERT (book->save (UNISTR_TO_LIBXLSTR(filepath)));
I'm glad that you solved the issue and you can continue the AddOn development!
#285711
Tibor Lorántfy wrote:
Tue Aug 28, 2018 8:42 am
Yes, you're absolutely right. The code inside DBASSERT runs only if you built your AddOn using Debug configuration.
park ki hyun wrote:
Tue Aug 28, 2018 8:15 am
DBASSERT (book->save (UNISTR_TO_LIBXLSTR(filepath)));
I'm glad that you solved the issue and you can continue the AddOn development!
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.

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. ;-)
By SajW
#289431
park ki hyun wrote:
Tue Aug 28, 2018 8:15 am
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.
I get the following errors when the change mentioned is made, any suggestions why?

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