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.

Options

API: Parsing the "expression" string of the variable for the unit

robert_chiodirobert_chiodi Member Posts: 12

I'm working on an integration where we deal a lot of with updating variables in a Variable Studio and regenerating a geometry. I was wondering if you'd be willing to share some knowledge or code on how you perform parsing of the "expression" string when converting it to the "value" string. As the title says, I am particularly interested in parsing out the unit string from the "expression".

Thanks!

Comments

  • billy2billy2 Member, OS Professional, Mentor, Developers, User Group Leader Posts: 2,100 PRO

    I might not be following your question and this might not answer your question.

    If you want to parse "json" it's best to use a prettyprint function to understand how to build an accessor.

    pretty print function

    This function will print an indented format allowing you to build a accessor

    ie…. json.data[2].unit

    println("unit "~json.data[2].unit); //"mm"

  • robert_chiodirobert_chiodi Member Posts: 12
    edited July 14
  • robert_chiodirobert_chiodi Member Posts: 12
    edited 12:53AM

    Thank you for the response. My question is about how to parse responses to the GET variables end point, where a single variable looks like, for instance:

    {"type": "ANY",
     "name": "ref",
     "value": "383.68955520000003 meter^2",
     "description": "",
     "expression": "594720.0in^2"      
    },
    

    In particular, I am finding it difficult to consistently identify the unit in the "expression", but I am now thinking about a different approach. I am left with these questions:
    1. Is the "value" string always in SI (meters, rad)?
    2. How is the unit determined for "value"? Could it have been meter*meter in my example for instance?

    Thanks!

Sign In or Register to comment.