Print Geo Data To File: Difference between revisions

From Macros Wiki
Jump to navigationJump to search
ConnerO (talk | contribs)
New page: ! print data from selected geometry to a file<br> <br> a1$ = "This macro look at the selected geometry and"<br> a2$ = "print the data for that geometry to a text file,"<br> a3$ = "with the...
 
ConnerO (talk | contribs)
No edit summary
 
(3 intermediate revisions by the same user not shown)
Line 1: Line 1:
! print data from selected geometry to a file<br>
{|
|!&nbsp;&nbsp;&nbsp; print data from selected geometry to a file
|-
|&nbsp;
|-
|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."
|-
|&nbsp;
|-
|message "%a1$\n%a2$\n%a3$"
|-
|&nbsp;
|-
|check part_open, "You must have a part open to run this macro"
|-
|check part_mill, "This macro is not designed for turned parts"
|-
|&nbsp;
|-
|get_num_feat_selected inum
|-
|if inum<1 then stop "No geometry selected"
|-
|&nbsp;
|-
|!&nbsp;&nbsp;&nbsp;  create a file open dialog
|-
|!&nbsp;&nbsp;&nbsp;  -------------------------
|-
|&nbsp;
|-
|file_dialog_new "Select output filename"
|-
|file_dialog_extension "Text files (*.txt)", "txt"
|-
|file_dialog_extension "All files (*.*)", "*"
|-
|file_dialog_show save, f$
|-
|&nbsp;
|-
|!&nbsp;&nbsp;&nbsp;  open the file on unit 1 for writing
|-
|!&nbsp;&nbsp;&nbsp;  -----------------------------------
|-
|&nbsp;
|-
|file1_open=0
|-
|&nbsp;
|-
|file_open 1, f$, write
|-
|if FileError<>0 then goto file_error
|-
|&nbsp;
|-
|file1_open=1
|-
|&nbsp;
|-
|!&nbsp;&nbsp;&nbsp;  loop through all selected features and
|-
|!&nbsp;&nbsp;&nbsp;  update the min/max xy data according
|-
|!&nbsp;&nbsp;&nbsp;  to each features xy data
|-
|!&nbsp;&nbsp;&nbsp;  --------------------------------------
|-
|&nbsp;
|-
|!&nbsp;&nbsp;&nbsp;  try setting fmt$ to any of the next 3
|-
|!&nbsp;&nbsp;&nbsp;  to get different formatted numbers
|-
|&nbsp;
|-
|fmt$ = <nowiki>"+0.0~~"</nowiki>  || !&nbsp;&nbsp;&nbsp; output spaces in place of leading/trailing zeros
|-
|!&nbsp;&nbsp;&nbsp;fmt$ = "+###0.0##"  || !&nbsp;&nbsp;&nbsp; do not output leading/trailing zeros
|-
|!&nbsp;&nbsp;&nbsp;fmt$ = "+0000.000"  || !&nbsp;&nbsp;&nbsp; output leading/trailing zeros
|-
|&nbsp;
|}
for i=1 to inum
<br>
<br>
a1$ = "This macro look at the selected geometry and"<br>
:!&nbsp;&nbsp;&nbsp;  get the feature reference number for
a2$ = "print the data for that geometry to a text file,"<br>
:!&nbsp;&nbsp;&nbsp;  the 'i'th selected feature
a3$ = "with the filename selected by the user."<br>
:!&nbsp;&nbsp;&nbsp;  ------------------------------------
<br>
<br>
message "%a1$\n%a2$\n%a3$"<br>
:get_selected_geo_ref i, iref
<br>
<br>
check part_open, "You must have a part open to run this macro"<br>
:!&nbsp;&nbsp;&nbsp; get the feature type for this feature
check part_mill, "This macro is not designed for turned parts"<br>
:!&nbsp;&nbsp;&nbsp; -------------------------------------
<br>
get_num_feat_selected inum<br>
if inum<1 then stop "No geometry selected"<br>
<br>
!  create a file open dialog<br>
!  -------------------------<br>
<br>
file_dialog_new "Select output filename"<br>
file_dialog_extension "Text files (*.txt)", "txt"<br>
file_dialog_extension "All files (*.*)", "*"<br>
file_dialog_show save, f$<br>
<br>
!  open the file on unit 1 for writing<br>
!  -----------------------------------<br>
<br>
file1_open=0<br>
<br>
file_open 1, f$, write<br>
if FileError<>0 then goto file_error<br>
<br>
file1_open=1<br>
<br>
!  loop through all selected features and<br>
!  update the min/max xy data according<br>
!  to each features xy data<br>
!  --------------------------------------<br>
<br>
!  try setting fmt$ to any of the next 3<br>
!  to get different formatted numbers<br>
<br>
fmt$ = "+[[User:ConnerO|ConnerO]]0.0~~"    ! output spaces in place of leading/trailing zeros<br>
!fmt$ = "+###0.0##"  ! do not output leading/trailing zeros<br>
!fmt$ = "+0000.000"  ! output leading/trailing zeros<br>
<br>
<br>
for i=1 to inum<br>
<br>
!  get the feature reference number for<br>
!  the 'i'th selected feature<br>
!  ------------------------------------<br>
<br>
:get_selected_geo_ref i, iref<br>
<br>
!  get the feature type for this feature<br>
!  -------------------------------------<br>
<br>
<br>
:get_feat_type iref, itype
:get_feat_type iref, itype
Line 138: Line 182:
:if FileError<>0 then goto file_error
:if FileError<>0 then goto file_error
<br>
<br>
next i<br>
{|
<br>
|next i
file_close 1<br>
|-
if FileError<>0 then goto file_error<br>
|&nbsp;
<br>
|-
yesno "View the output ?", iyesno<br>
|file_close 1
if iyesno = 0 then stop "Finished"<br>
|-
<br>
|if FileError<>0 then goto file_error
run_exe "\Windows\System32\Notepad.exe", f$<br>
|-
<br>
|&nbsp;
stop "Finished"<br>
|-
<br>
|yesno "View the output ?", iyesno
<nowiki>:</nowiki>file_error<br>
|-
<br>
|if iyesno = 0 then stop "Finished"
ierr=FileError<br>
|-
<br>
|&nbsp;
if file_open=1 then file_close 1<br>
|-
<br>
|run_exe "\Windows\System32\Notepad.exe", f$
stop "File error, code = %FileError"<br>
|-
|&nbsp;
|-
|stop "Finished"
|-
|&nbsp;
|-
|<nowiki>:</nowiki>file_error
|-
|&nbsp;
|-
|ierr=FileError
|-
|&nbsp;
|-
|if file_open=1 then file_close 1
|-
|&nbsp;
|-
|stop "File error, code = %FileError"
|}

Latest revision as of 15:38, 29 July 2010

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