cancel
Showing results for 
Search instead for 
Did you mean: 
cancel
Showing results for 
Search instead for 
Did you mean: 
Developer forum

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!
1 ACCEPTED SOLUTION

Solution
Tibor Lorantfy
Graphisoft Alumni
Graphisoft Alumni
In a nutshell:
API_Element element;
BNZeroMemory (&element, sizeof (API_Element));
element.header.typeID = API_ObjectID;

API_ElementMemo elementMemo;
BNZeroMemory (&elementMemo, sizeof (API_ElementMemo));
ACAPI_Element_GetDefaults (&element, &elementMemo);

element.object.libInd = libIndex;
element.object.pos.x = 3;
element.object.pos.y = 0;
element.object.level = 0;

ACAPI_Element_Create (&element, &elementMemo);
ACAPI_DisposeElemMemoHdls (&elementMemo);

View solution in original post

17 REPLIES 17

Ralph Wessel
Mentor
n.mihaylov wrote:
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?
In reply to your questions:
1) Yes, new elements can be created with ACAPI_Element_Create

2) Yes, API_ObjectID is the correct type for a general-purpose object element.

3) I doubt it. Objects usually render themselves, either through a script and parameter values or by embedded (fixed) geometry. You may have to set some parameter values or (most likely) at least the bounding object size.

I recommend looking at some of the API example projects, where you will find code for creating object elements etc.
Ralph Wessel BArch

Solution
Tibor Lorantfy
Graphisoft Alumni
Graphisoft Alumni
In a nutshell:
API_Element element;
BNZeroMemory (&element, sizeof (API_Element));
element.header.typeID = API_ObjectID;

API_ElementMemo elementMemo;
BNZeroMemory (&elementMemo, sizeof (API_ElementMemo));
ACAPI_Element_GetDefaults (&element, &elementMemo);

element.object.libInd = libIndex;
element.object.pos.x = 3;
element.object.pos.y = 0;
element.object.level = 0;

ACAPI_Element_Create (&element, &elementMemo);
ACAPI_DisposeElemMemoHdls (&elementMemo);

Anonymous
Not applicable
It works after I got the libIndex (libPart.index) this way:

GS::ucscpy (libPart.docu_UName, L("Object Name"));
ACAPI_LibPart_Search (&libPart, false);
Thank you both!

Anonymous
Not applicable
One more question:
What type of structure is this API_ObjectType element? It is none of these below and I cannot get the corresponding index of the element.wall.composite index, for example, in order to set the attribute.header.index and get the element with ACAPI_Attribute_Get

Ralph Wessel
Mentor
API_ObjectType is an element created from a library part. The element contains a list of parameter values typically referenced by the library part to render it in 2D and 3D.

A composite is a multi-skinned construction attribute specifying its component materials (including thickness and fill). A composite is relevant to planar elements like walls, roofs and slabs. Composites can't be applied to objects because there's no obvious application to a body that might have any shape.

That's why you find that only a limited number of elements have a composite attribute. Objects may have many other attributes, e.g. materials, fills and pens. Some are stored in API_ObjectType, but they're more commonly found in the object's parameter settings.
Ralph Wessel BArch

Anonymous
Not applicable
Thanks, got it!
I found how to get the element:

API_LibPart libPart;
BNZeroMemory (&libPart, sizeof (API_LibPart));
libPart.index = element.object.libInd;
ACAPI_LibPart_Get (&libPart);

Ralph Wessel
Mentor
n.mihaylov wrote:
I found how to get the element:
API_LibPart libPart;
BNZeroMemory (&libPart, sizeof (API_LibPart));
libPart.index = element.object.libInd;
ACAPI_LibPart_Get (&libPart);
It could become confusing if you use the wrong terminology. That code you quoted gives you the definition of a library part, not an element. You only have an element when an instance of the library part is placed in the project.
Ralph Wessel BArch

Anonymous
Not applicable
Yes, you are right! I need to get details for my element and so I need the details for its Library Part.
I have an element which is an instance of the Library Part. First I take the guids of all elements of type API_ObjectID with ACAPI_Element_GetElemList, then I take each element with ACAPI_Element_Get using these guids and finally I get the Library Part for my element with ACAPI_LibPart_Get using element.object.libInd as libPart.index

Ralph Wessel
Mentor
n.mihaylov wrote:
Yes, I need to get details for my element and so I need the details for its Library Part.
Ok, that makes sense as long as the details you are interested in are defined by the library part and can't be overridden by the instance element. For example, the parameter values should be extracted from the element, not the library part (unless you want the defaults).
Ralph Wessel BArch

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

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

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

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!

Still looking?

Browse more topics

Back to forum

See latest solutions

Accepted solutions

Start a new discussion!