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.
SOLVED!

APIERR_BADINDEX error on ACAPI_Element_Create

Anonymous
Not applicable
Hello,
could anyone help a newbie?
I got APIERR_BADINDEX error on ACAPI_Element_Create and I can't get out.
This is the function code:
GSErrCode CreateObjectElement (double posX, double posY, API_Guid& placedObjectGuid)
{
    GSErrCode err = NoError;
    API_Element objElement = {};
    API_ElementMemo  memo = {};

    BNZeroMemory (&objElement, sizeof (API_Element));
    BNZeroMemory (&memo, sizeof (API_ElementMemo));

    API_LibPart libPart;
    BNZeroMemory (&libPart, sizeof (API_LibPart));
    libPart.typeID = APILib_ObjectID;
    libPart.isTemplate = false;
    libPart.isPlaceable = true;
    CHCopyC ("{9C72BC5B-9742-4B29-8863-75AAF5F23226}-{4281AA33-3CD6-46A2-AAB0-85F555577C6F}", libPart.ownUnID); // Cube unID

    // searching the libray using "libPart.ownUnID"
    err = ACAPI_LibPart_Search(&libPart, false);
    if (err != NoError) {
        return err;
    }
    
    objElement.object.libInd=libPart.index; //library index
    objElement.object.head.typeID = API_ObjectID;
    objElement.object.head.variationID = APIVarId_Object;
    err = ACAPI_Element_GetDefaults (&objElement, &memo);
    if (err != NoError) {
        return err;
    }

    double aParam, bParam;
    Int32 addParNum;
    
    err = ACAPI_LibPart_GetParams (libPart.index, &aParam, &bParam, &addParNum, &memo.params);
    if(err != noErr){
        return err;
    }

    objElement.object.libInd=libPart.index;
    objElement.object.head.typeID = API_ObjectID;
    objElement.object.head.variationID = APIVarId_Object;
    objElement.object.pos.x = 0;
    objElement.object.pos.y = 0;
    objElement.object.level = 0;
    
    err = ACAPI_Element_Create (&objElement, &memo);
    if (err != NoError) {
        return err; // ------- got error here!! ------
    }

    placedObjectGuid = objElement.header.guid;
    ACAPI_DisposeElemMemoHdls (&memo);
    return NoError;
}
The function is called from a ACAPI_CallUndoableCommand block:

                ACAPI_CallUndoableCommand ("Create and Object", [&] () -> GSErrCode {
                    err = STR_OM::CreateObjectElement (columnElement.column.origoPos.x  + 1, columnElement.column.origoPos.y + 1, placedObjectGuid);
                    if (err != NoError)
                        return err;
                     ...
                    return NoError;
                });
Thanks in advance.
1 ACCEPTED SOLUTION

Accepted Solutions
Solution
Anonymous
Not applicable
found the error ... bad cube UnID

View solution in original post

1 REPLY 1
Solution
Anonymous
Not applicable
found the error ... bad cube UnID