The Global ARCHICAD Community

Stay informed. Get help. Share your knowledge.

Discussions about using GRAPHISOFT's tools (API DevKit) for independent software developers

Moderators: Karl Ottenstein, LaszloNagy, ejrolon, Barry Kelly, gkmethy, rmasaki, MOREH Tamas, Akos Somorjai, Ed Brown, Mihály Palenik, Tibor Lorántfy

#295334
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
ACAPI_Element_Create.png
Place_Element_With_Mouse.PNG
#295366
n.mihaylov wrote:
Wed Mar 13, 2019 5:17 pm
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.
#295379
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:
Screenshot 2019-03-14 at 14.26.47 (2).png
#295382
n.mihaylov wrote:
Thu Mar 14, 2019 1:48 pm
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.
#295415
Yes, this did the trick :) I just found this in DG_Test example.
Code: Select all
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!