cancel
Showing results for 
Search instead for 
Did you mean: 
cancel
Showing results for 
Search instead for 
Did you mean: 
Archicad C++ API
About Archicad add-on development using the C++ API.

Delete Elevations get error!

Newbie
Participant

I am try to delete Elevation element using below code but always get error saying "The command cannot be executed with the passed parameters." with error code -2130312311.

 

GS::Array<API_DatabaseUnId> dbases;
GSErrCode err = ACAPI_Database(APIDb_GetElevationDatabasesID, nullptr, &dbases);
if (err == NoError) {
for (const auto& dbUnId : dbases) {
API_DatabaseInfo dbPars = {};
BNZeroMemory(&dbPars, sizeof(API_DatabaseInfo));
dbPars.databaseUnId = dbUnId;
GSErrCode err2 = ACAPI_Database(APIDb_GetDatabaseInfoID, &dbPars, nullptr);
if (err2 == NoError && dbPars.typeID == APIWind_ElevationID) {
GSErrCode err3 = ACAPI_Database(APIDb_DeleteDatabaseID, &dbPars, nullptr);
if (err3 != NoError) {
ACAPI_WriteReport("Remove Elevation Error >> %d", true, err3);
}
}
}
}

 

Is there anyone could suggest how to fix?

6 REPLIES 6

Did you already try deleting the Elevation marker with ACAPI_Element_Delete?

I've just tested it, and that works and also removes the elevation itself.
Don't forget to put it in an undo scope.

Automating Archicad with Add-Ons, GDL-Objects & Python Archi-XT.com
Newbie
Participant

Hello bschwb,

 

Thanks for your suggestion. Anyway, how to get Elevation marker list as per mentioned above?.

I have try with dbPars.databaseUnId.elemSetId from above code but still no luck.

 

You have to options to get the list of elevation markers:

  1. Use ACAPI_Element_GetElemList
  2. Use the linkedElement of an Elevation Database

Sample Codes

Sample code for Option 1:

ACAPI_CallUndoableCommand ("Remove All Elevations 1", []() -> GSErrCode {
	GSErrCode err = NoError;

	GS::Array<API_Guid> elevationMarkers{};
	err = ACAPI_Element_GetElemList (API_ElevationID, &elevationMarkers);
	if (err != NoError) { return err; }

	err = ACAPI_Element_Delete (elevationMarkers);
	return err;
});

 
Sample code for Option 2 (adapted from your previously posted code):

ACAPI_CallUndoableCommand ("Remove All Elevations 2", []() -> GSErrCode {
	GS::Array<API_DatabaseUnId> dbases;
	GSErrCode err = ACAPI_Database (APIDb_GetElevationDatabasesID, nullptr, &dbases);
	if (err == NoError) {
		for (const auto& dbUnId : dbases) {
			API_DatabaseInfo dbPars = {};
			BNZeroMemory (&dbPars, sizeof (API_DatabaseInfo));
			dbPars.databaseUnId = dbUnId;
			GSErrCode err2 = ACAPI_Database (APIDb_GetDatabaseInfoID, &dbPars, nullptr);
			if (err2 == NoError && dbPars.typeID == APIWind_ElevationID) {
				GSErrCode err3 = ACAPI_Element_Delete ({ dbPars.linkedElement });
				if (err3 != NoError) {
					ACAPI_WriteReport ("Remove Elevation Error >> %d", true, err3);
				}
			}
		}
	}

	return NoError;
});


Hope that helps,

Bernd

Automating Archicad with Add-Ons, GDL-Objects & Python Archi-XT.com

Hello Bernd,

 

Thanks a lot for your clearly suggestion. I will make a test on it.

BTW, I am not sure whether it could be use with Sections part or not.

 

Both solutions also work for sections.

 

  • Option 1: Use API_CutPlaneID
  • Option 2: Use APIDb_GetSectionDatabasesID and APIWind_SectionID
Automating Archicad with Add-Ons, GDL-Objects & Python Archi-XT.com
Joel Buehler
Enthusiast

i never worked with the ACAPI_Database, but are you sure you dont need to put those API Calls not in a ACAPI_CallUndoableCommand method? 

 

edit: oops, did not see your post. sorry 😄