Notifications
Clear all

[Closed] "[1,2,3]" as point3 – doesnt work

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?

2 Replies

You can use the execute command instead:


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

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]