home *** CD-ROM | disk | FTP | other *** search
/ Liren Large Software Subsidy 13 / 13.iso / p / p024 / 5.img / SUPPORT2.LIB / DDATTEXT.LSP < prev    next >
Encoding:
Text File  |  1993-02-08  |  11.6 KB  |  400 lines

  1. ;;;------------------------------------------------------------------------
  2. ;;;  DDATTEXT.LSP
  3. ;;;  ¬⌐┼v (C) 1992  Autodesk ñ╜Ñq
  4. ;;;
  5. ;;; Ñ╗│n┼ΘºK╢O¿╤▒z╢iªµÑ⌠ª≤Ñ╬│~╗▌¿D¬║½■¿⌐íB¡╫º∩ñ╬╡oªµ, ª²¼O░╚╜╨┐φ┤`ñU¡z
  6. ;;; ¡∞½h :
  7. ;;;
  8. ;;; 1)  ñWªC¬║¬⌐┼v│qºi░╚╗▌ÑX▓{ªb¿Cñ@Ñ≈½■¿⌐∙╪íC
  9. ;;; 2)  ¼█├÷¬║╗í⌐·ñσÑ≤ñ]Ñ▓╢╖⌐·╕ⁿ¬⌐┼v│qºiñ╬Ñ╗╢╡│\Ñi│qºiíC
  10. ;;;
  11. ;;; Ñ╗│n┼Θ╢╚┤ú¿╤º@¼░└│Ñ╬ñW¬║░╤ª╥, ª╙Ñ╝┴n⌐·⌐╬┴⌠ºtÑ⌠ª≤½O├╥; ╣∩⌐≤Ñ⌠ª≤»S«φ
  12. ;;; Ñ╬│~ñº╛A║┘⌐╩, ÑHñ╬░╙╖~╛P░Γ⌐╥┴⌠ºtÑX¿π¬║½O├╥, ªbª╣ñ@╖ºñ⌐ÑHº_╗{íC
  13. ;;;
  14. ;;;
  15. ;;;------------------------------------------------------------------------
  16. ;;;  DESCRIPTION
  17. ;;;
  18. ;;;  This is an enhancement to the ATTEXT command. It loads up a dialogue box
  19. ;;;  which presents to the user all the prompts and options that he/she
  20. ;;;  might encounter during the extraction of attributes.
  21. ;;;
  22. ;;;------------------------------------------------------------------------
  23. ;;;  Warning
  24. ;;;
  25. ;;;  The filenames are not turned into uppercase because unix files are
  26. ;;;  case sensitive.
  27. ;;;
  28. ;;;------------------------------------------------------------------------
  29. ;;;   Prefixes in command and keyword strings:
  30. ;;;      "."  specifies the built-in AutoCAD command in case it has been
  31. ;;;           redefined.
  32. ;;;      "_"  denotes an AutoCAD command or keyword in the native language
  33. ;;;           version, English.
  34. ;;;------------------------------------------------------------------------
  35. ;;;
  36. ;;;====================== load-time error checking ========================
  37.  
  38.   (defun ai_abort (app msg)
  39.      (defun *error* (s)
  40.         (if old_error (setq *error* old_error))
  41.         (princ)
  42.      )
  43.      (if msg
  44.        (alert (strcat " └│Ñ╬╡{ªí┐∙╗~: "
  45.                       app
  46.                       " \n\n  "
  47.                       msg
  48.                       "  \n"
  49.               )
  50.        )
  51.      )
  52.      (exit)
  53.   )
  54.  
  55. ;;; Check to see if AI_UTILS is loaded, If not, try to find it,
  56. ;;; and then try to load it.
  57. ;;;
  58. ;;; If it can't be found or it can't be loaded, then abort the
  59. ;;; loading of this file immediately, preserving the (autoload)
  60. ;;; stub function.
  61.  
  62.   (cond
  63.      (  (and ai_dcl (listp ai_dcl)))          ; it's already loaded.
  64.  
  65.      (  (not (findfile "ai_utils.lsp"))                     ; find it
  66.         (ai_abort "DDATTEXT"
  67.                   (strcat "ºΣñú¿∞íuAI_UTILS.LSPív└╔«╫;"
  68.                           "\n  ╜╨└╦¼díusupportívÑ╪┐²íC")))
  69.  
  70.      (  (eq "failed" (load "ai_utils" "failed"))            ; load it
  71.         (ai_abort "DDATTEXT" "╡L¬k╕ⁿñJíuAI_UTILS.LSPív└╔«╫"))
  72.   )
  73.  
  74.   (if (not (ai_acadapp))               ; defined in AI_UTILS.LSP
  75.       (ai_abort "DDATTEXT" nil)         ; a Nil <msg> supresses
  76.   )                                    ; ai_abort's alert box dialog.
  77.  
  78. ;;;===================== end load-time operations =========================
  79.  
  80. ;;;
  81. ;;; The main routine.
  82. ;;;
  83. (defun c:ddattext (/
  84.                   bit         ftype          out_ext        tile_name
  85.                   data        mod            out_file       title
  86.                   dcl_id      mode           out_or_temp    what_next
  87.                   ext         n              ss             which_file
  88.                   file        old_cmd        temp_file      fl
  89.                   file_name   old_error      temp_var       undo_init
  90.                   )
  91.   ;;
  92.   ;;  Get template file from file dialogue box.
  93.   ;;
  94.   (defun get_tfile (/ temp_var)
  95.     (if (setq temp_var
  96.           (getfiled "Template File" temp_file "txt" 2)
  97.       )
  98.       (progn
  99.         (setq temp_file temp_var)
  100.         (set_tile "temp_file" temp_file)
  101.       )
  102.     )
  103.   )
  104.   ;;
  105.   ;;  Gets output file from file dialogue box.
  106.   ;;
  107.   (defun get_ofile (/ temp_var)
  108.     (if (= ftype "DXF")
  109.       (setq out_ext "dxx")
  110.       (setq out_ext "txt")
  111.     )
  112.     (if (setq temp_var
  113.           (getfiled "Output File" out_file out_ext 3)
  114.         )
  115.       (progn
  116.         (setq out_file temp_var)
  117.         (set_tile "out_file" out_file)
  118.       )
  119.     )
  120.   )
  121.   ;;
  122.   ;;  Change the extension of the output file to the new extension
  123.   ;;  (either .TXT or .DXX).
  124.   ;;
  125.   (defun new_ext (file_name ext mode / n ch)
  126.     (setq n        2
  127.           out_file (substr file_name 1 1)
  128.     )
  129.     (mode_tile "temp_file" mode)
  130.     (mode_tile "select_temp_file" mode)
  131.     (while (and (/= ch ".") (/= ch ""))
  132.       (setq ch       (substr file_name n 1)
  133.             n        (1+ n)
  134.       )
  135.       (if (or (= ch ".") (= ch ""))
  136.         (setq out_file (strcat out_file "." ext))
  137.         (setq out_file (strcat out_file ch))
  138.       )
  139.     )
  140.     (set_tile "out_file" out_file)
  141.   )
  142.  
  143.   ;;
  144.   ;;  Remove extension of the output file (it's guaranteed to have one).
  145.   ;;
  146.   (defun rem_ext (which_file / n ch)
  147.     (setq n    2
  148.           file (substr which_file 1 1)
  149.     )
  150.     (while (/= ch ".")
  151.       (setq ch (substr which_file n 1)
  152.             n  (1+ n)
  153.       )
  154.       (if (= ch ".")
  155.         (setq file file)
  156.         (setq file (strcat file ch))
  157.       )
  158.     )
  159.   )
  160.   ;;
  161.   ;;  Test name of file for invalid name or extension.
  162.   ;;
  163.   (defun file_test (file_name tile_name)
  164.     (if (= tile_name "temp_file")
  165.       (setq ext "txt")
  166.       (if (= ftype "DXF")
  167.         (setq ext "dxx")
  168.         (setq ext "txt")
  169.       )
  170.     )
  171.     (cond
  172.       ((wcmatch file_name "*`.")
  173.         (setq file_name (strcat file_name ext))
  174.       )
  175.       ((or (= file_name "")(= file_name nil)) ; looks for empty file name
  176.         (set_tile "error" "íu└╔ªWív╡L«─íC")
  177.         (mode_tile tile_name 2)
  178.       )
  179.       ((and (wcmatch file_name "*`.*")
  180.            (not (wcmatch (strcase file_name) (strcat "*`." (strcase ext))))
  181.        )
  182.         (set_tile "error" (strcat "⌐╡ª∙└╔ªWº∩ª¿íu." ext "ív"))
  183.         (rem_ext file_name)
  184.         (setq file_name (strcat file "." ext))
  185.       )
  186.       ((not (wcmatch file_name "*`.*"))
  187.         (setq file_name (strcat file_name "." ext))
  188.       )
  189.       (T (set_tile "error" " "))
  190.     )
  191.     (set_tile tile_name file_name)
  192.     file_name                         ; return the file name
  193.   )
  194.   ;;
  195.   ;; Is the output file name valid.
  196.   ;;
  197.   (defun check_out()
  198.     (if (findfile out_file)
  199.       (if (not (out_exists))
  200.         (progn (mode_tile "out_file" 2) nil)
  201.         T
  202.       )
  203.       (progn
  204.         (setq data (open out_file "w"))
  205.         (if (not data)
  206.           (progn
  207.             (set_tile "error" "íu┐ΘÑX└╔ªWív╡L«─íC")
  208.             (mode_tile "out_file" 2)
  209.             nil                      ; return nil on error
  210.           )
  211.           (progn
  212.             (close data)
  213.             T
  214.           )
  215.         )
  216.       )
  217.     )
  218.   )
  219.  
  220.   ;;
  221.   ;;  Upon hitting Ok, checks validity of template file as well as output
  222.   ;;  file. Also checks that the template file and output file don't have
  223.   ;;  the same name. The ATTEXT command normally allows user to overwrite
  224.   ;;  the template file thus rendering the template file useless. This
  225.   ;;  will not let the user overwrite the template file under any
  226.   ;;  circumstance.
  227.   ;;
  228.   (defun accept ()
  229.     (cond
  230.       ;; Check the output file name.
  231.       ((= "" (setq out_file (file_test (get_tile "out_file") "out_file"))))
  232.  
  233.       ;; Check output file name for invalid characters.
  234.       ((wcmatch out_file "*[] `#`@`?`*`~`[`,`'!%^&()+={}|;\"<>]*")
  235.         (set_tile "error" "└╔ªWññª│╡L«─¬║íuªr▓┼ívíC")
  236.         (mode_tile "out_file" 2)
  237.       )
  238.  
  239.       ;; Check template file if not DXF.
  240.       ((not (check_template)))
  241.  
  242.       ;; Check if the output file name is valid.
  243.       ((and (= 1 fl)(not (check_out))))
  244.  
  245.       ;; If all the above is legit then quit.
  246.       (T (done_dialog 1))
  247.     )
  248.   )
  249.  
  250.   ;;
  251.   ;; Check fo the template file if not DXF.
  252.   ;;
  253.   (defun check_template()
  254.     (if (= ftype "DXF")
  255.       T                              ;  DXF does not care about the template.
  256.       (progn
  257.         (if (/= (strcase out_file) (strcase temp_file))
  258.           (progn
  259.             (setq temp_file (file_test (get_tile "temp_file") "temp_file"))
  260.             (if (not (findfile temp_file))
  261.               (progn
  262.                 (set_tile "error" "ºΣñú¿∞└╔«╫íC")
  263.                 (mode_tile "temp_file" 2)
  264.                 nil
  265.               )
  266.               T
  267.             )
  268.           )
  269.           (progn
  270.             (out_temp)
  271.             (mode_tile "out_file" 2)
  272.             nil
  273.           )
  274.         )
  275.       )
  276.     )
  277.   )
  278.  
  279.   ;;
  280.   ;; Reset the error tile.
  281.   ;;
  282.   (defun rs_error()
  283.     (set_tile "error" "")
  284.   )
  285.  
  286.   ;;
  287.   ;;  Alert dialogue, called on OK to get confirmation of overwriting File.
  288.   ;;  Return T if Overwrite and nil if Cancel.
  289.   ;;
  290.   (defun out_exists()
  291.     (if (not (new_dialog "out_exists" dcl_id)) (exit))
  292.     (action_tile "yes" "(done_dialog 2)")
  293.     (action_tile "cancel" "(done_dialog 0)")
  294.     (if (= (start_dialog) 2)  T (setq redefine nil))
  295.   )
  296.   ;;
  297.   ;;  Alert dialogue, called on OK to alert user that template file is about
  298.   ;;  to be overwritten by output file.
  299.   ;;
  300.   (defun out_temp()
  301.     (if (not (new_dialog "out_temp" dcl_id)) (exit))
  302.     (action_tile "yes" "(done_dialog 2)")
  303.     (if (= (start_dialog) 2)  T)
  304.   )
  305.   ;;
  306.   ;; Pop up the dialogue.
  307.   ;;
  308.   (defun ddattext_main()
  309.  
  310.     (setq what_next 2
  311.           ftype "CDF"
  312.           temp_file "")
  313.  
  314.     ;; main loop
  315.     ;;
  316.     (while (> what_next 1)
  317.       (if (not (new_dialog "ddattext" dcl_id))
  318.         (exit)
  319.       )
  320.  
  321.       (set_tile "cdf" "1")
  322.  
  323.       (if (not temp_file) (setq temp_file ""))
  324.       (set_tile "temp_file" temp_file)
  325.  
  326.       (if (not out_file)
  327.         (setq out_file (strcat (getvar "dwgname") ".txt"))
  328.       )
  329.       (set_tile "out_file" out_file)
  330.  
  331.       (set_tile "how_many" (if ss
  332.                              (itoa (sslength ss))
  333.                              (eval "0")
  334.                            )
  335.       )
  336.  
  337.       (action_tile "cdf" "(setq ftype \"CDF\")(new_ext out_file \"txt\" 0)")
  338.       (action_tile "sdf" "(setq ftype \"SDF\")(new_ext out_file \"txt\" 0)")
  339.       (action_tile "dxf" "(setq ftype \"DXF\")(new_ext out_file \"dxx\" 1)")
  340.       (action_tile "selobjs" "(done_dialog 2)")
  341.       (action_tile "temp_file" "(rs_error)(setq temp_file $value)")
  342.       (action_tile "select_temp_file" "(rs_error)(get_tfile)")
  343.       (action_tile "out_file" "(rs_error)(setq fl 1)(setq out_file $value)")
  344.       (action_tile "select_out_file" "(rs_error)(setq fl 0)(get_ofile)")
  345.       (action_tile "accept" "(accept)")
  346.       (action_tile "cancel" "(done_dialog 0)")
  347.       (action_tile "help" "(acad_helpdlg \"acad.hlp\" \"ddattext\")")
  348.       (setq what_next (start_dialog))
  349.       (cond
  350.         ((= what_next 2)
  351.           (prompt "\n┐∩╛▄¬½┼Θ: ")
  352.           (setq ss (ssget))
  353.         )
  354.       )
  355.     )      ; end while loop
  356.  
  357.     (if (= what_next 1)
  358.       (progn
  359.         (rem_ext out_file)
  360.         (command "_.attext")
  361.         (cond
  362.           (ss)
  363.           (command "_e" ss "")
  364.         )
  365.         (if (= ftype "DXF")
  366.           (command (substr ftype 1 1) file)
  367.           (command (substr ftype 1 1) temp_file file)
  368.         )
  369.       )
  370.     )
  371.   )
  372.  
  373.   ;; Set up error function.
  374.   (setq old_cmd (getvar "cmdecho")    ; save current setting of cmdecho
  375.         old_error  *error*            ; save current error function
  376.         *error* ai_error              ; new error function
  377.   )
  378.  
  379.   (setvar "cmdecho" 0)
  380.  
  381.   (cond
  382.      (  (not (ai_notrans)))                        ; transparent not OK
  383.      (  (not (ai_acadapp)))                      ; ACADAPP.EXP xloaded?
  384.      (  (not (setq dcl_id (ai_dcl "ddattext"))))  ; is .DCL file loaded?
  385.      (T (ai_undo_push)
  386.         (ddattext_main)                          ; proceed!
  387.         (ai_undo_pop)
  388.      )
  389.   )
  390.  
  391.   (setq *error* old_error)
  392.   (setvar "cmdecho" old_cmd)
  393.  
  394.   (princ)
  395. )
  396.  
  397. ;;;-----------------------------------------------------------------------
  398. (princ "  íuDDATTEXTívñw╕ⁿñJíC")
  399. (princ)
  400.