Print Geo Data To File
From Macros Wiki
| ! print data from selected geometry to a file | |
| a1$ = "This macro look at the selected geometry and" | |
| a2$ = "print the data for that geometry to a text file," | |
| a3$ = "with the filename selected by the user." | |
| message "%a1$\n%a2$\n%a3$" | |
| check part_open, "You must have a part open to run this macro" | |
| check part_mill, "This macro is not designed for turned parts" | |
| get_num_feat_selected inum | |
| if inum<1 then stop "No geometry selected" | |
| ! create a file open dialog | |
| ! ------------------------- | |
| file_dialog_new "Select output filename" | |
| file_dialog_extension "Text files (*.txt)", "txt" | |
| file_dialog_extension "All files (*.*)", "*" | |
| file_dialog_show save, f$ | |
| ! open the file on unit 1 for writing | |
| ! ----------------------------------- | |
| file1_open=0 | |
| file_open 1, f$, write | |
| if FileError<>0 then goto file_error | |
| file1_open=1 | |
| ! loop through all selected features and | |
| ! update the min/max xy data according | |
| ! to each features xy data | |
| ! -------------------------------------- | |
| ! try setting fmt$ to any of the next 3 | |
| ! to get different formatted numbers | |
| fmt$ = "+0.0~~" | ! output spaces in place of leading/trailing zeros |
| ! fmt$ = "+###0.0##" | ! do not output leading/trailing zeros |
| ! fmt$ = "+0000.000" | ! output leading/trailing zeros |
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
- if itype=1 then goto label_point
- if itype=2 then goto label_line
- if itype=3 then goto label_circle
- if itype=4 then goto label_arc
- continue
:label_point
- get_feat_start iref, 1, xs, ys, zs
- xs$ = format$(xs, fmt$)
- ys$ = format$(ys, fmt$)
- zs$ = format$(zs, fmt$)
- a$ = "Point X =%xs$ Y =%ys$ Z =%zs$"
- goto label_print
:label_line
- get_feat_start iref, 1, xs, ys, zs
- get_feat_end iref, 1, xe, ye, ze
- xs$ = format$(xs, fmt$)
- ys$ = format$(ys, fmt$)
- zs$ = format$(zs, fmt$)
- xe$ = format$(xe, fmt$)
- ye$ = format$(ye, fmt$)
- ze$ = format$(ze, fmt$)
- a$ = "Line Xs=%xs$ Ys=%ys$ Zs=%zs$"
- a$ = a$ + " Xe=%xe$ Ye=%ye$ Ze=%ze$"
- goto label_print
:label_circle
- get_circle_data iref, 1, rad, xc, yc, zc
- xc$ = format$(xs, fmt$)
- yc$ = format$(ys, fmt$)
- zc$ = format$(zs, fmt$)
- rr$ = format$(rad, fmt$)
- a$ = "Circle Xc=%xs$ Yc=%ys$ Zc=%zs$ R =%rr$"
- goto label_print
:label_arc
- get_feat_start iref, 1, xs, ys, zs
- get_feat_end iref, 1, xe, ye, ze
- get_arc_data iref, 1, rad, dir, xc, yc, zc
- xc$ = format$(xc, fmt$)
- yc$ = format$(yc, fmt$)
- zc$ = format$(zc, fmt$)
- xs$ = format$(xs, fmt$)
- ys$ = format$(ys, fmt$)
- zs$ = format$(zs, fmt$)
- xe$ = format$(xe, fmt$)
- ye$ = format$(ye, fmt$)
- ze$ = format$(ze, fmt$)
- rr$ = format$(rad, fmt$)
- a$="Arc CCW"
- if dir=1 then a$ = "Arc CW "
- a$ = a$ + " Xc=%xc$ Yc=%yc$ Zc=%zc$ R =%rr$"
- a$ = a$ + "\n Xs=%xs$ Ys=%ys$ Zs=%zs$"
- a$ = a$ + " Xe=%xe$ Ye=%ye$ Ze=%ze$"
- Goto label_print
:label_print
- file_write_text 1, a$
- if FileError<>0 then goto file_error
| next i |
| file_close 1 |
| if FileError<>0 then goto file_error |
| yesno "View the output ?", iyesno |
| if iyesno = 0 then stop "Finished" |
| run_exe "\Windows\System32\Notepad.exe", f$ |
| stop "Finished" |
| :file_error |
| ierr=FileError |
| if file_open=1 then file_close 1 |
| stop "File error, code = %FileError" |