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.
SOLVED!

Switching to section window

OakForest
Participant

I'm using the code in the SDK example and tried to create a section and switch to the newly created section window. The result is that the section is successfully created, but the databaseID of the section cannot be retrieved, making it impossible to assign a value to windInfo.databaseUnId. I am confused. How should I correct the following code?

 

{
/*Here are some ellipsis operations on memo and element ,give enough information to create a section.*/

err = ACAPI_Element_CreateExt(&element, &memo, 1UL, &marker); 
/*Here create the section successfully.*/

ACAPI_DisposeElemMemoHdls(&memo);
ACAPI_DisposeElemMemoHdls(&marker.memo);

API_DatabaseInfo origDB = {};
ACAPI_Database_GetCurrentDatabase(&origDB);
API_DatabaseInfo planDB = {};
planDB.typeID = APIWind_FloorPlanID;
const GSErrCode err2 = ACAPI_Database_ChangeCurrentDatabase(&planDB);
if (err2 != NoError) {
return ;
}

API_WindowInfo windInfo = {};
windInfo.typeID = APIWind_SectionID;
err = ACAPI_Element_Get(&element);
if (err == NoError) {
windInfo.databaseUnId = element.cutPlane.segment.databaseID;
}

if (element.cutPlane.segment.databaseID.elemSetId == APINULLGuid) {
ACAPI_WriteReport("# There is no databaseID in the element. ", true);
}

ACAPI_Database_ChangeCurrentDatabase(&origDB);

ACAPI_Window_ChangeWindow(&windInfo);
return ;
}
1 ACCEPTED SOLUTION

Accepted Solutions
Solution
LChen
Graphisoft
Graphisoft

Hi,

I suppose the problem maybe you didn't finish Undo session before you tried to get section DB ID.
Please try the following code to see whether it solves your problem:

	API_Guid sectGuid;
	GSErrCode err = ACAPI_CallUndoableCommand ("Create Section",
	[&] () -> GSErrCode {
		...
		err = ACAPI_Element_CreateExt(&element, &memo, 1UL, &marker);
		sectGuid = element.header.guid;
	});

	API_Element elemSect{};

	elemSect.header.guid = sectGuid;
	err = ACAPI_Element_Get(&elemSect);

	API_WindowInfo windInfo = {};
	windInfo.typeID = APIWind_SectionID;
	windInfo.databaseUnId = elemSect.cutPlane.segment.databaseID;

	if (elemSect.cutPlane.segment.databaseID.elemSetId == APINULLGuid) {
		ACAPI_WriteReport("# There is no databaseID in the element. ", true);
	}

	ACAPI_Window_ChangeWindow(&windInfo);

HTH

View solution in original post

1 REPLY 1
Solution
LChen
Graphisoft
Graphisoft

Hi,

I suppose the problem maybe you didn't finish Undo session before you tried to get section DB ID.
Please try the following code to see whether it solves your problem:

	API_Guid sectGuid;
	GSErrCode err = ACAPI_CallUndoableCommand ("Create Section",
	[&] () -> GSErrCode {
		...
		err = ACAPI_Element_CreateExt(&element, &memo, 1UL, &marker);
		sectGuid = element.header.guid;
	});

	API_Element elemSect{};

	elemSect.header.guid = sectGuid;
	err = ACAPI_Element_Get(&elemSect);

	API_WindowInfo windInfo = {};
	windInfo.typeID = APIWind_SectionID;
	windInfo.databaseUnId = elemSect.cutPlane.segment.databaseID;

	if (elemSect.cutPlane.segment.databaseID.elemSetId == APINULLGuid) {
		ACAPI_WriteReport("# There is no databaseID in the element. ", true);
	}

	ACAPI_Window_ChangeWindow(&windInfo);

HTH