Calc Geo Extents

From Macros Wiki
Jump to: navigation, search
!    calculate the extents in X and Y of the selected geometry
a1$ = "This macro will calculate the extents"
a2$ = "(min/max X and Y) of the selected geometry"
message "%a1$\n%a2$"
check part_open, "You must have a part open to run this macro"
check part_mill, "This macro is not designed for turned parts"
global xmin, ymin, xmax,ymax ! these variables are used by all macros
global ics
!    when we get the data for each feature, we can
!    get the xyz values in either the world cs or
!    the cs local to each feature.
trace on
ics = 1  ! world cs (local cs would be zero)
!    get the number of selected features
!    -----------------------------------
get_num_feat_selected inum
if inum<1 then stop "No geometry selected"
!    loop through all selected features and
!    update the min/max xy data according
!    to each features xy data
!    --------------------------------------
for i=1 to inum
!    get the feature reference number for
!    the 'i'th selected feature
!    ------------------------------------

get_selected_geo_ref i, iref

!    get the feature type for this feature
!    -------------------------------------

get_feat_type iref, itype

debug i, iref, itype

if itype=1 then call "Check_Point_Data.mac"
if itype=2 then call "Check_Line_Data.mac"
if itype=3 then call "Check_Circle_Data.mac"
if itype=4 then call "Check_Arc_Data.mac"
next i
!    display the results
!    -------------------
msg$="X Min = %xmin$\n"
msg$=msg$+"Y Min = %ymin$\n"
msg$=msg$+"X Max = %xmax$\n"
msg$=msg$+"X Max = %ymax$"
message msg$, "Geometry Extents"
yesno "Draw a rectangle around the geometry ?", iyesno
if iyesno=0 then stop "Finished"
start xmin, ymin
line xmax, ymin
line xmax, ymax
line xmin, ymax
line xmin, ymin
stop "Finished"