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

How to get all instance of a Object in C++?

Tran Thanh Lo
Booster

Hi guys,

I want to get all API_ObjectID of a API_LibPart in active floor. Do you know any way? Can you tell me?

Thank you very much.

1 REPLY 1

Hi!

Here's some sample code. I haven't tested it but it should be very close to what you need:

GSErrCode IterateThroughListLibPartsOnCurrentFloor ()
{
	API_LibPart libPart{};

	CHCopyC ("{GUID OF YOUR LIBPART HERE}-{00000000-0000-0000-0000-000000000000}",
		libPart.ownUnID);

	GSErrCode err = ACAPI_LibPart_Search (&libPart, false);
	if (err != NoError) { return err; }

	if (libPart.location != nullptr) {
		delete libPart.location;
		libPart.location = nullptr;
	}

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

	for (const auto objectGuid : objectList) {
		API_Element objectElem{};
		objectElem.header.guid = objectGuid;
		err = ACAPI_Element_Get (&objectElem);
		if (err != NoError) { return err; }

		if (libPart.index == objectElem.object.libInd) {
			// Here you have a placed object element from the library part
		}
	}


	return err;
}