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.

Issues with rendering Objects through code(API_ObjectType)

kency
Enthusiast

Hey team,

 

We have been trying to render an object through Archicad Add-on code. Issues found:

  1. Changing the fixPoint value does not change the object's position. We understand that the fix-point will be one of the several hotspots/points within the object that will be considered for the clicked position. However, when we change this value, it does not shift the object accordingly
  2. There is no change in rendering the object when the offset value is changed.
  3. There is a visual difference in the object when rendered through code and through the UI(Please refer to the screenshots)

 

 Is there anything that we are missing out on?

@BerndSchwarzenbacher  @Akos Somorjai 

Code:

 

 

 

 

GSErrCode CreateFurnitureElement()
{
	API_Element element = {};
	BNClear(element);
	SetAPIElementType(element, API_ObjectID);
	API_ElementMemo memo{};
	BNClear(memo);

	GSErrCode err = ACAPI_Element_GetDefaults(&element, &memo);
	if (err != NoError)
	{
		return err;
	}
	element.object.head.floorInd = 0;
	Int32 libInd = GetLibraryIndex("Sofa L-Shape 03 26", APILib_ObjectID);
	if (libInd > 0)
	{
		element.object.libInd = libInd;
		element.object.pos = {2,2};
		element.object.angle = 0;
                element.object.level = 0;
                element.object.fixPoint = 1;
                element.object.useXYFixSize = false;
                element.object.offset = {1,1};
                element.object.xRatio = 1;
                element.object.yRatio =1;

		err = ACAPI_Element_Create(&element, &memo);
		if (err != NoError)
		{
			return err;
		}
		return NoError;
	}
	throw std::runtime_error("Furniture not found");
}

 

 

 

 

 Rendered through UI

renderedThroughUI.png

 

 

Rendered through code

renderedThroughCode.png

  

Thank you!

3 REPLIES 3

Hi Kency,

 

About 1 & 2: I think from the API point of placing an object, you have to specify pos where you want the origin (0,0,0) of the GDL object to be.
My suspicion is, that offset then might give you the distance of the clicked point to the actual position of the GDL origin as an output. That then depends on the fixPoint if that's not at the GDL object's origin. I think offset is not available as an input for API calls.
But all of this is just a guess how it works, I don't have time to confirm this right now.

 

About 3: Is the difference only in the material display or is there something else I'm missing? Also what do you mean exactly by "rendered through code" vs. "rendered through ui"?


Best,
Bernd

 

 

 

1. For the fixPoint what I meant was with the pos value set to 0,0,0 and then just changing the fixPoint does not shift the object. Our understanding is that the position will be aligned to the fixPoint set. (For example, if the fixPoint is one of the corners of the object, the pos (0,0,0) will be set for that corner).

 

2. Offset is provided in the API documentation. But did not understand its relevance and it did not change the positioning of the object.

 

3. There is a visual difference. What I meant by "rendered through code" is the one on the left was placed by triggering the add-on that we have written(the snippet is shared in the first post) and "Rendered through UI" means we placed the exact same object through the archicad UI after the add-on execution.

I've just seen that again and stilll have some thoughts, that's why I'm answering so late.

1. I think that understanding is incorrect. I think the object is placed such that the GDL origin is at the specified position.
2. I think it's only an output parameter.

3. Looking at the code, it seems like you are not updating the parameters in the memo after changing the library part index. So I guess, that the relevant material, surface and pen parameters are not properly set up for the object placed via the Add-On (since you get those parameters from the current default object).