Calc Geo Extents: Difference between revisions
From Macros Wiki
Jump to navigationJump to search
No edit summary |
No edit summary |
||
| (One intermediate revision by the same user not shown) | |||
| Line 1: | Line 1: | ||
{| | {| | ||
|- | |- | ||
|! calculate the extents in X and Y of the selected geometry | |! calculate the extents in X and Y of the selected geometry | ||
|- | |- | ||
| | | | ||
|- | |- | ||
|a1$ = "This macro will calculate the extents" | |a1$ = "This macro will calculate the extents" | ||
| Line 9: | Line 9: | ||
|a2$ = "(min/max X and Y) of the selected geometry" | |a2$ = "(min/max X and Y) of the selected geometry" | ||
|- | |- | ||
| | | | ||
|- | |- | ||
|message "%a1$\n%a2$" | |message "%a1$\n%a2$" | ||
|- | |- | ||
| | | | ||
|- | |- | ||
|check part_open, "You must have a part open to run this macro" | |check part_open, "You must have a part open to run this macro" | ||
| Line 19: | Line 19: | ||
|check part_mill, "This macro is not designed for turned parts" | |check part_mill, "This macro is not designed for turned parts" | ||
|- | |- | ||
| | | | ||
|- | |- | ||
|global xmin, ymin, xmax,ymax ! these variables are used by all macros | |global xmin, ymin, xmax,ymax ! these variables are used by all macros | ||
| Line 25: | Line 25: | ||
|global ics | |global ics | ||
|- | |- | ||
| | | | ||
|- | |- | ||
|xmin=99999 | |xmin=99999 | ||
| Line 35: | Line 35: | ||
|ymax=-99999 | |ymax=-99999 | ||
|- | |- | ||
| | | | ||
|- | |- | ||
|! when we get the data for each feature, we can | |! when we get the data for each feature, we can | ||
|- | |- | ||
|! get the xyz values in either the world cs or | |! get the xyz values in either the world cs or | ||
|- | |- | ||
|! the cs local to each feature. | |! the cs local to each feature. | ||
|- | |- | ||
|trace on | |trace on | ||
| Line 47: | Line 47: | ||
|ics = 1 ! world cs (local cs would be zero) | |ics = 1 ! world cs (local cs would be zero) | ||
|- | |- | ||
| | | | ||
|- | |- | ||
|! get the number of selected features | |! get the number of selected features | ||
|- | |- | ||
|! ----------------------------------- | |! ----------------------------------- | ||
|- | |- | ||
| | | | ||
|- | |- | ||
|get_num_feat_selected inum | |get_num_feat_selected inum | ||
| Line 59: | Line 59: | ||
|if inum<1 then stop "No geometry selected" | |if inum<1 then stop "No geometry selected" | ||
|- | |- | ||
| | | | ||
|- | |- | ||
|! loop through all selected features and | |! loop through all selected features and | ||
|- | |- | ||
|! update the min/max xy data according | |! update the min/max xy data according | ||
|- | |- | ||
|! to each features xy data | |! to each features xy data | ||
|- | |- | ||
|! -------------------------------------- | |! -------------------------------------- | ||
|- | |- | ||
| | | | ||
|- | |- | ||
|for i=1 to inum | |for i=1 to inum | ||
| Line 75: | Line 75: | ||
| | | | ||
|} | |} | ||
:! get the feature reference number for | :! get the feature reference number for | ||
:! the 'i'th selected feature | :! the 'i'th selected feature | ||
:! ------------------------------------ | :! ------------------------------------ | ||
<br> | |||
:get_selected_geo_ref i, iref | :get_selected_geo_ref i, iref | ||
<br> | |||
:! get the feature type for this feature | |||
:! get the feature type for this feature | |||
:! ------------------------------------- | :! ------------------------------------- | ||
<br> | |||
:get_feat_type iref, itype | :get_feat_type iref, itype | ||
<br> | |||
debug i, iref, itype | |||
<br> | |||
:if itype=1 then call "[[Check_Point_Data|Check_Point_Data.mac]]" | :if itype=1 then call "[[Check_Point_Data|Check_Point_Data.mac]]" | ||
| Line 108: | Line 101: | ||
|next i | |next i | ||
|- | |- | ||
| | | | ||
|- | |- | ||
|! display the results | |! display the results | ||
|- | |- | ||
|! ------------------- | |! ------------------- | ||
|- | |- | ||
| | | | ||
|- | |- | ||
|xmin$=format$(xmin,"####0.0###") | |xmin$=format$(xmin,"####0.0###") | ||
| Line 124: | Line 117: | ||
|ymax$=format$(ymax,"####0.0###") | |ymax$=format$(ymax,"####0.0###") | ||
|- | |- | ||
| | | | ||
|- | |- | ||
|msg$="X Min = %xmin$\n" | |msg$="X Min = %xmin$\n" | ||
| Line 134: | Line 127: | ||
|msg$=msg$+"X Max = %ymax$" | |msg$=msg$+"X Max = %ymax$" | ||
|- | |- | ||
| | | | ||
|- | |- | ||
|message msg$, "Geometry Extents" | |message msg$, "Geometry Extents" | ||
|- | |- | ||
| | | | ||
|- | |- | ||
|yesno "Draw a rectangle around the geometry ?", iyesno | |yesno "Draw a rectangle around the geometry ?", iyesno | ||
|- | |- | ||
| | | | ||
|- | |- | ||
|if iyesno=0 then stop "Finished" | |if iyesno=0 then stop "Finished" | ||
|- | |- | ||
| | | | ||
|- | |- | ||
|contour[ | |contour[ | ||
| Line 162: | Line 155: | ||
|] | |] | ||
|- | |- | ||
| | | | ||
|- | |- | ||
|redraw | |redraw | ||
|- | |- | ||
| | | | ||
|- | |- | ||
|stop "Finished" | |stop "Finished" | ||
|- | |- | ||
|} | |} | ||
Latest revision as of 20:42, 29 July 2010
| ! 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 |
| xmin=99999 |
| ymin=99999 |
| xmax=-99999 |
| ymax=-99999 |
| ! 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 |
| ! ------------------- |
| xmin$=format$(xmin,"####0.0###") |
| ymin$=format$(ymin,"####0.0###") |
| xmax$=format$(xmax,"####0.0###") |
| ymax$=format$(ymax,"####0.0###") |
| 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" |
| contour[ |
| start xmin, ymin |
| line xmax, ymin |
| line xmax, ymax |
| line xmin, ymax |
| line xmin, ymin |
| ] |
| redraw |
| stop "Finished" |