Держи программулину.....
;;; One of the most common tasks in civil design is the conversion and
;;; inclusion of survey data into the drawing. This information is often in
;;; the form of a comma delimited ASCII file. It is not always presented in
;;; the same order o point number, northing, easting, elevation, description.
;;; It could be in a number of different combination. Keep in mind that a
;;; survey northing, easting combination corresponds to AutoCAD Y,X.
;;; ASCII_IN.LSP использует 6 различных форматов данных:
;;; P,N,E,Z,D номер точки,север,юг,Z,описание
;;; P,N,E,Z номер точки,север,юг,Z
;;; P,N,E номер точки,север,юг
;;; N,E север,юг
;;; N,E,Z,D север,юг,Z,описание
;;; X,Y,Z,D X,Y,Z,описание
;;; The program also allows you to preview the data file. This comes in
;;; handy if you forget what format the data is in. You won't have to leave
;;; the program in order to look at the data file.
;;; Another feature is that the program looks for a block within the
;;; drawing named ASCII_IN. This is the name of the attribute block used to
;;; insert the information into the drawing. If the block ASCII_IN is not
;;; in the drawing the program will create it. To change the point style
;;; use PDMODE.
;;; The program uses nested dialog boxes. This means that picking buttons
;;; on the first dialog box will display another one. Picking the button
;;; "Data File..." will display the standard R12 dialog box used to
;;; retrieve file names. Pick the "Format..." button to display a list of
;;; format options using radio buttons. The "Preview" button displays a
;;; list box showing the contents of the ASCII file.
;;; IMPORTANT!
;;; The program assumes that .ASC is the text file extension. You may
;;; change this in the file dialogue box.
;;; The current text style must be defined with the height = 0. Control the
;;; size by changing the scale in the dialogue box.
;;; The program will produce unpredictable results if you import using the
;;; wrong format. If you data is N,E,Z and you select a format that assumes
;;; the first piece of data to be a point number (P,N,E,Z) the program will
;;; use the Northing as the point number.
(DEFUN C:ASCII_IN ()
(SETVAR "attreq" 1)
(SETVAR "attdia" 0)
(SETVAR "cmdecho" 0)
(SETVAR "OSMODE" 0)
(IF (/= (CDR (ASSOC 40 (TBLSEARCH "STYLE" (GETVAR "TEXTSTYLE"))))0.0)
(ALERT "Текущий стиль текста должен быть определен с высотой = 0")
(PROGN
(COMMAND "_UNDO" "_M")
(SETQ format 1)
(SETQ v:do_it NIL)
(SETQ dcl_id (LOAD_DIALOG "ascii_in.dcl"))
(IF (NOT (NEW_DIALOG "ascii_in" dcl_id))(EXIT))
(SET_TILE "format_in" "P,N,E,Z,D")
(SET_TILE "error" "")
(SET_TILE "file_name" "Не определен")
(SET_TILE "scale" "1")
(ACTION_TILE "dataformat" "(GET_FORMAT)")
(ACTION_TILE "datafile" "(GET_FNAME)")
(ACTION_TILE "preview" "(SHOW_FILE)")
(ACTION_TILE "scale" "(CHK_SCALE)")
(ACTION_TILE "accept" "(CHK_VALUES)")
(START_DIALOG)
(UNLOAD_DIALOG dcl_id)
;(PRINT fname)
(IF v:do_it (IMPORT_ASCII))
)
)
(PRINC)
)
;;;=====================================
(DEFUN GET_FORMAT ()
(IF (NOT (NEW_DIALOG "format" dcl_id))(EXIT))
(SET_TILE "pnezd" "1")
(ACTION_TILE "accept" "(SET_FORMAT)")
(START_DIALOG)
)
(DEFUN SET_FORMAT ()
(SETQ format
(COND
((= (GET_TILE "pnezd") "1") 1)
((= (GET_TILE "pnez") "1") 2)
((= (GET_TILE "pne") "1") 3)
((= (GET_TILE "ne") "1") 4)
((= (GET_TILE "nezd") "1") 5)
((= (GET_TILE "xyzd") "1") 6)
)
)
(DONE_DIALOG)
(SET_TILE "format_in"
(COND
((= format 1) "P,N,E,Z,D")
((= format 2) "P,N,E,Z")
((= format 3) "P,N,E")
((= format 4) "N,E")
((= format 5) "N,E,Z,D")
((= format 6) "X,Y,Z,D")
)
)
)
;(DEFUN GET_FNAME (/ fname)
(DEFUN GET_FNAME ()
;;(IF (SETQ fname (GETFILED "ASCII File" "*" "ASC" 2))
(IF (SETQ fname (GETFILED "Файл данных" "" "*" 2))
(SET_TILE "file_name" fname)
)
)
(DEFUN CHK_SCALE ()
(IF (SETQ scale (DISTOF (GET_TILE "scale")))
(SET_TILE "error" "")
(PROGN
(SET_TILE "error" "Масштаб должен быть числом!")
(MODE_TILE "scale" 2)
)
)
)
(DEFUN SHOW_FILE ()
(IF (FINDFILE (GET_TILE "file_name"))
; (IF (FINDFILE fname))
(PROGN
(SETQ Q?0 (OPEN (GET_TILE "file_name") "r") Qj0())
(WHILE (SETQ Q@0 (READ-LINE Q?0))(SETQ Qj0 (CONS Q@0 Qj0)))
(SETQ Qj0 (REVERSE Qj0))
(SETQ Q?0 (CLOSE Q?0))
(IF (NOT (NEW_DIALOG "show_file" dcl_id))(EXIT))
(START_LIST "txt" 3)
(MAPCAR (QUOTE add_list) Qj0)
(END_LIST)
(ACTION_TILE "accept" "(done_dialog)")
(START_DIALOG)
)
(ALERT "Файл не найден!")
)
)
(DEFUN CHK_VALUES ()
(IF (= (GET_TILE "error") "")
(COND
((NOT (FINDFILE (GET_TILE "file_name"))) (ALERT "Файл не найден!"))
((/= (TYPE scale)(quote REAL)) (CHK_SCALE))
(T (SETQ V:DO_IT 1) (DONE_DIALOG))
)
)
)
(DEFUN IMPORT_ASCII (/ QQ0 Ql0)
(IF (NOT (TBLSEARCH "BLOCK" "ASCII_IN"))
(PROGN
(SETQ QQ0 (SSADD))
(COMMAND "_POINT" (GETVAR "VIEWCTR"))
(SSADD (ENTLAST) QQ0)
; (COMMAND "_ATTDEF" "" "НОМЕР" "" "" (LIST (+(CAR (GETVAR "VIEWCTR")) 1) (+ (CADR (GETVAR "viewctr")) 2)) 1.0 90)
; (SSADD (ENTLAST) QQ0)
(COMMAND "_ATTDEF" "" "ОПИСАНИЕ" "" "" (LIST (+ (CAR(GETVAR "VIEWCTR")) 1) (CADR (GETVAR "viewctr"))) 1.0 90)
(SSADD (ENTLAST) QQ0)
(COMMAND "_ATTDEF" "" "ОТМЕТКА" "" "" (LIST (+ (CAR (GETVAR "VIEWCTR"))1) (- (CADR (GETVAR"viewctr")) 2)) 1.0 90)
(SSADD (ENTLAST) QQ0)
(COMMAND "_BLOCK" "ASCII_IN" (GETVAR "VIEWCTR") QQ0 "")
)
)
(SETQ Ql0 1)
(PRINC "Ждите... ")
(FOREACH Q&0 Qj0 (PARSE_LIST Q&0 Ql0) (SETQ Ql0 (1+ Ql0)))
)
(DEFUN PARSE_LIST (Q@0 Ql0 /)
(SETQ Q10 1)
(SETQ Q#0 ())
(REPEAT
(STRLEN Q@0)
(IF (= (SUBSTR Q@0 Q10 1) ",")(SETQ Q#0(CONS Q10 Q#0)))
(SETQ Q10 (1+ Q10))
)
(SETQ Q#0 (REVERSE Q#0))
(COND
((= format 1)
(SETQ number (SUBSTR Q@0 1 (1- (NTH 0 Q#0)))
Q&0 (DISTOF (SUBSTR Q@0 (1+ (NTH 0 Q#0)) (1- (- (NTH 1 Q#0) (NTH 0 Q#0)))))
Q$0 (DISTOF (SUBSTR Q@0 (1+ (NTH 1 Q#0)) (1- (- (NTH 2 Q#0) (NTH 1 Q#0)))))
z_point (SUBSTR Q@0 (1+ (NTH 2 Q#0)) (1- (- (NTH 3 Q#0)(NTH 2 Q#0))))
descript (SUBSTR Q@0 (1+ (NTH 3 Q#0)))
)
(COMMAND "_INSERT" "ASCII_IN" (LIST Q$0 Q&0) scale "" 0 number descript z_point)
(WORKING)
)
((= format 2)
(SETQ number (SUBSTR Q@0 1(1-(NTH 0 Q#0)))
Q&0 (DISTOF (SUBSTR Q@0 (1+(NTH 0 Q#0))(1-(-(NTH 1 Q#0)(NTH 0 Q#0)))))
Q$0 (DISTOF (SUBSTR Q@0 (1+(NTH 1 Q#0))(1-(-(NTH 2 Q#0)(NTH 1 Q#0)))))
z_point (SUBSTR Q@0 (1+(NTH 2 Q#0))(1-(-(NTH 3 Q#0)(NTH 2 Q#0))))
descript " "
)
(COMMAND "_INSERT" "ASCII_IN" (LIST Q$0 Q&0) scale "" "" 0 number descript z_point)
(WORKING)
)
((= format 3)
(SETQ number (SUBSTR Q@0 1(1-(NTH 0 Q#0)))
Q&0 (DISTOF (SUBSTR Q@0 (1+(NTH 0 Q#0))(1-(-(NTH 1 Q#0)(NTH 0 Q#0)))))
Q$0 (DISTOF (SUBSTR Q@0 (1+(NTH 1 Q#0))(1-(-(NTH 2 Q#0)(NTH 1 Q#0)))))
z_point " "
descript " "
)
(COMMAND "_INSERT" "ASCII_IN" (LIST Q$0 Q&0) scale "" 0 number descript z_point)
(WORKING))
((= format 4)
(SETQ number (ITOA Ql0)
Q&0 (DISTOF (SUBSTR Q@0 1 (1-(NTH 0 Q#0))))
Q$0 (DISTOF (SUBSTR Q@0 (1+(NTH 0 Q#0))(1-(-(NTH 1 Q#0)(NTH 0 Q#0)))))
z_point " "
descript " "
)
(COMMAND "_INSERT" "ASCII_IN" (LIST Q$0 Q&0) scale "" 0 number descript z_point)
(WORKING))
((= format 5)
(SETQ number (ITOA Ql0)
Q&0 (DISTOF (SUBSTR Q@0 1(1-(NTH 0 Q#0))))
Q$0 (DISTOF (SUBSTR Q@0 (1+(NTH 0 Q#0))(1-(-(NTH 1 Q#0)(NTH 0 Q#0)))))
z_point (SUBSTR Q@0(1+(NTH 1 Q#0))(1-(-(NTH 2 Q#0)(NTH 1 Q#0))))
descript (SUBSTR Q@0(1+(NTH 2 Q#0)))
)
(COMMAND "_INSERT" "ASCII_IN" (LIST Q$0 Q&0) scale "" 0 number descript z_point)
(WORKING))
((= format 6)
(SETQ number (ITOA Ql0)
x_point (DISTOF (SUBSTR Q@0 1(1-(NTH 0 Q#0))))
y_point (DISTOF (SUBSTR Q@0 (1+(NTH 0 Q#0))(1-(-(NTH 1 Q#0)(NTH 0 Q#0)))))
z_point (SUBSTR Q@0(1+(NTH 1 Q#0))(1-(-(NTH 2 Q#0)(NTH 1 Q#0))))
z_point-real (ATOF z_point)
descript (SUBSTR Q@0(1+(NTH 2 Q#0)))
)
;; (COMMAND "_INSERT" "ASCII_IN" (LIST x_point y_point z_point-real) scale "" 0 number descript z_point)
(COMMAND "_INSERT" "ASCII_IN" (LIST x_point y_point z_point-real) scale "" 0 descript z_point)
(WORKING)
)
)
)
(DEFUN WORKING ()
(SETQ A# (IF A# A# 4))
(PRINC
(COND
((= (REM (SETQ A# (1+ A#)) 4) 0) "\010!")
((= (REM A# 4) 1) "\010/")
((= (REM A# 4) 2) "\010-")
(T "\010\\")
)
)
)
(PROMPT"\nВведите команду ASCII_IN для запуска.")
(PRIN1)
И диалог
// ASCII_IN.DCL
// Read an ASCII coordinate point file into a drawing.
// Fred R. Weaver (c) March, 1993
preview_button : retirement_button {
label = "Просмотр...";
key = "preview";
mnemonic = "П";
}
ok_cancel_preview : column {
: row {
fixed_width = true;
alignment = centered;
ok_button;
cancel_button;
preview_button;
}
}
ascii_in : dialog {
label = "Импорт данных";
: row {
: button {
label = "Файл данных...";
key = "datafile";
mnemonic = "д";
fixed_width = true;
}
: edit_box {
edit_width = 20;
key = "file_name";
fixed_width = true;
}
}
: row {
: edit_box {
label = "Масштаб";
edit_with = 2;
key = "scale";
mnemonic = "М";
}
: button {
label = "Формат...";
key = "dataformat";
mnemonic = "Ф";
fixed_width = true;
}
: text {
key = "format_in";
width = 9;
}
}
: errtile {
key = "error";
}
ok_cancel_preview;
}
show_file : dialog {
label = "Просмотр данных";
: list_box {
key = "txt";
height = 10;
width = 60;
}
ok_only;
}
format : dialog {
label = "Формат";
: radio_column {
: radio_button {
label = "P,N,E,Z,D";
key = "pnezd";
}
: radio_button {
label = "P,N,E,Z";
key = "pnez";
}
: radio_button {
label = "P,N,E";
key = "pne";
}
: radio_button {
label = "N,E";
key = "ne";
}
: radio_button {
label = "N,E,Z,D";
key = "nezd";
}
: radio_button {
label = "X,Y,Z,D";
key = "xyzd";
}
}
ok_only;
}