Inch Metric: Difference between revisions

From Macros Wiki
Jump to navigationJump to search
ConnerO (talk | contribs)
New page: ! change current part units from inch to metric<br> ! or metric to inch, ie swap the current units<br> <br> a1$ = "This macro will change the units of the current part"<br> a2$ = "from inc...
 
No edit summary
 
(3 intermediate revisions by 2 users not shown)
Line 1: Line 1:
! change current part units from inch to metric<br>
{|
! or metric to inch, ie swap the current units<br>
|!&nbsp;&nbsp;&nbsp; change current part units from inch to metric
<br>
|-
a1$ = "This macro will change the units of the current part"<br>
|!&nbsp;&nbsp;&nbsp; or metric to inch, ie swap the current units
a2$ = "from inch to metric, or metric to inch, scaling the"<br>
|-
a3$ = "geometry and solids accordingly"<br>
|&nbsp;
<br>
|-
message "%a1$\n%a2$\n%a3$"<br>
|a1$ = "This macro will change the units of the current part"
<br>
|-
check part_open, "You must have a part open to run this macro"<br>
|a2$ = "from inch to metric, or metric to inch, scaling the"
<br>
|-
get_part_data units, iunits<br>
|a3$ = "geometry and solids accordingly"
<br>
|-
if iunits=1 then goto inch<br>
|&nbsp;
<br>
|-
yesno "This part is Metric, Do you want to convert it to Inch ?", iyesno, "Inch Metric Macro"<br>
|message "%a1$\n%a2$\n%a3$"
if iyesno=0 then stop "Finished - no action taken"<br>
|-
<br>
|&nbsp;
! convert from metric to inch<br>
|-
! ---------------------------<br>
|check part_open, "You must have a part open to run this macro"
<br>
|-
scale = 1/25.4<br>
|&nbsp;
iunits= 1<br>
|-
<br>
|get_part_data units, iunits
goto scale<br>
|-
<br>
|&nbsp;
! convert from inch to metric<br>
|-
! ---------------------------<br>
|if iunits=1 then goto inch
<br>
|-
<nowiki>:</nowiki>inch
|&nbsp;
scale = 25.4<br>
|-
iunits= 0<br>
|yesno "This part is Metric, Do you want to convert it to Inch ?", iyesno, "Inch Metric Macro"
<br>
|-
<nowiki>:</nowiki>scale<br>
|if iyesno=0 then stop "Finished - no action taken"
<br>
|-
set_part_data units, iunits  &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;  ! change the part units<br>
|&nbsp;
<br>
|-
! any solids will have been scaled by changing the<br>
|!&nbsp;&nbsp;&nbsp; convert from metric to inch
! part units, now scale the geometry<br>
|-
<br>
|!&nbsp;&nbsp;&nbsp; ---------------------------
select_all_geo<br>
|-
scale_geo scale<br>
|&nbsp;
<br>
|-
yesno "Scale the stock ?", iyesno, "Inch Metric Macro"<br>
|scale = 1/25.4
if iyesno=0 then redraw<br>
|-
if iyesno=0 then stop "Finished - stock size not changed"<br>
|iunits= 1
<br>
|-
! get the current stock<br>
|&nbsp;
! ---------------------<br>
|-
<br>
|goto scale
get_part_data stock_x1, x1<br>
|-
get_part_data stock_y1, y1<br>
|&nbsp;
get_part_data stock_z1, z1<br>
|-
get_part_data stock_x2, x2<br>
|!&nbsp;&nbsp;&nbsp; convert from inch to metric
get_part_data stock_y2, y2<br>
|-
get_part_data stock_z2, z2<br>
|!&nbsp;&nbsp;&nbsp; ---------------------------
<br>
|-
!get_part_data stock_z1, z1  &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;    ! you would use these variables<br>
|&nbsp;
!get_part_data stock_z2, z2  &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;   ! for a turned part<br>
|-
!get_part_data stock_rad, rr<br>
|<nowiki>:</nowiki>inch
<br>
|-
! change the current stock<br>
|scale = 25.4
! ------------------------<br>
|-
<br>
|iunits= 0
set_part_data stock_x1, x1*scale<br>
|-
set_part_data stock_y1, y1*scale<br>
|&nbsp;
set_part_data stock_z1, z1*scale<br>
|-
set_part_data stock_x2, x2*scale<br>
|<nowiki>:</nowiki>scale
set_part_data stock_y2, y2*scale<br>
|-
set_part_data stock_z2, z2*scale<br>
|&nbsp;
<br>
|-
!get_part_data stock_z1, z1  &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;   ! you would use these variables<br>
|set_part_data units, iunits  ||  !&nbsp;&nbsp;&nbsp; change the part units
!get_part_data stock_z2, z2  &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;   ! for a turned part<br>
|-
!get_part_data stock_rad, rr<br>
|&nbsp;
<br>
|-
zoom_view 0<br>
|!&nbsp;&nbsp;&nbsp; any solids will have been scaled by changing the
<br>
|-
message "Finished"<br>
|!&nbsp;&nbsp;&nbsp; part units, now scale the geometry
|-
|&nbsp;
|-
|!&nbsp;&nbsp;&nbsp; get the current WorkGroup number and
|-
|!&nbsp;&nbsp;&nbsp; then scale the geometry in each WorkGroup
|-
|&nbsp;
|-
|iCurWG = CURRENT_WG_NUMBER
|-
|&nbsp;
|-
|GET_WG_LIST
|-
|iNumWG = NUMBER_OF_WGS  ! save the current WG number
|-
|&nbsp;
|-
|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
|-
|&nbsp;
|-
|FOR i=1 TO iNumWG
|-
|&nbsp;&nbsp;&nbsp; iWG = ListWG(i)
|-
|&nbsp;
|-
|&nbsp;&nbsp;&nbsp; SET_WG iWG            ! select this WG
|-
|&nbsp;
|-
|&nbsp;&nbsp;&nbsp; select_all_geo       ! select all geomtry in this WG
|-
|&nbsp;&nbsp;&nbsp; scale_geo scale       ! scale all geometry in this WG
|-
|NEXT i
|-
|&nbsp;
|-
|SET_WG iCurWG            ! reselect the current WG
|-
|&nbsp;
|-
|yesno "Scale the stock ?", iyesno, "Inch Metric Macro"
|-
|if iyesno=0 then redraw
|-
|if iyesno=0 then stop "Finished - stock size not changed"
|-
|&nbsp;
|-
|!&nbsp;&nbsp;&nbsp; get the current stock
|-
|!&nbsp;&nbsp;&nbsp; ---------------------
|-
|&nbsp;
|-
|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
|-
|&nbsp;
|-
|!&nbsp;&nbsp;&nbsp;get_part_data stock_z1, z1  ||    !&nbsp;&nbsp;&nbsp; you would use these variables
|-
|!&nbsp;&nbsp;&nbsp;get_part_data stock_z2, z2  ||    !&nbsp;&nbsp;&nbsp; for a turned part
|-
|!&nbsp;&nbsp;&nbsp;get_part_data stock_rad, rr
|-
|&nbsp;
|-
|!&nbsp;&nbsp;&nbsp; change the current stock
|-
|!&nbsp;&nbsp;&nbsp; ------------------------
|-
|&nbsp;
|-
|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
|-
|&nbsp;
|-
|!&nbsp;&nbsp;&nbsp;get_part_data stock_z1, z1  ||    !&nbsp;&nbsp;&nbsp; you would use these variables
|-
|!&nbsp;&nbsp;&nbsp;get_part_data stock_z2, z2  ||    !&nbsp;&nbsp;&nbsp; for a turned part
|-
|!&nbsp;&nbsp;&nbsp;get_part_data stock_rad, rr
|-
|&nbsp;
|-
|zoom_view 0
|-
|&nbsp;
|-
|message "Finished"
|}

Latest revision as of 19:05, 4 December 2020

!    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"