Hello,
Imagine I have a string label "test" created in a 3D object.
If this label is assigned with an empty string (""), I noticed the following:
- myObject.test.length returns 1
- myObject.test.as(string).length returns 0
Why does that happen?
Hello,
Imagine I have a string label "test" created in a 3D object.
If this label is assigned with an empty string (""), I noticed the following:
- myObject.test.length returns 1
- myObject.test.as(string).length returns 0
Why does that happen?
In the first case the value gets treated as a Variant for which the "length" property returns the number of elements if the value is an array, 0 if it's a null value and 1 otherwise.
The "length" property of a string is the byte length of the string, so 0 for the empty string.
Hello @Felix Möhlmann ,
thank you for your explanation. However, should not defining a label as "string data" suffice to cast it as "not a variant"?
The inference from your response is that all "length" calls for string labels need to be manually casted to avoid code misbehavior.
The misbehavior still happens in the code below
- string test = myObject.test;
- print(test.length); // returns 1
The only "fixes" are these
- string test = myObject.test.as(string);
- print(test.length); // returns 0
or
- print(myObject.test.as(string).length); //returns 0
I would think the compiler assumes a Variant because while the label might be set as containing string data this could change thoughout the model run.
The first example code you posted should work though (casting the label to a string variable and then printing its length).
Could you maybe upload the entire example?
Hi, @Felix Möhlmann ,
thank you. There is not much of an example. The only missing aspect from the case that triggered this question is that the original value was not an "empty string token" (i.e. ""), but an attribution from an empty cell from a global table.
Something like:
- myObject.test = myGlobalTable[1]["value"] //column 'value' is previously
- assigned as string/text
string test = myObject.test;
print(test.length); // returns 1
Anyway, my takeaway from all this is that every label needs to be explicitly casted as string if string attributes/functions are expected to work properly.
Thank you.
6 People are following this question.
FlexSim can help you understand and improve any system or process. Transform your existing data into accurate predictions.
FlexSim is a fully 3D simulation software environment. FlexSim can be used to simulate any process in any industry.
FlexSim®, FlexSim Healthcare™, Problem Solved.®, the FlexSim logo, the FlexSim X-mark, and the FlexSim Healthcare logo with stylized Caduceus mark are trademarks of FlexSim Software Products, Inc. All rights reserved.
Privacy | Do not sell or share my personal information | Cookie preferences | Report noncompliance | Terms of use | Legal | © 2025 Autodesk Inc. All rights reserved