BIM Coordinator Program (INT) April 22, 2024
Find the next step in your career as a Graphisoft Certified BIM Coordinator!
Archicad C++ API
About Archicad add-on development using the C++ API.

Help using ACAPI_Element_Change to change Door's "info"

Anonymous
Not applicable
I'm needing help to change the element.door.openingBase.info of all doors. I've been able to use this API function to change a Wall's info but for some reason no luck with Doors


API_Element element, mask;
Int32 nElem;
GSErrCode err;
char newID[256];
bool *suspGrp;
char msgText[256];

err = ACAPI_OpenUndoableSession ("Create Door Unique IDs");

err = ACAPI_Environment (APIEnv_IsSuspendGroupOnID, &suspGrp, "", "");


/* suspend group mode */
if (suspGrp==false)
err = ACAPI_Element_Tool (NULL, 0, APITool_SuspendGroups, "");

BNZeroMemory (&element, sizeof (API_DoorType));

err = ACAPI_Element_GetNum (API_DoorID, &nElem);
for (Int32 k = 1; k <= nElem; k++)
{
element.header.typeID = API_DoorID;
element.header.index = k;
err = ACAPI_Element_Get (&element);

if (err == NoError) {

sprintf (newID, "%s%d", "Door ", k);

ACAPI_ELEMENT_MASK_CLEAR (mask);
ACAPI_ELEMENT_MASK_SET (mask, API_OpeningBaseType, info);
CHCopyC(newID, element.door.openingBase.info);

//CHCopyC(element.door.openingBase.info, msgText);
//DGAlert (DG_INFORMATION, "Unique IDs", msgText, "", "OK","", "");

err = ACAPI_Element_Change (&element, &mask, NULL, 0, true);
//err = ACAPI_Element_Change (&element, NULL, NULL, 0, true);

if (err) {

WriteReport_Err ("Doors-Create Unique IDs:ACAPI_Element_Change", err);
err = NoError;
}
}
}
ACAPI_CloseUndoableSession ();
}
3 REPLIES 3
Akos Somorjai
Graphisoft
Graphisoft
Bianca wrote:
I'm needing help to change the element.door.openingBase.info of all doors. I've been able to use this API function to change a Wall's info but for some reason no luck with Doors

ACAPI_ELEMENT_MASK_CLEAR (mask);
ACAPI_ELEMENT_MASK_SET (mask, API_OpeningBaseType, info);
CHCopyC(newID, element.door.openingBase.info);

}
Hi Bianca,

Please set the mask differently:

			ACAPI_ELEMENT_MASK_CLEAR (mask);
			ACAPI_ELEMENT_MASK_SET (mask, API_Element, door.openingBase.info);
			CHTruncate (newID, element.door.openingBase.info, sizeof (element.door.openingBase.info));
Hope this helps, Akos
Tibor Lorantfy
Graphisoft Alumni
Graphisoft Alumni
Hi Bianca,

You have few mistakes in your code, let me correct them:
Bianca wrote:
BNZeroMemory (&element, sizeof (API_DoorType));
Correction wrote:
BNZeroMemory (&element, sizeof (API_Element));

Bianca wrote:
ACAPI_ELEMENT_MASK_SET (mask, API_OpeningBaseType, info);
Correction wrote:
ACAPI_ELEMENT_MASK_SET (mask, API_DoorType, openingBase.info);


And I suggest you to don't use old typeID+index identification (it's deprecated and in API18 it will be deleted), please use Guids!
Here is your fully corrected code:
API_Element			element, mask; 
GS::Array<API_Guid>	elemList; 
Int32				nElem = 0; 
GSErrCode			err = NoError; 
char				newID[256]; 
bool				*suspGrp; 
char				msgText[256]; 
 
err = ACAPI_OpenUndoableSession ("Create Door Unique IDs"); 
if (err) 
	WriteReport_Err ("ACAPI_OpenUndoableSession failed", err); 
 
err = ACAPI_Environment (APIEnv_IsSuspendGroupOnID, &suspGrp, "", ""); 
if (err) 
	WriteReport_Err ("APIEnv_IsSuspendGroupOnID failed", err); 
 
/* suspend group mode */  
if (suspGrp == false) { 
	err = ACAPI_Element_Tool (NULL, 0, APITool_SuspendGroups, ""); 
	if (err) 
		WriteReport_Err ("APIEnv_IsSuspendGroupOnID failed", err); 
} 
 
BNZeroMemory (&element, sizeof (API_Element)); 
 
ACAPI_Element_GetElemList (API_DoorID, &elemList); 
for (GS::Array<API_Guid>::ConstIterator it = elemList.Enumerate (); it != NULL; ++it) { 
	element.header.typeID = API_DoorID; 
	element.header.guid = *it; 
 
	err = ACAPI_Element_Get (&element); 
 
	if (err == NoError) { 
		ACAPI_ELEMENT_MASK_CLEAR (mask); 
		ACAPI_ELEMENT_MASK_SET (mask, API_DoorType, openingBase.info); 
 
		sprintf (newID, "%s%d", "Door ", ++nElem); 
		CHCopyC (newID, element.door.openingBase.info); 
 
		err = ACAPI_Element_Change (&element, &mask, NULL, 0, true); 
		if (err) { 
			WriteReport_Err ("Doors-Create Unique IDs:ACAPI_Element_Change", err); 
			err = NoError; 
		} 
	} 
} 
 
ACAPI_CloseUndoableSession ();


Best Regards,
Tibor
Anonymous
Not applicable
Thank you so much for your help. I learnt a few things from this
Learn and get certified!