We value your input! Please participate in Archicad 28 Home Screen and Tooltips/Quick Tutorials survey
2023-07-09 07:53 AM - last edited on 2023-07-12 05:25 AM by Laszlo Nagy
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?
2023-07-09 09:15 AM
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.
2023-07-09 11:46 AM
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.
2023-07-09 12:15 PM
You have to options to get the list of elevation markers:
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
2023-07-10 05:13 AM
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.
2023-07-10 08:34 AM
Both solutions also work for sections.
2023-07-10 04:48 PM - edited 2023-07-10 04:49 PM
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 😄