How to deal with string array parameters?
Anonymous
Not applicable
Options
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
2019-08-01
03:11 PM
- last edited on
2022-10-04
04:25 PM
by
Daniel Kassai
2019-08-01
03:11 PM
Hey everyone,
i am trying to wrap my head arround how to handle string arrays in memo params. Example:
Thanks a lot in advance!
i am trying to wrap my head arround how to handle string arrays in memo params. Example:
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!
Thanks a lot in advance!
Labels:
- Labels:
-
Add-On (C++)
3 REPLIES 3
Options
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
2019-08-01 05:51 PM
2019-08-01
05:51 PM
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 call ACAPI_Goodies with APIAny_ChangeAParameterID . What would you like to do with parameters?
Ralph Wessel BArch
Central Innovation
Central Innovation
Anonymous
Not applicable
Options
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
2019-08-02 08:46 AM
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.
Any help would be aprecciated!
Edit: I found that using UTF16Char instead of char gives me the correct number of signs in the string array (including the two split signs as pointed out in the API documentation)
num_chars = BMGetHandleSize((GSConstHandle)(*memo.params).value.array)/ sizeof(UTF16Char);
Anonymous
Not applicable
Options
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
2019-08-02 10:19 AM
2019-08-02
10:19 AM
I was able to read out the string values like this:
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?)); } }