2019-08-01 03:11 PM - last edited on 2022-10-04 04:25 PM by Daniel Kassai
UInt32 totalParams = BMGetHandleSize((GSConstHandle)memo.params) / sizeof(API_AddParType); for (int i=0; i<totalParams ;i++){ GS::UniString pname = (*memo.params).name; GS::Array<GS::UniString> conditions = {"param1" ,"param2"}; if (conditions.Contains(pname)){ WriteReport("dim1: %d", (*memo.params).dim1); WriteReport("dim2: %d", (*memo.params).dim2); UInt32 numArrayItems = BMGetHandleSize((GSConstHandle)(*memo.params).value.array) / sizeof(double); WriteReport("num array items: %i", numArrayItems); API_AddParType* pAddPar = &(*memo.params); double** arrHdl = reinterpret_cast<double**>(pAddPar->value.array); for (Int32 k = 0; k < pAddPar->dim1; k++){ for (Int32 j = 0; j < pAddPar->dim2; j++){ switch((*memo.params).typeID){ case APIParT_RealNum: WriteReport("realnum"); WriteReport("value %f", (*arrHdl)[k * pAddPar->dim2 + j]); break; case APIParT_CString: WriteReport("cstring"); WriteReport("value: %s", "??????????"); break; } } } } }This is working for arrays with APIParT_RealNum value type but im having trouble retrieving the full cstring values. Part of this comes down to me not really understanding the structure and types of the value array and my porbably my basic C++ knowledge. How are numerical and string values stored there? I would be very glad for some explanation and hints!
2019-08-01 05:51 PM
2019-08-02 08:46 AM
Ralph wrote:I basically want to replace some arrays in an LibPart instance. According to the second post from Oleg in this this thread
You may not need to unpack the contents of the parameter memo, depending on what you want to do. If you want to change a parameter value, for example, you can callACAPI_Goodieswith APIAny_ChangeAParameterID. What would you like to do with parameters?
Int32 ind = 0; if((*memo.params).typeID == APIParT_RealNum){ for (Int32 k = 0; k < pAddPar->dim1; k++){ for (Int32 j = 0; j < pAddPar->dim2; j++){ value = (Int32) ((double *) *(*memo.params).value.array) [ind]; valueStr = nullptr; ind ++; WriteReport("value %f", value); } } } if((*memo.params).typeID == APIParT_CString){ UInt32 num_chars; num_chars = BMGetHandleSize((GSConstHandle)(*memo.params).value.array)/ sizeof(char); WriteReport("num chars: %i", num_chars); for(int j=0; j<num_chars;j++){ value = 0.0; valueStr = *(*memo.params).value.array + ind; ind += strlen (valueStr) + 1; WriteReport("val: %s", valueStr); } }but num_chars is allways the same and not specific to the string array element.
num_chars = BMGetHandleSize((GSConstHandle)(*memo.params).value.array)/ sizeof(UTF16Char);
2019-08-02 10:19 AM
char* valueStr; double value; GS::Array<GS::UniString> StrArrValues; GS::UniString ValueString; Int32 ind = 0; if((*memo.params).typeID == APIParT_RealNum){ for (Int32 k = 0; k < (*memo.params).dim1; k++){ for (Int32 j = 0; j < (*memo.params).dim2; j++){ value = (Int32) ((double *) *(*memo.params).value.array) [ind]; valueStr = nullptr; ind ++; WriteReport("val %i:", k * (*memo.params).dim2 + j); WriteReport("%f", value); } } } if((*memo.params).typeID == APIParT_CString){ UInt32 num_chars; num_chars = BMGetHandleSize((GSConstHandle)(*memo.params).value.array)/ sizeof(UTF16Char); for(int j=0; j<num_chars;j++){ value = 0.0; valueStr = *(*memo.params).value.array + ind; //valueStr = *(*addPars).value.array + ind; if(*valueStr == '\0'){ StrArrValues.Push(ValueString); ValueString = ""; ind += 2; }else{ ValueString.Append(valueStr); ind += strlen (valueStr) + 1; } } for(int j=0; j<StrArrValues.GetSize();j++){ WriteReport("val %i:", j); WriteReport("%s", UniStringToConstCString(StrArrValuesIt works but i guess i this is not the way it is supposed to be done isn't it?)); } }