2024-05-01 05:52 AM - last edited on 2024-09-17 11:05 AM by Doreena Deng
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?
2024-05-01 05:22 PM
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
2024-05-02 03:23 AM
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?
2024-05-02 09:39 PM
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
2024-05-03 01:06 PM
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, ¶mOwner);
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?)
"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?