cancel
Showing results for 
Search instead for 
Did you mean: 
cancel
Showing results for 
Search instead for 
Did you mean: 
Archicad C++ API
About Archicad add-on development using the C++ API.
SOLVED!

How to set a string for a cell in array values of GDL object?

Tran Thanh Lo
Booster
Spoiler
 

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.

1 ACCEPTED SOLUTION

Accepted Solutions
Solution
DGSketcher
Legend

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?

Apple iMac Intel i9 / macOS Sonoma / AC27UKI (most recent builds.. if they work)

View solution in original post

3 REPLIES 3
Solution
DGSketcher
Legend

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?

Apple iMac Intel i9 / macOS Sonoma / AC27UKI (most recent builds.. if they work)

@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.

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;
}
Bernd Schwarzenbacher - Archicad Add-On Developer - Get Add-Ons & Archicad Tips on my Website: Archi-XT.com