Archicad C++ API
About Archicad add-on development using the C++ API.
SOLVED!

Get information of current selection

SajW
Participant
How can I get the 'guids' of the current selection (multiple element types) ?
Can I use ACAPI_Element_GetElemList ?
1 ACCEPTED SOLUTION

Accepted Solutions
Solution
Tibor Lorantfy
Graphisoft Alumni
Graphisoft Alumni
You can use ACAPI_Selection_Get to get the current selection:
static GS::Array<API_Guid>	GetSelectedElements (bool assertIfNoSel /* = true*/, bool onlyEditable /*= true*/)
{
	GSErrCode            err;
	API_SelectionInfo    selectionInfo;
	API_Neig             **selNeigs;

	err = ACAPI_Selection_Get (&selectionInfo, &selNeigs, onlyEditable);
	BMKillHandle ((GSHandle *)&selectionInfo.marquee.coords);
	if (err == APIERR_NOSEL || selectionInfo.typeID == API_SelEmpty) {
		if (assertIfNoSel) {
			DGAlert (DG_ERROR, "Error", "Please select an element!", "", "Ok");
		}
	}

	if (err != NoError) {
		BMKillHandle ((GSHandle *)&selNeigs);
		return GS::Array<API_Guid>();
	}

	UInt32 nSel = BMGetHandleSize ((GSHandle)selNeigs) / sizeof (API_Neig);

	GS::Array<API_Guid> guidArray;
	for (UInt32 i = 0; i < nSel; ++i) {
		guidArray.Push ((*selNeigs).guid);
	}

	BMKillHandle ((GSHandle *)&selNeigs);

	return guidArray;
}

View solution in original post

1 REPLY 1
Solution
Tibor Lorantfy
Graphisoft Alumni
Graphisoft Alumni
You can use ACAPI_Selection_Get to get the current selection:
static GS::Array<API_Guid>	GetSelectedElements (bool assertIfNoSel /* = true*/, bool onlyEditable /*= true*/)
{
	GSErrCode            err;
	API_SelectionInfo    selectionInfo;
	API_Neig             **selNeigs;

	err = ACAPI_Selection_Get (&selectionInfo, &selNeigs, onlyEditable);
	BMKillHandle ((GSHandle *)&selectionInfo.marquee.coords);
	if (err == APIERR_NOSEL || selectionInfo.typeID == API_SelEmpty) {
		if (assertIfNoSel) {
			DGAlert (DG_ERROR, "Error", "Please select an element!", "", "Ok");
		}
	}

	if (err != NoError) {
		BMKillHandle ((GSHandle *)&selNeigs);
		return GS::Array<API_Guid>();
	}

	UInt32 nSel = BMGetHandleSize ((GSHandle)selNeigs) / sizeof (API_Neig);

	GS::Array<API_Guid> guidArray;
	for (UInt32 i = 0; i < nSel; ++i) {
		guidArray.Push ((*selNeigs).guid);
	}

	BMKillHandle ((GSHandle *)&selNeigs);

	return guidArray;
}