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

Using API_RoomRelation structure

Anonymous
Not applicable
I am newbie here. Trying to write a program to Cycle through all the Zones. Find related objects in each Zone and Modify a Parameter.

Following is part of the code.


static GSErrCode CycleZoneObjects ( const long index, const char *floor_param, const char *floor_type )
{
	GSErrCode				lastErr;
	API_RoomRelation        relData;
	API_ElemTypeID			typeID;
	long                    ind;
	char					buffer[256];
	API_Element				element;
	API_ElementMemo			memo;

	typeID = API_ObjectID;

	lastErr = ACAPI_Element_GetRelations (API_ZoneID, index,
		typeID, &relData);
	
	if ( lastErr != NoError )
			return lastErr;
	sprintf ( buffer, "Found %d Related Objects", relData.nObject );
	WriteReport_Alert( buffer, true );
	//continue;
	{

		for ( ind=0; ind < relData.nObject; ind++)
		{
			BNZeroMemory (&element, sizeof (API_Element));
			element.header.typeID = typeID;
			element.header.index = (long) relData.objects[ind];
//Here the object index I get seems to be invalid.			
			lastErr = ACAPI_Element_Get ( &element );
			if (lastErr == NoError )
			{
				lastErr = ACAPI_Element_GetMemo_Masked ( element.header.typeID, element.header.index, APIMemoMask_AddPars, &memo);
				SetFloorParValue ( &memo.params, floor_param, floor_type);
				ACAPI_DisposeElemMemoHdls (&memo);
			}
			if (lastErr != NoError )
				WriteReport_Alert("ACAPI_Element_Get/Memo in ZoneObjects Error", true );
		}
	}

	ACAPI_DisposeRoomRelationHdls (&relData);
	return lastErr;
}


static GSErrCode CycleZones ( void)
{
	GSErrCode       lastErr;
	API_ElemTypeID  typeID;
	API_Element		elem;
	API_ElementMemo elemMemo;
	long            nElem, i;
	char			floor_param[] = "floor_f";
	char			floor_type[50];
	char			buffer[256];

	typeID = API_ZoneID;
	lastErr = ACAPI_Element_GetNum (typeID, &nElem);
	if (lastErr != NoError)
		return lastErr;

	sprintf ( buffer, "Found %ld Zones", nElem );
	WriteReport_Alert( buffer, true );

	for (i = 1; i <= nElem && !lastErr; i++) 
	{
		if (!ACAPI_Element_Filter (typeID, i, APIFilt_OnVisLayer | APIFilt_OnActFloor))
			continue;
			
		BNZeroMemory (&elem, sizeof (API_Element));

		elem.header.typeID = typeID;
		elem.header.index = i;
		lastErr = ACAPI_Element_Get (&elem);
		if (lastErr == NoError && elem.header.hasMemo) 
		{
			lastErr = ACAPI_Element_GetMemo_Masked ( typeID, i, APIMemoMask_AddPars, &elemMemo);
			/* Custom element processing */
			GetFloorParValue ( &elemMemo.params, floor_param, floor_type);
			if (CHEqualASCII(floor_type, "Tiles", CS_CaseInsensitive) ||
				CHEqualASCII(floor_type, "Carpet", CS_CaseInsensitive) )
			{
				sprintf(buffer, "The floor type is %s\n", floor_type);
				WriteReport_Alert(buffer, true);
				CycleZoneObjects ( elem.header.index, floor_param, floor_type );
			}
			ACAPI_DisposeElemMemoHdls (&elemMemo);
		}
	}
	return lastErr;
}


static void	DoZoneCycling (void)

{
	CycleZones();
	return;

}
I am having trouble getting the right object index from API_RoomRelation structure. When I pass the object index to ACAPI_Element_Get, I am getting error 13 which is not in the error list.

Also, I get the number of objects as 4 when there is only one object in the zone (3 more than the actual objects).

This is on ArchiCAD 10 using API 10.22
2 REPLIES 2
Ralph Wessel
Mentor
suresha wrote:

			element.header.index = (long) relData.objects[ind];
//Here the object index I get seems to be invalid.			
			lastErr = ACAPI_Element_Get ( &element );
When I pass the object index to ACAPI_Element_Get, I am getting error 13 which is not in the error list.
The error is actually 1 line above where you discover the problem. relData.objects is a handle, not a pointer, so you have to dereference it twice. That's why you have had to cast the value as (long) - the compiler was actually giving you a useful warning there.

So instead of:
element.header.index = (long) relData.objects[ind];
...you should write:
element.header.index = (*relData.objects)[ind];
Ralph Wessel BArch
Anonymous
Not applicable
Thank you very much Ralph!!

Regards,