We value your input! Please participate in Archicad 28 Home Screen and Tooltips/Quick Tutorials survey
2023-10-14 03:49 PM - last edited on 2024-09-16 02:27 PM by Doreena Deng
I get and set a value in array values like this.
if ((*memo.params)[i].name == (GS::UniString)"matrix_area")
{
API_AddParType* pAddPar = &(*memo.params)[i];
GS::uchar_t** arrHdl = reinterpret_cast<GS::uchar_t**>(pAddPar->value.array);
(*arrHdl)[0] = 'f';
}
But I can only set it to the uchar_t value. Can I set it a string value?
Can you answer for me? Thank you very much.
Solved! Go to Solution.
2023-10-14 06:55 PM
In GDL land an array may only contain one data type e.g. number or string, they can't be mixed. Not sure if that is what you are trying to do?
2023-10-14 06:55 PM
In GDL land an array may only contain one data type e.g. number or string, they can't be mixed. Not sure if that is what you are trying to do?
2023-10-15 06:36 AM
@DGSketcher wrote:In GDL land an array may only contain one data type e.g. number or string, they can't be mixed. Not sure if that is what you are trying to do?
Yes, I see. Thank you very much.
2023-10-16 12:21 AM
You need to use something like GS::ucscpy
to copy a whole string (instead of a single character) into a uchar_t
pointer. And the handle needs to be appropriately sized!
Here's some (untested) sample code:
GS::Array<GS::UniString> stringsToCopy{ "foo", "barbar" };
// assuming we have a one dimensional parameter array of strings
auto& currentParam = (*memo.params)[i];
if (currentParam.dim1 != 1) { return; }
currentParam.dim1 = usedZoneCats.GetSize ();
currentParam.dim2 = 1;
GS::USize totalLength = 0;
for (const auto str : stringsToCopy) {
// +1 because the "\0" string delimiter is not counted in GetLength () function
totalLength += str.GetLength () + 1;
}
currentParam.value.array = BMReallocHandle (currentParam.value.array,
totalLength * sizeof (GS::uchar_t), REALLOC_FULLCLEAR, 0);
auto attrArray = reinterpret_cast<GS::uchar_t*>(*currentParam.value.array);
GS::USize strStart = 0;
for (Int32 j = 0; j < currentParam.dim1; ++j) {
GS::ucscpy (attrArray + strStart, stringsToCopy[j].ToUStr ());
strStart += stringsToCopy[j].GetLength () + 1;
}