License Delivery maintenance is expected to occur on Saturday, November 30, between 8 AM and 11 AM CET. This may cause a short 3-hours outage in which license-related tasks: license key upload, download, update, SSA validation, access to the license pool and Graphisoft ID authentication may not function properly. We apologize for any inconvenience.
Archicad C++ API
About Archicad add-on development using the C++ API.

Why it's not work (About placing library object on floorplan

Anonymous
Not applicable
static void Do_MyFunction(void)
{
	API_Element element;
	API_ElementMemo memo;
	BNZeroMemory(&element, sizeof(API_Element));
	BNZeroMemory(&memo, sizeof(API_ElementMemo));
	double A = 0;
	double B = 0;
	Int32 parCount = 0;
	//----
	element.header.typeID = API_ObjectID;
	ACAPI_Element_GetDefaults(&element, NULL);
	ACAPI_LibPart_GetParams(20, &A, &B, &parCount, &memo.params);
	element.object.pos.x = 1;
	element.object.pos.y = 1;
	element.object.xRatio = A;
	element.object.yRatio = B;
	element.object.libInd = 20;
	
	GSErrCode	err = ACAPI_Element_Create(&element, &memo);
	if( err == NoError)
	{
		ACAPI_WriteReport("Ok ",true);
	}
	else
	{
		ACAPI_WriteReport("Error ",true);
	}

	ACAPI_DisposeElemMemoHdls (&memo);
}
It's all return Error only

P.S. I want to test on library index 20.
I'm coding this on VS2005 and ArchiCAD 14 Demo Version
7 REPLIES 7
Ralph Wessel
Mentor
Paodekcal wrote:
It's all return Error only
P.S. I want to test on library index 20.
Are you using ACAPI_OpenUndoableSession before calling this function? You should also check the error code returned by ACAPI_Element_GetDefaults and ACAPI_LibPart_GetParams.

As an aside, the library part index is temporary, i.e. you can cannot be certain what part it will refer to. I would never hard code an index like that.
Ralph Wessel BArch
Software Engineer Speckle Systems
Anonymous
Not applicable
Thanks for your reply

OK I will check it soon.

but a little, I confuse this sentence
"library part index is temporary"

Can you explain me in detail?
Anonymous
Not applicable
	API_LibPart part;   
	GSErrCode err;   
	BNZeroMemory(&part, sizeof(API_LibPart));   

	part.index = 20;
	err = ACAPI_LibPart_Search(&part, false);
	err = ACAPI_LibPart_Get(&part);
	API_Element element;
	API_ElementMemo memo;
	BNZeroMemory(&element, sizeof(API_Element));
	BNZeroMemory(&memo, sizeof(API_ElementMemo));
	double A = 0;
	double B = 0;
	Int32 parCount = 0;
	//----
	element.header.typeID = API_ObjectID;
	err = ACAPI_Element_GetDefaults(&element, NULL);
	err = ACAPI_LibPart_GetParams(part.index, &A, &B, &parCount, &memo.params);
	element.object.pos.x = 1;
	element.object.pos.y = 1;
	element.object.xRatio = A;
	element.object.yRatio = B;
	element.object.libInd = part.index;
	
	err = ACAPI_Element_Create(&element, &memo);
	if( err == NoError)
	{
		ACAPI_WriteReport("Ok ",true);
	}
	else
	{
		ACAPI_WriteReport("Error ",true);
	}

	ACAPI_DisposeElemMemoHdls (&memo);
I use above code and it's error too

I error only on
err = ACAPI_Element_Create(&element, &memo);
err return
APIERR_REFUSEDCMD -2130312312 81060388 The passed identifier is not subject to the operation. 
Anonymous
Not applicable
switch (menuParams->menuItemRef.itemIndex) {
case 1: Do_MyFunction (); break;
case 2: Do_CreateWindowFromHatch (); break;
}

I call it from this.

I don't know it's contain undoable session or not?
Anonymous
Not applicable
ACAPI_OpenUndoableSession("Test Lib");
	err = ACAPI_Element_Create(&element, &memo);
	ACAPI_CloseUndoableSession();
OK thx.

I just place 2 undo line here.

It's work!!!

I just understand that it "must" use with undo too.
Ralph Wessel
Mentor
Paodekcal wrote:
I confuse this sentence
"library part index is temporary"
Can you explain me in detail?
If you ask for an object with an index of '20', ArchiCAD will return whatever object has that index. But if you change the loaded libraries and ask for the object at index '20', don't be surprised if you get a different object.

Objects do not have a permanent index - refer to the object guid instead, or perhaps the name.
Ralph Wessel BArch
Software Engineer Speckle Systems
Anonymous
Not applicable
OK I get it.

Thank you.