We value your input!
Please participate in Archicad 28 Home Screen and Tooltips/Quick Tutorials survey

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

changing the index of library part does not work

Martin Walter
Enthusiast
I'm trying to change the library part index of an element by this code:


API_Element elementMask;
BNZeroMemory(&elementMask, sizeof(API_Element));

ACAPI_ELEMENT_MASK_SET(elementMask, API_WindowType, openingBase.libInd);
element.window.openingBase.libInd = iLibIndex;

const GSErrCode error = ACAPI_Element_ChangeParameters({ element.header.guid }, &element, nullptr, &elementMask);

const GSErrCode errorChange = ACAPI_Element_Change(&element, &elementMask, nullptr, 0UL, false);

But I get the result APIERR_BADPARS for both functions ACAPI_Element_ChangeParameters and ACAPI_Element_Change.
AC22-27, Windows 11, i7-1355U, 32GB RAM, 2TB SSD
1 ACCEPTED SOLUTION

Accepted Solutions
Solution
Ralph Wessel
Mentor
I think that changing just the index of the library part may not be sufficient. You probably also need to set the correct parameters for that object – possibly that's what the error is indicating.

You could get the correct parameters by loading the default from the object with ACAPI_LibPart_GetParams. The memo data retrieved with this method can be directly used to update the target element, but you might want to use ACAPI_Element_Change in order to write the changes to both the element and memo data.
Ralph Wessel BArch
Software Engineer Speckle Systems

View solution in original post

5 REPLIES 5
Ralph Wessel
Mentor
Are you attempting to change the element within an active undo session? Otherwise, what error is returned?
Ralph Wessel BArch
Software Engineer Speckle Systems
Martin Walter
Enthusiast
Yes I use the command in ACAPI_CallUndoableCommand.

The returned error is APIERR_BADPARS.
AC22-27, Windows 11, i7-1355U, 32GB RAM, 2TB SSD
Martin Walter
Enthusiast
Any ideas?
AC22-27, Windows 11, i7-1355U, 32GB RAM, 2TB SSD
Solution
Ralph Wessel
Mentor
I think that changing just the index of the library part may not be sufficient. You probably also need to set the correct parameters for that object – possibly that's what the error is indicating.

You could get the correct parameters by loading the default from the object with ACAPI_LibPart_GetParams. The memo data retrieved with this method can be directly used to update the target element, but you might want to use ACAPI_Element_Change in order to write the changes to both the element and memo data.
Ralph Wessel BArch
Software Engineer Speckle Systems
Martin Walter
Enthusiast
Using the element memo instead of a nullptr was the correct hint. Thanks a lot!
AC22-27, Windows 11, i7-1355U, 32GB RAM, 2TB SSD