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

How to use the 'LibPart' to create Axis Net?

Anonymous
Not applicable
I have found the 'LibPart' of the element of Axis Net. But when I create, it error.

BNZeroMemory (&element, sizeof (API_Element));
BNZeroMemory(&element, sizeof(API_ElementMemo));
element.header.typeID = API_ObjectID;
ACAPI_Element_GetDefaults(&element, &memo);

for(int j = 0; j < addParNum; j++)
{
     API_AddParType &addPar = (*addPars);
     if(CHEqualCStrings(addPar.name, "AC_MarkerText_1"))
    {
         GS::ucscpy(addPar.value.uStr, L("A"));
    }
}

element.object.pos.x = c.x;
element.object.pos.y = c.y;
element.object.libInd = libPart.index;
element.object.angle = 0;

memo.params = addPars;

err = ACAPI_Element_Create(&element, &memo);
ACAPI_DisposeElemMemoHdls(&memo);
it returns the error "APIERR_BADPARS".
What's wrong?
5 REPLIES 5
Ralph Wessel
Mentor
wcyoot wrote:
I have found the 'LibPart' of the element of Axis Net. But when I create, it error.
You haven't shown all your source code, so the problem may be outside of this, e.g how did you obtain addPars and libPart.index? Have you opened an 'Undo' session with ACAPI_OpenUndoableSession?
You also have an obvious bug here:
BNZeroMemory(&element, sizeof(API_ElementMemo)); 
That should be:
BNZeroMemory(&memo, sizeof(API_ElementMemo)); 
That bug alone may be causing the problem (because the memo fields are not initialised to zero). I recommend starting with code from the examples bundled with the API. You could look at the code for Do_CreateWindow in the Element_Test project, which places a window object in a specified wall.
Ralph Wessel BArch
Software Engineer Speckle Systems
Anonymous
Not applicable
I am sure I have got the libPart and addPars, because I have debug it step and step.I also correct that bug. But has no effect.
Ralph Wessel
Mentor
wcyoot wrote:
I am sure I have got the libPart and addPars, because I have debug it step and step.I also correct that bug. But has no effect.
OK. Can you confirm you are using ACAPI_OpenUndoableSession prior to the code shown?

Also, check the attributes of the newly created object, particularly the layer. ACAPI_Element_GetDefaults obtains the current tool settings, but they are not necessarily valid, e.g. the selected layer may be locked, hidden, or even missing. The same is true for other attributes, e.g. materials. Check the storey settings too.

Also, what type of library part are you trying to place, i.e. what is "Axis Net"? Is it a simple object, or does it have a 'special' purpose, e.g. a door, window, or label, which might require different data?

I also recommend simplifying your code as much as possible when you hit a snag like this. Take out anything inessential, e.g. the code that modifies the "AC_MarkerText_1" parameter, so you reduce the problem to the smallest possible subset of commands. Once the essential code works you can continue adding additional features
Ralph Wessel BArch
Software Engineer Speckle Systems
Anonymous
Not applicable
I'm sure I have used ACAPI_OpenUndoableSession, I have used the same way to create another LibPart, but I cannot create this by the same way.
Akos Somorjai
Graphisoft
Graphisoft
wcyoot wrote:
I'm sure I have used ACAPI_OpenUndoableSession, I have used the same way to create another LibPart, but I cannot create this by the same way.
Where are the addPar and the libPart.index coming from? Is it possible that you really have a bad set parameters?

best,

Akos