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

Change the default value of a parameter in a LibPart

tsuyoshimishina
Contributor

Hello experts,
I am a newbie and am here trying to get some information about changing the default value of a parameter in a LibPart. By reading this topic, I have managed to call APIAny_OpenParametersID, APIAny_GetActParametersID, and APIAny_ChangeAParameterID on the parameter with NoError. But the parameter value does not change. Do I need to call some extra function after APIAny_ChangeAParameterID in order to "overwrite" the library part with the new default parameter value?

4 REPLIES 4
Ralph Wessel
Mentor

Is the library part stored in a writable state? If not, e.g. embedded in an LCF, you won't be able to write changes to it

Ralph Wessel BArch
Software Engineer Speckle Systems

I'm not sure if it's in a writable state. The library part is in the embedded library folder. Do I need to call  ACAPI_Environment(APIEnv_OverwriteLibPartID) or some function to make it writable?

If it's in the embedded library, you should be able to echo the example code for ACAPI_LibraryPart_OpenParameters here: https://graphisoft.github.io/archicad-api-devkit/group___library_part.html

Ralph Wessel BArch
Software Engineer Speckle Systems

Ralph,

Thank you for pointing me to an example.
Below is what I'm actually doing in my add-on to change the value of the "c4dPhoIESFile" parameter of a library part (lamp):

BNZeroMemory(&libPart, sizeof(API_LibPart));
// I have both parentUniID and ownUniID values of the library part in std::string variables
strcpy(libPart.ownUnID, ownUniID.c_str());
strcpy(libPart.parentUnID, parentUniID.c_str());
auto err = ACAPI_LibPart_Search(&libPart, false);
if (err != NoError)
    ACAPI_WriteReport(L("Failed to search the library part"), true);

API_GetParamsType theParams{ };
API_ParamOwnerType paramOwner{ };
paramOwner.typeID = API_ObjectID; // may have to be API_LampID?
paramOwner.libInd = libPart.index;
GSErrCode err = ACAPI_Goodies(APIAny_OpenParametersID, &paramOwner);
err |= ACAPI_Goodies(APIAny_GetActParametersID, &theParams);
if (err == NoError) {
    API_ChangeParamType changeParam{ };
    CHTruncate("c4dPhoIESFile", changeParam.name, API_NameLen);
    GS::UniString uniStrName("test.ies");
    GS::uchar_t uniStrBuffer[_MAX_FNAME]{ 0 };
    GS::ucsncpy(uniStrBuffer, uniStrName.ToUStr().Get(), _MAX_FNAME);
    changeParam.uStrValue = uniStrBuffer;
    err = ACAPI_Goodies(APIAny_ChangeAParameterID, &changeParam);
    if (err != NoError)
        ACAPI_WriteReport(L("[LampImportTest, ERROR] Failed to update the c4dPhoIESFile parameter"), true);
}
else ACAPI_WriteReport(L("[LampImportTest, ERROR] Failed to get the c4dPhoIESFile parameter"), true);
ACAPI_DisposeAddParHdl(&theParams.params);
ACAPI_Goodies(APIAny_CloseParametersID);

This runs without any errors but the parameter value doesn't change.

I checked the parameter on GDL Object Editor, and noticed that its type is not a simple string but a list of selectable strings (which is called a "value list" in ARCHICAD terminology?)

 

c4dPhoIESFile.png

 

"test.ies" is certainly in the list, but it doesn't seem to be able to select it by simply setting a value to the parameter. Can you suggest me how to deal with this type of parameter using the API?