Welcome to the Onshape forum! Ask questions and join in the discussions about everything Onshape.
First time visiting? Here are some places to start:- Looking for a certain topic? Check out the categories filter or use Search (upper right).
- Need support? Ask a question to our Community Support category.
- Please submit support tickets for bugs but you can request improvements in the Product Feedback category.
- Be respectful, on topic and if you see a problem, Flag it.
If you would like to contact our Community Manager personally, feel free to send a private message or an email.
pretty-print a map?
adamohern
Member, OS Professional Posts: 216 PRO

The above is really hard on the eyes. I find it difficult to read. Is there a way to print out nested maps and arrays with better formatting?
0
Comments
So something like:
// new type export type MyType typecheck isMyType; export predicate isMyType(value) { value is map; isInteger(value.id); isLength(value.length); is3dLengthVector(value.endPoint); isAngle(value.axialRotation); is3dDirection(value.orientation); } // constructor export function myType(id is number, length is ValueWithUnits, endPoint is Vector, axialRotation is ValueWithUnits, orientation is Vector) returns MyType { return {"id" : id, "length" : length, "endPoint" : endPoint, "axialRotation" : axialRotation, "orientation" : orientation } as MyType; } // overloads export function toString(value is MyType) returns string { var out is string = "MyType:"; for (var entry in value) { out ~= "\n" ~ entry.key ~ ": "; out ~= toString(entry.value); } return out; } export function debug(value is MyType) { // call debug() on the relevant data in this type }I'm not sure about your exact use case, but for sake of conciseness in the type, it might be nicer to group endPoint, axialRotation, and orientation into a single CoordSystem to start with (personally, I find it mind-numbing trying to do vector math unless I'm starting with a CoordSystem and can call fromWorld() everywhere).
In the future, we'd like to have a nicer way of presenting big chunks of native data by default (even when custom types aren't defined), but today, untyped data is printed as a big long literal.
println("my map is " ~ toString(myMap)); // or simply println(myMap);Making a type is still good practice, but for the pretty-printing, calling the preexisting toString() will be much better than what you're seeing above.