Inch Metric
From Macros Wiki
Jump to navigationJump to search
| ! 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 | |
| ! get the current WorkGroup number and | |
| ! then scale the geometry in each WorkGroup | |
| iCurWG = CURRENT_WG_NUMBER | |
| GET_WG_LIST | |
| iNumWG = NUMBER_OF_WGS ! save the current WG number | |
| LOCAL ListWG(iNumWG+1) ! in case there is only 1 WG, arrays size must be more than 1 | |
| GET_WG_LIST ListWG ! get a list of all WGs | |
| FOR i=1 TO iNumWG | |
| iWG = ListWG(i) | |
| SET_WG iWG ! select this WG | |
| select_all_geo ! select all geomtry in this WG | |
| scale_geo scale ! scale all geometry in this WG | |
| NEXT i | |
| SET_WG iCurWG ! reselect the current WG | |
| 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" |