home *** CD-ROM | disk | FTP | other *** search
/ Windows 95 v2.4 Fix / W95-v2.4fix.iso / ACADWIN / SUPPORT / DDATTEXT.LSP < prev    next >
Encoding:
Lisp/Scheme  |  1995-02-08  |  12.8 KB  |  413 lines

  1. ; Next available MSG number is    15 
  2. ; MODULE_ID DDATTEXT_LSP_
  3. ;;;
  4. ;;;    ddattext.lsp
  5. ;;;
  6. ;;;    Copyright (C) 1990, 1992, 1994 by Autodesk, Inc.
  7. ;;;
  8. ;;;    Permission to use, copy, modify, and distribute this software
  9. ;;;    for any purpose and without fee is hereby granted, provided
  10. ;;;    that the above copyright notice appears in all copies and
  11. ;;;    that both that copyright notice and the limited warranty and
  12. ;;;    restricted rights notice below appear in all supporting
  13. ;;;    documentation.
  14. ;;;
  15. ;;;    AUTODESK PROVIDES THIS PROGRAM "AS IS" AND WITH ALL FAULTS.
  16. ;;;    AUTODESK SPECIFICALLY DISCLAIMS ANY IMPLIED WARRANTY OF
  17. ;;;    MERCHANTABILITY OR FITNESS FOR A PARTICULAR USE.  AUTODESK, INC.
  18. ;;;    DOES NOT WARRANT THAT THE OPERATION OF THE PROGRAM WILL BE
  19. ;;;    UNINTERRUPTED OR ERROR FREE.
  20. ;;;
  21. ;;;    Use, duplication, or disclosure by the U.S. Government is subject to
  22. ;;;    restrictions set forth in FAR 52.227-19 (Commercial Computer
  23. ;;;    Software - Restricted Rights) and DFAR 252.227-7013(c)(1)(ii) 
  24. ;;;    (Rights in Technical Data and Computer Software), as applicable.
  25. ;;;
  26. ;;;.
  27. ;;;  DESCRIPTION
  28. ;;;
  29. ;;;  This is an enhancement to the ATTEXT command. It loads up a dialogue box
  30. ;;;  which presents to the user all the prompts and options that he/she
  31. ;;;  might encounter during the extraction of attributes.
  32. ;;;
  33. ;;;  Warning
  34. ;;;
  35. ;;;  The filenames are not turned into uppercase because unix files are 
  36. ;;;  case sensitive.
  37. ;;;
  38. ;;;   Prefixes in command and keyword strings: 
  39. ;;;      "."  specifies the built-in AutoCAD command in case it has been        
  40. ;;;           redefined.
  41. ;;;      "_"  denotes an AutoCAD command or keyword in the native language
  42. ;;;           version, English.
  43. ;;;
  44. ;;;====================== load-time error checking ========================
  45.  
  46.   (defun ai_abort (app msg)
  47.      (defun *error* (s)
  48.         (if old_error (setq *error* old_error))
  49.         (princ)
  50.      )
  51.      (if msg
  52.        (alert (strcat " Error en la aplicaci≤n: "
  53.                       app
  54.                       " \n\n  "
  55.                       msg
  56.                       "  \n"
  57.               )
  58.        )
  59.      )
  60.      (exit)
  61.   )
  62.  
  63. ;;; Check to see if AI_UTILS is loaded, If not, try to find it,
  64. ;;; and then try to load it.
  65. ;;;
  66. ;;; If it can't be found or it can't be loaded, then abort the
  67. ;;; loading of this file immediately, preserving the (autoload)
  68. ;;; stub function.
  69.  
  70.   (cond
  71.      (  (and ai_dcl (listp ai_dcl)))          ; it's already loaded.
  72.  
  73.      (  (not (findfile ;|MSG0|;"ai_utils.lsp"))                     ; find it
  74.         (ai_abort "DDATTEXT"
  75.                   (strcat "Imposible localizar el archivo AI_UTILS-LSP."
  76.                           "\n Compruebe el directorio de soporte.")))
  77.  
  78.      (  (eq ;|MSG0|;"failed" (load "ai_utils" ;|MSG0|;"failed"))            ; load it
  79.         (ai_abort "DDATTEXT" "Imposible cargar el archivo AI_UTILS.LSP"))
  80.   )
  81.  
  82.   (if (not (ai_acadapp))               ; defined in AI_UTILS.LSP
  83.       (ai_abort "DDATTEXT" nil)         ; a Nil <msg> supresses
  84.   )                                    ; ai_abort's alert box dialog.
  85.  
  86. ;;;===================== end load-time operations =========================
  87.  
  88. ;;;
  89. ;;; The main routine.
  90. ;;;
  91. (defun c:ddattext (/ 
  92.                   bit         ftype          out_ext        tile_name
  93.                   data        mod            out_file       title
  94.                   dcl_id      mode           out_or_temp    what_next
  95.                   ext         n              ss             which_file
  96.                   file        old_cmd        temp_file      fl
  97.                   file_name   old_error      temp_var       undo_init
  98.                   )
  99.   ;;
  100.   ;;  Get template file from file dialogue box.
  101.   ;;
  102.   (defun get_tfile (/ temp_var)
  103.     (if (setq temp_var 
  104.           (getfiled "Archivo de plantilla" temp_file ;|MSG0|;"txt" 2)
  105.       )
  106.       (progn
  107.         (setq temp_file temp_var)
  108.         (set_tile ;|MSG0|;"temp_file" temp_file)
  109.       )
  110.     )
  111.   )
  112.   ;;
  113.   ;;  Gets output file from file dialogue box.
  114.   ;;
  115.   (defun get_ofile (/ temp_var)
  116.     (if (= ftype ;|MSG0|;"DXF")
  117.       (setq out_ext ;|MSG0|;"dxx")
  118.       (setq out_ext ;|MSG0|;"txt")
  119.     )
  120.     (if (setq temp_var 
  121.           (getfiled "Archivo de salida" out_file out_ext 3)
  122.         )
  123.       (progn
  124.         (setq out_file temp_var)
  125.         (set_tile ;|MSG0|;"out_file" out_file)
  126.       )
  127.     )
  128.   )
  129.   ;;
  130.   ;;  Change the extension of the output file to the new extension
  131.   ;;  (either .TXT or .DXX).
  132.   ;;
  133.   (defun new_ext (file_name ext mode / n ch)
  134.     (setq n        2
  135.           out_file (substr file_name 1 1)
  136.     )
  137.     (mode_tile ;|MSG0|;"temp_file" mode)
  138.     (mode_tile ;|MSG0|;"select_temp_file" mode)
  139.     (while (and (/= ch ".") (/= ch ""))
  140.       (setq ch       (substr file_name n 1)
  141.             n        (1+ n)
  142.       )
  143.       (if (or (= ch ".") (= ch ""))
  144.         (setq out_file (strcat out_file "." ext))
  145.         (setq out_file (strcat out_file ch))
  146.       )
  147.     )
  148.     (set_tile ;|MSG0|;"out_file" out_file)
  149.   )
  150.  
  151.   ;;
  152.   ;;  Remove extension of the output file (it's guaranteed to have one).
  153.   ;;
  154.   (defun rem_ext (which_file / n ch)
  155.     (setq n    2
  156.           file (substr which_file 1 1)
  157.     )
  158.     (while (/= ch ".")
  159.       (setq ch (substr which_file n 1)          
  160.             n  (1+ n)
  161.       )
  162.       (if (= ch ".")
  163.         (setq file file)
  164.         (setq file (strcat file ch))
  165.       )
  166.     )
  167.   )
  168.   ;;
  169.   ;;  Test name of file for invalid name or extension.
  170.   ;;
  171.   (defun file_test (file_name tile_name)
  172.     (if (= tile_name ;|MSG0|;"temp_file")
  173.       (setq ext ;|MSG0|;"txt")
  174.       (if (= ftype ;|MSG0|;"DXF")
  175.         (setq ext ;|MSG0|;"dxx")
  176.         (setq ext ;|MSG0|;"txt")
  177.       )
  178.     )
  179.     (cond
  180.       ((wcmatch file_name "*`.")
  181.         (setq file_name (strcat file_name ext))
  182.       )
  183.       ((or (= file_name "")(= file_name nil)) ; looks for empty file name
  184.         (set_tile "error" "Nombre de archivo no vßlido.")
  185.         (mode_tile tile_name 2)
  186.       )
  187.       ((and (wcmatch file_name "*`.*")
  188.            (not (wcmatch (strcase file_name) (strcat "*`." (strcase ext))))
  189.        )
  190.         (set_tile "error" (strcat "Extensi≤n cambiada a ." ext))
  191.         (rem_ext file_name)
  192.         (setq file_name (strcat file "." ext))
  193.       )
  194.       ((not (wcmatch file_name "*`.*"))
  195.         (setq file_name (strcat file_name "." ext))
  196.       )
  197.       (T (set_tile "error" " "))
  198.     )
  199.     (set_tile tile_name file_name)
  200.     file_name                         ; return the file name 
  201.   )
  202.   ;;
  203.   ;; Is the output file name valid.
  204.   ;; 
  205.   (defun check_out()
  206.     (if (findfile out_file)
  207.       (if (not (out_exists))
  208.         (progn (mode_tile ;|MSG0|;"out_file" 2) nil)
  209.         T
  210.       )
  211.       (progn
  212.         (setq data (open out_file ;|MSG0|;"w"))
  213.         (if (not data)
  214.           (progn
  215.             (set_tile "error" "Nombre del archivo de salida no vßlido.")
  216.             (mode_tile ;|MSG0|;"out_file" 2)
  217.             nil                      ; return nil on error
  218.           )
  219.           (progn
  220.             (close data)
  221.             T
  222.           )
  223.         )
  224.       )
  225.     )
  226.   )
  227.  
  228.   ;;
  229.   ;;  Upon hitting Ok, checks validity of template file as well as output
  230.   ;;  file. Also checks that the template file and output file don't have
  231.   ;;  the same name. The ATTEXT command normally allows user to overwrite
  232.   ;;  the template file thus rendering the template file useless. This
  233.   ;;  will not let the user overwrite the template file under any
  234.   ;;  circumstance.
  235.   ;;
  236.   (defun accept () 
  237.     (cond
  238.       ;; Check the output file name.
  239.       ((= "" (setq out_file (file_test (get_tile ;|MSG0|;"out_file") ;|MSG0|;"out_file"))))
  240.  
  241.       ;; Check output file name for invalid characters.
  242.       ((wcmatch out_file ;|MSG0|;"*[] `#`@`?`*`~`[`,`'!%^&()+={}|;\"<>]*")
  243.         (set_tile "error" "Carßcter no vßlido en el nombre de archivo.")
  244.         (mode_tile ;|MSG0|;"out_file" 2)
  245.       )
  246.  
  247.       ;; Check template file if not DXF.
  248.       ((not (check_template)))
  249.  
  250.       ;; Check if the output file name is valid.
  251.       ((and (= 1 fl)(not (check_out))))
  252.  
  253.       ;; If all the above is legit then quit.
  254.       (T (done_dialog 1))
  255.     )
  256.   )
  257.  
  258.   ;;
  259.   ;; Check fo the template file if not DXF.
  260.   ;;
  261.   (defun check_template()     
  262.     (if (= ftype ;|MSG0|;"DXF")
  263.       T                              ;  DXF does not care about the template.
  264.       (progn
  265.         (if (/= (strcase out_file) (strcase temp_file))
  266.           (progn
  267.             (setq temp_file (file_test (get_tile ;|MSG0|;"temp_file") ;|MSG0|;"temp_file"))
  268.             (if (not (findfile temp_file))
  269.               (progn
  270.                 (set_tile "error" "Archivo no encontrado.")
  271.                 (mode_tile ;|MSG0|;"temp_file" 2)
  272.                 nil
  273.               )
  274.               T
  275.             )
  276.           )
  277.           (progn
  278.             (out_temp)
  279.             (mode_tile ;|MSG0|;"out_file" 2)
  280.             nil
  281.           )
  282.         )
  283.       )
  284.     )
  285.   )
  286.  
  287.   ;;
  288.   ;; Reset the error tile.
  289.   ;;
  290.   (defun rs_error()
  291.     (set_tile "error" "")
  292.   )
  293.  
  294.   ;;
  295.   ;;  Alert dialogue, called on OK to get confirmation of overwriting File.
  296.   ;;  Return T if Overwrite and nil if Cancel.
  297.   ;;
  298.   (defun out_exists()
  299.     (if (not (new_dialog ;|MSG0|;"out_exists" dcl_id)) (exit))
  300.     (action_tile "yes" "(done_dialog 2)")
  301.     (action_tile "cancel" "(done_dialog 0)")
  302.     (if (= (start_dialog) 2)  T (setq redefine nil))
  303.   )
  304.   ;;
  305.   ;;  Alert dialogue, called on OK to alert user that template file is about
  306.   ;;  to be overwritten by output file.
  307.   ;;
  308.   (defun out_temp()
  309.     (if (not (new_dialog ;|MSG0|;"out_temp" dcl_id)) (exit))
  310.     (action_tile "yes" "(done_dialog 2)")
  311.     (if (= (start_dialog) 2)  T)
  312.   )
  313.   ;; 
  314.   ;; Pop up the dialogue.
  315.   ;;
  316.   (defun ddattext_main()
  317.  
  318.     (setq what_next 2
  319.           ftype ;|MSG0|;"CDF"
  320.           temp_file "")
  321.  
  322.     ;; main loop
  323.     ;;
  324.     (while (> what_next 1)
  325.       (if (not (new_dialog ;|MSG0|;"ddattext" dcl_id))
  326.         (exit)
  327.       )
  328.       (cond 
  329.         ((= ;|MSG0|;"CDF" ftype) (set_tile ;|MSG0|;"cdf" "1"))
  330.         ((= ;|MSG0|;"SDF" ftype) (set_tile ;|MSG0|;"sdf" "1"))
  331.         ((= ;|MSG0|;"DXF" ftype) (set_tile ;|MSG0|;"dxf" "1"))
  332.           (mode_tile ;|MSG0|;"temp_file" 1)
  333.           (mode_tile ;|MSG0|;"select_temp_file" 1)
  334.         ((T) (set_tile ;|MSG0|;"cdf" "1"))
  335.       )
  336.       (if (not temp_file) (setq temp_file ""))
  337.       (set_tile ;|MSG0|;"temp_file" temp_file)
  338.  
  339.       (if (not out_file)
  340.         (setq out_file (strcat (getvar "dwgname") ;|MSG0|;".txt"))
  341.       )
  342.       (set_tile ;|MSG0|;"out_file" out_file)
  343.  
  344.       (set_tile ;|MSG0|;"how_many" (if ss 
  345.                              (itoa (sslength ss))
  346.                              (eval "0")
  347.                            )
  348.       )
  349.  
  350.       (action_tile ;|MSG0|;"cdf" "(setq ftype \"CDF\")(new_ext out_file \"txt\" 0)")
  351.       (action_tile ;|MSG0|;"sdf" "(setq ftype \"SDF\")(new_ext out_file \"txt\" 0)")
  352.       (action_tile ;|MSG0|;"dxf" "(setq ftype \"DXF\")(new_ext out_file \"dxx\" 1)")
  353.       (action_tile ;|MSG0|;"selobjs" "(done_dialog 2)")
  354.       (action_tile ;|MSG0|;"temp_file" "(rs_error)(setq temp_file $value)")
  355.       (action_tile ;|MSG0|;"select_temp_file" "(rs_error)(get_tfile)")
  356.       (action_tile ;|MSG0|;"out_file" "(rs_error)(setq fl 1)(setq out_file $value)")
  357.       (action_tile ;|MSG0|;"select_out_file" "(rs_error)(setq fl 0)(get_ofile)")
  358.       (action_tile ;|MSG0|;"accept" "(accept)")
  359.       (action_tile ;|MSG0|;"cancel" "(done_dialog 0)")
  360.       (action_tile ;|MSG0|;"help" "(help \"\" \"ddattext\")")
  361.       (setq what_next (start_dialog))
  362.       (cond
  363.         ((= what_next 2)
  364.           (prompt "\nDesigne objetos: ")
  365.           (setq ss (ssget))
  366.         )
  367.       )
  368.     )      ; end while loop
  369.  
  370.     (if (= what_next 1)
  371.       (progn
  372.         (rem_ext out_file)
  373.         (command "_.attext")
  374.         (if ss
  375.           (command "_e" ss "")
  376.         )
  377.         (if (= ftype ;|MSG0|;"DXF")        
  378.           (command (strcat "_" (substr ftype 1 1)) file)
  379.           (command (strcat "_" (substr ftype 1 1)) temp_file file)
  380.         )
  381.       )
  382.     )
  383.   )
  384.  
  385.   ;; Set up error function.
  386.   (setq old_cmd (getvar "cmdecho")    ; save current setting of cmdecho
  387.         old_error  *error*            ; save current error function
  388.         *error* ai_error              ; new error function
  389.   )
  390.  
  391.   (setvar "cmdecho" 0)
  392.  
  393.   (cond
  394.      (  (not (ai_notrans)))                        ; transparent not OK
  395.      (  (not (ai_acadapp)))                      ; ACADAPP.EXP xloaded?
  396.      (  (not (setq dcl_id (ai_dcl ;|MSG0|;"ddattext"))))  ; is .DCL file loaded?
  397.      (T (ai_undo_push)
  398.         (ddattext_main)                          ; proceed!
  399.         (ai_undo_pop)
  400.      )
  401.   )
  402.  
  403.   (setq *error* old_error) 
  404.   (setvar "cmdecho" old_cmd)
  405.  
  406.   (princ)
  407. )
  408.  
  409. ;;;-----------------------------------------------------------------------
  410. (princ "  DDATTEXT cargada.")
  411. (princ)
  412.  
  413.