Welcome to the Onshape forum! Ask questions and join in the discussions about everything Onshape.

First time visiting? Here are some places to start:
  1. Looking for a certain topic? Check out the categories filter or use Search (upper right).
  2. Need support? Ask a question to our Community Support category.
  3. Please submit support tickets for bugs but you can request improvements in the Product Feedback category.
  4. 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.

println units

hervé_pipon
hervé_pipon Member Posts: 60 ✭✭
Hello

Here is a small piece of code:
    var sketchPlane = evOwnerSketchPlane(context, { "entity" : definition.selectedEdge });
    var n = 100;
    var samples = evEdgeTangentLines(context, { "edge" : definition.selectedEdge, "parameters" : range(0, 1, n) });
    var origin = worldToPlane(sketchPlane, samples[0].origin);
    println(origin * centimeter );

It prints :
    (0 meter^2, 0 meter^2)

I want to display centimeter : what is wrong ?

Comments

  • NeilCooke
    NeilCooke Moderator, Onshape Employees Posts: 6,078 image
    Units in println are always meters, plus you are multiplying origin (which has length units) by another length to get an area.
    Senior Director, Technical Services, EMEA
  • hervé_pipon
    hervé_pipon Member Posts: 60 ✭✭
    NeilCooke said:
    Units in println are always meters.
    @NeilCooke Thanks I didn't know.
  • Jacob_Corder
    Jacob_Corder Member Posts: 141 PRO
    change your println to this

    println(origin / centimeter );

  • EvanReese
    EvanReese Member, Mentor Posts: 3,013 PRO
    If you wanna get fancy with it
    printLn("origin = " ~ roundToPrecision(origin/centimeter, 3)~ " cm";
    This will print "origin = 3.25 cm" or whatever. You round to not display 3.250000000001 or some floating point value.

    Usually this isn't needed, but if there are a ton of things printing it can be nice to label them with strong concatenation. 
    Evan Reese
    The Onsherpa | Reach peak Onshape productivity
    www.theonsherpa.com