problems with "x-axis" key in Plane object

adamohern
adamohern Member, OS Professional Posts: 216 PRO
I'm trying to retrieve the X axis vector for a Plane.

var sketchPlane = plane(origin, normal, xDirection);
println(sketchPlane);
// result:
// normal(0, 0.7071067811865476, -0.7071067811865476)
// origin(-0.3048 meter, -0.6096 meter, 1.2192 meter)
// x-axis(1, 0, 0)

Huzzah! Except that I can't access the "x-axis" key in the map.

println(sketchPlane.x-axis);
// result:
// Variable axis not found.
// Using "-" in a map key is probably a bad idea for this reason. println(sketchPlane["x-axis"]); // result: // undefined // What the wha? It's clearly defined, as you can see in the original println() above.

What am I missing?

Comments

  • ilya_baran
    ilya_baran Onshape Employees, Developers, HDM Posts: 1,279 image
    The field is just called "x".  "x-axis" is just how it's getting pretty-printed (println uses the toString function which is overloaded to pretty-print Planes).  I can see how that's confusing and will change the plane pretty printing to say "x".  You can always get the "raw" form by doing:
    println("" ~ sketchPlane);
    Ilya Baran \ VP, Architecture and FeatureScript \ Onshape Inc
  • adamohern
    adamohern Member, OS Professional Posts: 216 PRO
    Ah, thanks Ilya. Why would you ever want to pretty-print a map definition, I wonder? In what use-case would a user print a map definition but not care what the key strings are?
  • ilya_baran
    ilya_baran Onshape Employees, Developers, HDM Posts: 1,279 image
    An example is meter: that is actually a map with keys "value" and "units", but a user would likely just want to see "meter" printed.
    Ilya Baran \ VP, Architecture and FeatureScript \ Onshape Inc