BIM Coordinator Program (INT) April 22, 2024
Find the next step in your career as a Graphisoft Certified BIM Coordinator!
Archicad C++ API
About Archicad add-on development using the C++ API.

Create and change database to newly created db

Miha Nahtigal
Advocate
When I try to switch current database to newly created worksheet, I get APIERR_BADDATABASE (The command cannot be executed on the current database). The worksheet is sucessfully created but changing database fails. What am I doing wrong here??

	GSErrCode					err;    
	API_DatabaseInfo			dbInfo;

	BNZeroMemory (&dbInfo, sizeof (API_DatabaseInfo));

	dbInfo.typeID = APIWind_WorksheetID;
	CHANSI2Unicode ("Det 1", (GS::Int32)strlen("Det 1"), dbInfo.name, API_UniLongNameLen);
	CHANSI2Unicode ("D10", (GS::Int32)strlen("D10"), dbInfo.ref, API_UniLongNameLen);

	if (ACAPI_Database (APIDb_NewDatabaseID, &dbInfo, NULL) == NoError) {
		err = ACAPI_Database (APIDb_ChangeCurrentDatabaseID, &dbInfo, NULL);
	}
BIMquants.comBETA - Quantities and Costs Estimation with Archicad AddOn :: rushing to publish a beta preview
3 REPLIES 3
Oleg
Expert
You need to open the window this database after creation, before the database using.
( I dont check it in last APIs, may be it changed ).

ACAPI_Automate( APIDo_ChangeWindowID, &m_db, NULL );
Miha Nahtigal
Advocate
Works! Thanks Oleg.
BIMquants.comBETA - Quantities and Costs Estimation with Archicad AddOn :: rushing to publish a beta preview
Akos Somorjai
Graphisoft
Graphisoft
vuego wrote:

	CHANSI2Unicode ("Det 1", (GS::Int32)strlen("Det 1"), dbInfo.name, API_UniLongNameLen);
	CHANSI2Unicode ("D10", (GS::Int32)strlen("D10"), dbInfo.ref, API_UniLongNameLen);

This can be simplified to:

	GS::ucscpy (dbInfo.name, L("Det 1"));
	GS::ucscpy (dbInfo.ref, L("D10"));
Best, Ákos
Learn and get certified!