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.

Squaring Variable expression or how to square a number in onshape

jonah_mack964jonah_mack964 Member Posts: 4
edited May 6 in General

been stuck on this for ages - I cant seem to get this variable expression to work and despite asking LLMs for help on the topic they also seem to be unsure as to why it doesnt work - i have tried making them unitless too but the expression just doenst seem to work. any help appreciated

full expression is:

sqrt((#upper_x**2) + (#upper_y**2))

but no matter how i seem to try ad write the experession i get a syntax error

edit: changed title for better search results

Screenshot 2025-05-06 at 11.09.04.png

Comments

  • NeilCookeNeilCooke Moderator, Onshape Employees Posts: 5,851

    It's because the values have units, so you are creating mm^2

    Try: sqrt((#upper_x/mm)^2 + (#upper_y/mm)^2) * mm

    Senior Director, Technical Services, EMEA
  • jelte_steur814jelte_steur814 Member Posts: 454 PRO

    hmm, actually Neil, the sqrt cancels out the square returning the units to the proper mm.

    but the "**2" syntax is wrong. for square, use "^2"

  • ilya_baranilya_baran Onshape Employees, Developers, HDM Posts: 1,232

    @jelte_steur814 is correct — sqrt(#upper_x^2 + #upper_y^2) should work with units. Even better is hypot(#upper_x, #upper_y).

    Ilya Baran \ VP, Architecture and FeatureScript \ Onshape Inc
  • jonah_mack964jonah_mack964 Member Posts: 4

    thanks both for the answers - i did soon find this out after the post and was able to get the correct output

    the ai overview response suggested the use of "**" to square numbers - hopefully the above will provide a quick search result for others

  • eric_pestyeric_pesty Member Posts: 2,160 PRO

    I would recommend trying out Onshape's own AI Advisor, which should not provide misleading information the way a "generic" google search does…

    https://learn.onshape.com/pages/ai-advisor

    Side note, this should be way easier to find!

Sign In or Register to comment.