Inch Metric
From Macros Wiki
| ! change current part units from inch to metric | |
| ! or metric to inch, ie swap the current units | |
| a1$ = "This macro will change the units of the current part" | |
| a2$ = "from inch to metric, or metric to inch, scaling the" | |
| a3$ = "geometry and solids accordingly" | |
| message "%a1$\n%a2$\n%a3$" | |
| check part_open, "You must have a part open to run this macro" | |
| get_part_data units, iunits | |
| if iunits=1 then goto inch | |
| yesno "This part is Metric, Do you want to convert it to Inch ?", iyesno, "Inch Metric Macro" | |
| if iyesno=0 then stop "Finished - no action taken" | |
| ! convert from metric to inch | |
| ! --------------------------- | |
| scale = 1/25.4 | |
| iunits= 1 | |
| goto scale | |
| ! convert from inch to metric | |
| ! --------------------------- | |
| :inch | |
| scale = 25.4 | |
| iunits= 0 | |
| :scale | |
| set_part_data units, iunits | ! change the part units |
| ! any solids will have been scaled by changing the | |
| ! part units, now scale the geometry | |
| select_all_geo | |
| scale_geo scale | |
| yesno "Scale the stock ?", iyesno, "Inch Metric Macro" | |
| if iyesno=0 then redraw | |
| if iyesno=0 then stop "Finished - stock size not changed" | |
| ! get the current stock | |
| ! --------------------- | |
| get_part_data stock_x1, x1 | |
| get_part_data stock_y1, y1 | |
| get_part_data stock_z1, z1 | |
| get_part_data stock_x2, x2 | |
| get_part_data stock_y2, y2 | |
| get_part_data stock_z2, z2 | |
| !get_part_data stock_z1, z1 | ! you would use these variables |
| !get_part_data stock_z2, z2 | ! for a turned part |
| !get_part_data stock_rad, rr | |
| ! change the current stock | |
| ! ------------------------ | |
| set_part_data stock_x1, x1*scale | |
| set_part_data stock_y1, y1*scale | |
| set_part_data stock_z1, z1*scale | |
| set_part_data stock_x2, x2*scale | |
| set_part_data stock_y2, y2*scale | |
| set_part_data stock_z2, z2*scale | |
| ! get_part_data stock_z1, z1 | ! you would use these variables |
| ! get_part_data stock_z2, z2 | ! for a turned part |
| ! get_part_data stock_rad, rr | |
| zoom_view 0 | |
| message "Finished" |