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

[LibPart] Placing on scene from plugin

Anonymous
Not applicable
Hello,

I need to place LibPart using API functions from plugin. Simple Example:
I've defined box.gsm:
XFORM 1, cos(alfa), 0, 0,    
	0, 1, 0, 0,    
	0, 0, 1, 0    
BLOCK A, B, 1


I've added path to it in plugin:
IO::Location rab("D:/GDLobjects/");    
if(!rab.IsValid())    
	throw ElementException("bad location");    
if(ACAPI_Environment (APIEnv_AddLibrariesID, reinterpret_cast<void *>(&rab), NULL) == NoError)    
	_interface->GetReporter().Report("folder added");    
else    
	throw ElementException("registering location failed");


And successfully founded and loaded it to memory:
API_LibPart part;    
GSErrCode err;    
BNZeroMemory(&part, sizeof(API_LibPart));    
CHANSI2Unicode("box.gsm", strlen("box.gsm"), part.file_UName, API_UniLongNameLen);    
if((err = ACAPI_LibPart_Search(&part, false)) == NoError)    
{    
	if((err = ACAPI_LibPart_Get(&part)) == NoError)    
	{    
		// place on specified location    
	}    
	else    
		_interface->GetReporter().Report(err);    
}    
else    
	_interface->GetReporter().Report(err);


BUT!!!

I haven't found any function in ACAPI_LibPart_* to place it on scene and pass parameters to it (like: A, B, alfa);

Do anyone have examples how to do it...

Thanks for help, I need it badly

-edit-

I found ACAPI_LibPart_ShapePrims, but i have no idea how to use it 😕
2 REPLIES 2
Ralph Wessel
Mentor
bamboos wrote:
I haven't found any function in ACAPI_LibPart_* to place it on scene and pass parameters to it (like: A, B, alfa);
You've looked up the definition of a library part, but now you want to place an instance of it. They are completely different things.

To place an object in the plan, for example, you need to populate an element data structure, in this case the 'object' member of API_Element (which is of type API_ObjectType), and writing it to the element database with ACAPI_Element_Create.

Take a look at APIAny_OpenParametersID (and associated functions) for setting parameter values.
Ralph Wessel BArch
Software Engineer Speckle Systems
Anonymous
Not applicable
Helped a LOT!!!

Thanks!
API_Element element;
API_ElementMemo memo;
BNZeroMemory(&element, sizeof(API_Element));
BNZeroMemory(&memo, sizeof(API_ElementMemo));
double A = 0;
double B = 0;
long parCount = 0;
//----
element.header.typeID = API_ObjectID;
ACAPI_Element_GetDefaults(&element, &memo);
ACAPI_LibPart_GetParams(part.index, &A, &B, &parCount, &memo.params);
element.object.angle = 0;
element.object.pos.x = 0 + i;
element.object.pos.y = 0 + ii;
element.object.xRatio = A;
element.object.yRatio = B;
element.object.libInd = part.index;
					
ACAPI_Element_Create(&element, &memo);