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

Creating a new Element for a Library Object

Anonymous
Not applicable
Hi guys,

With your help I imported this library object from an .lcf file which has classification Building Element Proxy:


I have to create an element for it and I want to ask the following:

1. Do I have to use ACAPI_Element_Create or some API_​LibPart function?

2. In the first case, is this the correct ID - element.header.typeID = API_ObjectID?

3. Do I have to set in the memo the coordinates and sizes of all the "lines" which build this figure? If I already have them imported, can I retrieve them in some way?

I could not find anything relevant in the example and in the other topics in the forum.

Thanks in advance!
17 REPLIES 17
Anonymous
Not applicable
In my case I needed the name of the Library Part and found only this way to get it.
I thik it can't be overridden by the instance element.
Anonymous
Not applicable
Hello again,

I came upon the following strange problem:
When I import a new Library Object and then create an element of it and place it, some of the parameters are changed and the whole element is "broken". The object itself is imported with the correct parameters in the Library Manager - if I manually choose the object and place an instance, everything is OK, the parameters are correct. Only the element created by ACAPI_Element_Create in my addon has wrong parameters.
What could be the problem?

Parameters from ACAPI_Element_Create ----------- Parameters of object in Object Manager
Ralph Wessel
Mentor
n.mihaylov wrote:
When I import a new Library Object and then create an element of it and place it, some of the parameters are changed and the whole element is "broken". The object itself is imported with the correct parameters in the Library Manager - if I manually choose the object and place an instance, everything is OK, the parameters are correct. Only the element created by ACAPI_Element_Create in my addon has wrong parameters.
What could be the problem?
I think you want to look at what default values the element is inheriting when you use ACAPI_Element_Create. Remember, the library part is like a template or class and its parameter values are at best a default. But each instance you place as an element can have any (allowed) values in the parameters, i.e. its values are disassociated from the library part (template).

I'm guessing your default parameter values are probably coming from the Door tool settings. If you want them to be the same as the originating library part, make sure the memo settings for the element instance are copied from the library part memo.
Ralph Wessel BArch
Software Engineer Speckle Systems
Anonymous
Not applicable
Thank you, Ralph!

Now I know what to do but with no success so far
According to the example for ACAPI_​Element_​GetDefaults, I added a new line setting APIVarId_Object and also doubled the element.object.libInd setting but I keep on getting the default values of an object called Armchair 01 22 from the default library:
Ralph Wessel
Mentor
n.mihaylov wrote:
According to the example for ACAPI_​Element_​GetDefaults, I added a new line setting APIVarId_Object and also doubled the element.object.libInd setting but I keep on getting the default values of an object called Armchair 01 22 from the default library:
I think ACAPI_​Element_​GetDefaults will simply extract all the settings from the specified tool settings dialog, including the memo with the parameter settings. The libInd you specify is ignored and overwritten with whatever object is currently selected in the settings dialog.

I think you probably need to get the memo from original library part use that when you create your new element. Then the parameters will be set to the default values of your original library part.
Ralph Wessel BArch
Software Engineer Speckle Systems
Anonymous
Not applicable
I did not find any way to get the memo of a library part. The only way I think is to use ACAPI_LibPart_GetParams and then change all the params of the element after I create it
Ralph Wessel
Mentor
Take a look at ACAPI_LibPart_GetParams. This gives you the same handle to the object parameters that use in the element memo structure.
Ralph Wessel BArch
Software Engineer Speckle Systems
Anonymous
Not applicable
Yes, this did the trick I just found this in DG_Test example.

ACAPI_LibPart_GetParams (libPart.index, &aParam, &bParam, &addParNum, &elementMemo.params);
element.object.libInd = libPart.index;
element.object.pos.x = 3;
element.object.pos.y = 0;
element.object.level = 0;
element.object.xRatio = aParam;
element.object.yRatio = bParam;
        
ACAPI_Element_Create (&element, &elementMemo);
ACAPI_DisposeElemMemoHdls (&elementMemo);
Now the element has the correct parameters.

Thank you!