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.
how to get the coordinates from all parts? loop through all parts en print the coordinates
rooiejoris
OS Professional Posts: 16 PRO
Hi,
I am not a programmer, but I think I want something fairly simple:
I want a list of coordinates of all parts in the part studio.
Basically loop through all parts and print the coordinates in the monitor (or save to csv, but that is luxury... : )
https://cad.onshape.com/documents/bced954384551d9a45056666/w/1c4ec0f34b9d2439e54967bb/e/efbe92356f7e4fdb9a7ffea8?renderMode=0&uiState=65cc8eb5ce42ed723b91737c
I tried chatgpt for inspiration. (see the featurestudio starting with 'chatgpt' and 'google' There are probably some hints in there, but I didn't get it to work.
Can someone give me a better hint, or a working script... : )
cheers / joris
I am not a programmer, but I think I want something fairly simple:
I want a list of coordinates of all parts in the part studio.
Basically loop through all parts and print the coordinates in the monitor (or save to csv, but that is luxury... : )
https://cad.onshape.com/documents/bced954384551d9a45056666/w/1c4ec0f34b9d2439e54967bb/e/efbe92356f7e4fdb9a7ffea8?renderMode=0&uiState=65cc8eb5ce42ed723b91737c
I tried chatgpt for inspiration. (see the featurestudio starting with 'chatgpt' and 'google' There are probably some hints in there, but I didn't get it to work.
Can someone give me a better hint, or a working script... : )
cheers / joris
Tagged:
0
Best Answers
-
chadstoltzfus Member, Developers, csevp Posts: 144 PROWhen you display the results of box3dCenter(), it will always be in meters since it is displaying the raw value stored by the variable coord in your example. If you display a ValueWithUnits in a custom table, it will go off of your workspace's unit settings. If you want to bypass that, you'll have to do some conversion math and display it as a string instead.
The box3dCenter function returns a Vector, which is an array of ValueWithUnits values (x, y, z). So to display an individual value of a vector, you can call it like so
To display the value in your table, you can add the key/value pair onto the map when appending a row.
coord[0]rows = append(rows, tableRow({ "name" : partName, "coord" : coord, "coordx" : coord[0], "coordy": coord[1] }));
Applications Developer at Premier Custom Built
chadstoltzfus@premiercb.com0 -
rooiejoris OS Professional Posts: 16 PROThanks...!
Also improved my script in de mean time.
Nice to know was to divide by millimeter to 'just get the value'.
key was here:var xcoord = roundToPrecision(coord[0]/millimeter,3);var ycoord = roundToPrecision(coord[1]/millimeter,3);
cheers / joris0
Answers
now I cant get the units to mm instead of meters
and is it easy to make a column for just X and Y? in other words how to extract the X and Y value from:
see the "onshapeexample_volumetable Copy 1" featurescript
The box3dCenter function returns a Vector, which is an array of ValueWithUnits values (x, y, z). So to display an individual value of a vector, you can call it like so
To display the value in your table, you can add the key/value pair onto the map when appending a row.
chadstoltzfus@premiercb.com
Also improved my script in de mean time.
Nice to know was to divide by millimeter to 'just get the value'.
key was here:
cheers / joris