We value your input!
Please participate in Archicad 28 Home Screen and Tooltips/Quick Tutorials survey

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

ACAPI_Element_Change Issue

4livesdragon
Contributor

Hello everyone, I have encountered a very strange problem. I have two Archicad Pln files, the contents of which are the same except for a few object parameters. But when I change some object parameters, and call ACAPI_Element_Change at the end, one of the files can succeed, and the other file will always report an error at ACAPI_Element_Change? Does anyone know what the possible cause is and what are the key points when using API Element Change?

4livesdragon_0-1687137492655.png

Thank you so much!

2 REPLIES 2
4livesdragon
Contributor

I think I found a possible reason. I found that in the unsuccessful file, ACAPI_Element_Create was not successfully called, nor did any errors occur, but after being called, no object was created. I wonder what are the conditions for ACAPI_Element_Create to be used successfully?

Csanyi Bence
Contributor

hello

without context it's hard to tell you, what's the problem, share more from the code but the ACAPI_Element_Create should look like this:

 

 

	GSErrCode			err = NoError;

	// element
	API_Element			element;
	API_ElementMemo		memo;
	Int32				addParNum;
	API_AddParType**	addPars = nullptr;

	// libPart
	API_LibPart			libPart;
	double				a, b;
	Int32				nSystem;

	BNZeroMemory(&element, sizeof(API_Element));
	BNZeroMemory(&memo, sizeof(API_ElementMemo));

	element.header.type = API_ObjectID;

	err = ACAPI_Element_GetDefaults(&element, &memo);
	if (err != NoError)
	{
		ACAPI_DisposeElemMemoHdls(&memo);
		return err;
	}
	ACAPI_DisposeAddParHdl(&(memo.params));	// worth erase it
	memo.params = nullptr;

	// LibPart machinations
	BNClear(libPart);
	CHCopyC(objUNID, libPart.ownUnID);

	err = ACAPI_LibPart_Search(&libPart, false, false);
	if (libPart.location != nullptr)
		delete libPart.location;

	if (libPart.index == 0)
	{
		ACAPI_WriteReport("text", true);		// GDL object not found! Please add them in Library Manager.
		ACAPI_DisposeElemMemoHdls(&memo);
		return err;
	}

	err = ACAPI_LibPart_GetParams(libPart.index, &a, &b, &addParNum, &addPars);
	if (err != NoError)
	{
		ACAPI_WriteReport("ACAPI_LibPart_GetParams[%ld]", false, err);
		return err;
	}

	// set basic parameters
	memo.params = addPars;
	element.object.libInd = libPart.index;
	element.object.angle = 0.0;
	element.object.level = 0.0;
	element.object.xRatio = 1.0;
	element.object.yRatio = 1.0;

	// for loop for change parameters
	for (Int32 ii = 0; ii < addParNum; ii++)
	{
		// change something in memo
		if (CHEqualCStrings((*memo.params)[ii].name, "someParameter"))
		{
			((*memo.params)[ii].value.real) = 5.0;

		}
	} // for loop for change parameters ends

	// place something, .gsm in my case
	err = ACAPI_CallUndoableCommand("some text", [&]() -> GSErrCode	
		{
			err = ACAPI_Element_Create(&element, &memo);
			if (err != NoError)
			{
				return err;
			}

			err = ACAPI_Goodies(APIAny_RunGDLParScriptID, &element.header);
			return err;
		});
	if (err != NoError)
	{
		ACAPI_WriteReport("ACAPI_Element_Create failed", true);
		return err;
	}