View Full Version : "[1,2,3]" as point3 - doesnt work

04 April 2012, 04:04 AM
I'm defining a point3 in a user property, yet I can't cast it to a point3. Is this a known bug or is this some other way of doing this?

04 April 2012, 04:49 AM
You can use the execute command instead:

a = execute "[1,2,3]"
classof a -- Result: Point3

04 April 2012, 07:07 AM
Is this a known bug or is this some other way of doing this?

Not A Bug.

According to the topic "Value Common Properties, Operators, and Methods",
< value > as < class >
Converts the value to an instance of given class. See the description for each class for valid conversions. All values can be converted to class String, which yields a string with the printed representation of the value.

But the Point3 description page does not provide a conversion from String to Point3. The only allowed cast is <color> as point3. So while all values can be converted to strings, only some strings can be cast as values. For all others, execute() must be used, as shown in the other reply.

In addition, the "String Values" page shows that only Number, Integer and Float are valid classes to cast a String into. Point3 is not explicitly mentioned, and is thus not supported.

Here is an alternative way, which is more convoluted and does about the same as execute(). Just wanted to mention it if you have a large amount of data in a string you want to parse:

a = "[1, 2, 3]"
--> "[1, 2, 3]"
b = a as stringstream
--> StringStream:"[1, 2, 3]"
c = readValue b
--> [1,2,3]

CGTalk Moderation
04 April 2012, 07:07 AM
This thread has been automatically closed as it remained inactive for 12 months. If you wish to continue the discussion, please create a new thread in the appropriate forum.