home *** CD-ROM | disk | FTP | other *** search
/ Liren Large Software Subsidy 13 / 13.iso / p / p024 / 5.img / R11SUPP.EXE / ASCTEXT.LSP < prev    next >
Encoding:
Lisp/Scheme  |  1990-10-08  |  12.1 KB  |  404 lines

  1. ;;; --------------------------------------------------------------------------;
  2. ;;; ASCTEXT.LSP
  3. ;;;   Copyright (C) 1990 by Autodesk, Inc.
  4. ;;;  
  5. ;;;   Permission to use, copy, modify, and distribute this software and its
  6. ;;;   documentation for any purpose and without fee is hereby granted.  
  7. ;;;
  8. ;;;   THIS SOFTWARE IS PROVIDED "AS IS" WITHOUT EXPRESS OR IMPLIED WARRANTY. 
  9. ;;;   ALL IMPLIED WARRANTIES OF FITNESS FOR ANY PARTICULAR PURPOSE AND OF 
  10. ;;;   MERCHANTABILITY ARE HEREBY DISCLAIMED.
  11. ;;;
  12. ;;;   By Simon Jones  Autodesk Ltd, London  4 July 1986
  13. ;;;
  14. ;;;   Modified for use with AutoCAD 2.6           23 April 1987
  15. ;;;   REformatted and updated for AutoCAD Rell 11     July 1990
  16. ;;; --------------------------------------------------------------------------;
  17. ;;; DESCRIPTION
  18. ;;;
  19. ;;;   Use ASCTEXT.LSP to insert ASCII text files into AutoCAD drawings.
  20. ;;;   The blocks of text can be either Left, Center, Middle or Right
  21. ;;;   Justified.
  22. ;;;   The file name must include an extension and may include a
  23. ;;;   directory prefix, as in /acad/sample.txt or \\acad\\sample.txt.
  24. ;;;   Apart from height (unless fixed) & rotational angle,
  25. ;;;   "Text options" include:
  26. ;;;       Define distance between lines.
  27. ;;;       Define opening line for reading.
  28. ;;;       Define number of lines to read.
  29. ;;;       Global under/overscoring of lines.
  30. ;;;       Global upper/lower case change.
  31. ;;;    &  Column definitions.
  32. ;;;
  33. ;;; --------------------------------------------------------------------------;
  34. ;;;
  35. ;;; --------: GLOBAL variables
  36. ;;;  at_ang    : Last angle (for default value)
  37. ;;;  at_fnm    : Last file  (for default value)
  38. ;;;  rtfile : Read File
  39. ;;;  ang    : Rotation angle
  40. ;;;  c      : Total line count
  41. ;;;  cd     : Column distance
  42. ;;;  d      : Distance between lines
  43. ;;;  eof    : End of file flag
  44. ;;;  l1     : First line to read
  45. ;;;  h      : Text height
  46. ;;;  j      : Text justification
  47. ;;;  lc     : Column line count
  48. ;;;  n      : Number of lines to read
  49. ;;;  nl     : Number of lines per column
  50. ;;;  opt    : Options list
  51. ;;;  pt     : Text insertion point
  52. ;;;  pt1    : First text insertion point
  53. ;;;  rf     : File to read
  54. ;;;  s      : Text string
  55. ;;;  ts     : Text style list
  56. ;;;  ul     : Upper/lower case flag
  57. ;;;
  58. ;;;---------------------------------------------------------------------------;
  59.  
  60. ;;;
  61. ;;; Save modes
  62. ;;;
  63. (defun MODES (a) 
  64.   (setq MLST '
  65.         ())
  66.   (repeat (length a) 
  67.     (setq MLST (append MLST (list (list (car a) (getvar (car a))))))
  68.     (setq a (cdr a))
  69.   )
  70. ;;;
  71. ;;; Restore modes
  72. ;;;
  73. (defun MODER () 
  74.   (repeat (length MLST) 
  75.     (setvar (caar MLST) (cadar MLST))
  76.     (setq MLST (cdr MLST))
  77.   )
  78. ;;;
  79. ;;; Ascii Text error handler
  80. ;;;
  81. (defun at_err (st)                    ; If an error (such as CTRL-C) occurs
  82.                                       ; while this command is active...
  83.   (if (/= st "Function cancelled") 
  84.     (princ (strcat "\nError: " st))
  85.   ) 
  86.   (moder)                             ; Restore modified modes
  87.   (if (= (type rtfile) 'FILE) 
  88.     (close rtfile)
  89.   ) 
  90.   (setq rtfile nil)
  91.   (setq *error* olderr)               ; Restore old *error* handler
  92.   (princ)
  93. ;;;
  94. ;;; Function for inserting text a recalculation of insertion point.
  95. ;;;
  96. (defun 1LTXT () 
  97.   (if (member '1 opt) 
  98.     (setq s (strcat "%%u" s "%%u"))
  99.   ) 
  100.   (if (member '2 opt) 
  101.     (setq s (strcat "%%o" s "%%o"))
  102.   ) 
  103.   (if (member '4 opt) 
  104.     (setq s (strcase s))
  105.   ) 
  106.   (if (member '8 opt) 
  107.     (setq s (strcase s T))
  108.   ) 
  109.   (if (and (= lc (1+ nl)) (/= nl 0)) 
  110.     (progn
  111.       (setq lc 1)
  112.       (setq pt (polar pt1 ang cd))
  113.       (setq pt1 pt)
  114.     )
  115.   ) 
  116.   (cond 
  117.     ((and (= j "Aligned") h)        (command "TEXT" j  pt pt2 s))
  118.     ((and (= j "Aligned") (null h)) (command "TEXT" j  pt pt2 s))
  119.     ((and (= j "Fit")     h)        (command "TEXT" j  pt pt2 h (rtd ang) s))
  120.     ((and (= j "Fit")     (null h)) (command "TEXT" j  pt pt2 (rtd ang) s))
  121.     ((and (= j "L")       h)        (command "TEXT" pt h (rtd ang) s))
  122.     ((and (= j "L")       (null h)) (command "TEXT" pt (rtd ang) s))
  123.     ((and (/= j "L")      h)        (command "TEXT" j  pt h (rtd ang) s))
  124.     ((and (/= j "L")      (null h)) (command "TEXT" j  pt (rtd ang) s))
  125.   ) 
  126.   (if (/= d "Auto") 
  127.     (if (= (cdr (assoc 70 ts)) 4) 
  128.       (setq pt (polar pt (+ (dtr 90) ang) d))
  129.       (setq pt (polar pt (+ (dtr 270) ang) d))
  130.     )
  131.   ) 
  132.   (setq c (1+ c))
  133.   (if (= c n) 
  134.     (setq eof T)
  135.   )
  136. ;;;
  137. ;;; Degrees to radians conversion
  138. ;;;
  139. (defun DTR (y) 
  140.   (* pi (/ y 180.0))
  141. ;;;
  142. ;;; Radians to degrees conversion
  143. ;;;
  144. (defun RTD (Y) 
  145.   (* 180.0 (/ y pi))
  146. ;;;
  147. ;;; List the options.
  148. ;;;
  149. (defun justpn ()
  150.   (if (getvar "DIMCLRD") (textpage))
  151.   (princ "\nAlignment options: ")
  152.   (princ "\n\t TLeft   TCenter   TRight ")
  153.   (princ "\n\t MLeft   MCenter   MRight ")
  154.   (princ "\n\t BLeft   BCenter   BRight ")
  155.   (princ "\n\t  Left    Center    Right")
  156.   (princ "\n\tAligned   Middle    Fit")
  157.   (if (not (getvar "DIMCLRD")) (textscr))
  158.   (princ "\n\nPress any key to return to your drawing. ")
  159.   (grread)
  160.   (princ "\r                                           ")
  161.   (graphscr)
  162. )
  163. ;;;
  164. ;;; -------------------------- MAIN PROGRAM ----------------------------------
  165. ;;;
  166. (defun asctxt (/ olderr ang c cd d eof rtfile rf rfa h j l1 opt pt pt1 ts n nl 
  167.                     lc s ul)          ; at_ang holds default ANGLE
  168.                                       ; at_fnm holds default fILE
  169.   (setq olderr *error* 
  170.         *error* at_err)
  171.   (modes '("BLIPMODE" "CMDECHO" "HIGHLIGHT"))
  172.   (while (null rtfile)                ; Prompt for file to be inserted
  173.     (if (null at_fnm)
  174.       (progn
  175.         (initget 1) 
  176.         (princ "\nFile to read (including extension): ")
  177.       ) 
  178.       (progn
  179.         (princ "\nFile to read (including extension)/<") 
  180.         (princ (strcat at_fnm ">: "))
  181.       )
  182.     ) 
  183.     (setq rf (getstring))
  184.     (if (and (= rf "") (/= nil at_fnm)) 
  185.       (setq rf at_fnm)
  186.     ) 
  187.     (setq rfa (findfile rf))
  188.     (if rfa 
  189.       (progn
  190.         (setq at_fnm rfa)
  191.         (if (null (setq rtfile (open rfa "r")))
  192.           (princ (strcat 
  193.             "\n\tFile found, but couldn't open " at_fnm " for reading. "))
  194.         )
  195.       )
  196.       (if (/= (substr rf (- (strlen rf) 3) 1) ".")
  197.         (princ "\nFile not found.  Extension may be missing.")
  198.         (princ "\nFile not found. ")
  199.       )
  200.     )
  201.   ) 
  202.   (setq cont T)
  203.   ;; Prompt for start point or justification
  204.   (while cont                         
  205.     (if (getvar "DIMCLRD")
  206.       (initget 1 (strcat "TLeft TCenter TRight "
  207.                          "MLeft MCenter Mright "
  208.                          "BLeft BCenter Bright "
  209.                          "Aligned Center Fit Left Middle Right ?"))
  210.       (initget 1 "Aligned Center Fit Left Middle Right ?")
  211.     )
  212.     (setq pt (getpoint 
  213.              "\nStart point or Center/Middle/Right/?: "))
  214.     (if (/= (type pt) 'LIST) 
  215.       (if (= pt "?")
  216.         (progn
  217.           (justpn)
  218.           (setq cont T)
  219.         )
  220.         (progn
  221.           (setq cont nil)
  222.           ;;(setq j (substr pt 1 2))
  223.           (setq j pt)
  224.           (if (= j "Center") (setq j "MCenter"))
  225.           (initget 1) 
  226.           (setq pt (getpoint (strcat "\n" pt " point: ")))
  227.           (if (or (= j "Aligned") (= j "Fit"))
  228.             (progn
  229.               (initget 1)
  230.               (setq pt2 (getpoint pt (strcat "\nOther point: ")))
  231.               (setq at_ang (* (/ 180 pi) (angle pt pt2)))
  232.             )
  233.           )
  234.         )
  235.       )
  236.       (setq j    "L"
  237.             cont nil
  238.       )
  239.     )
  240.   )                                   ; Prompt for an insertion point
  241.   (setq pt1 pt)                       ; First insertion point
  242.  
  243.   ;; Prompt for a text height
  244.  
  245.   (setq ts (tblsearch "STYLE" (getvar "TEXTSTYLE")) 
  246.         h  nil)
  247.   (if (and (/= j "Aligned") (= (cdr (assoc 40 ts)) 0.0)) 
  248.     (progn
  249.       (initget 6) 
  250.       (setq h (getdist pt (strcat "\nHeight <" 
  251.                                   (rtos (getvar "TEXTSIZE")) ">: ")))
  252.       (if (null h) 
  253.         (setq h (getvar "TEXTSIZE"))
  254.       )
  255.     )
  256.   )                                   ;Prompt for rotation angle of text
  257.   (if (null at_ang) 
  258.     (progn
  259.       (if (= (cdr (assoc 70 ts)) 4)   ; Vertical style text
  260.         (progn
  261.           (setq at_ang 270)
  262.           (princ "\nRotation angle <270>: ")
  263.         ) 
  264.         (progn
  265.           (setq at_ang 0)
  266.           (princ "\nRotation angle <0>: ")
  267.         )
  268.       )
  269.     ) 
  270.     (if (and (/= j "Aligned") (/= j "Fit"))
  271.       (progn
  272.         (princ "\nRotation angle <") 
  273.         (princ (strcat (angtos at_ang) ">: "))
  274.       )
  275.     )
  276.   ) 
  277.   (setq ang (getangle pt))
  278.   (if (null ang) 
  279.     (setq ang at_ang)
  280.   ) 
  281.   (setq at_ang ang)
  282.   (setq d "Auto" 
  283.         l1 1 
  284.         n "All" 
  285.         opt nil 
  286.         lc 0 
  287.         nl 0 
  288.         c 0)
  289.   (initget "Yes No") 
  290.   (if (= "Yes" (getkword "\nChange text options? <N>: ")) 
  291.     (progn                            ; Prompt for distance between lines.
  292.       (initget "Auto") 
  293.       (setq d (getdist pt "\nDistance between lines/<Auto>: "))
  294.       (if (= d nil) 
  295.         (setq d "Auto")
  296.       )                               ; Prompt for first line to read.
  297.       (initget (+ 2 4)) 
  298.       (setq l1 (getint "\nFirst line to read/<1>: "))
  299.       (if (null l1) 
  300.         (setq l1 1)
  301.       )                               ; Prompt for number of following lines.
  302.       (initget (+ 2 4) "All")         
  303.       (setq n (getint "\nNumber of lines to read/<All>: "))
  304.       (if (= n "All") 
  305.         (setq n nil)
  306.       ) 
  307.       (initget "Yes No") 
  308.       (if (= "Yes" (getkword "\nUnderscore each line? <N>: ")) 
  309.         (setq opt (append opt '(1)))
  310.       ) 
  311.       (initget "Yes No") 
  312.       (if (= "Yes" (getkword "\nOverscore each line? <N>: ")) 
  313.         (setq opt (append opt '(2)))
  314.       )                               ; Option for global redefinition of text-
  315.                                       ; case.
  316.       (initget "Upper Lower No") 
  317.       (princ "\nChange text case? ") 
  318.       (setq ul (getkword "  Upper/Lower/<N>: "))
  319.       (cond ((= ul "Upper") (setq opt (append opt '(4)))) 
  320.         ((= ul "Lower") (setq opt (append opt '(8))))
  321.       )                               ; Option for setting up columns.
  322.       (initget "Yes No") 
  323.       (if (= "Yes" (getkword "\nSet up columns? <N>: ")) 
  324.         (progn
  325.           (setq opt (append opt '(16)))
  326.           (initget (+ 1 2)) 
  327.           (setq cd (getdist pt "\nDistance between columns: "))
  328.           (initget (+ 1 2 4)) 
  329.           (setq nl (getint "\nNumber of lines per column: "))
  330.         )
  331.       )
  332.     )
  333.   ) 
  334.   (setvar "BLIPMODE" 0)
  335.   (setvar "HIGHLIGHT" 0)
  336.   (setvar "CMDECHO" 0)
  337.   (setq eof nil)
  338.   (setq s (repeat l1 
  339.             (read-line rtfile)
  340.           ))
  341.   (setq lc (1+ lc))
  342.   (1ltxt) 
  343.   (while (null eof) 
  344.     (if (= d "Auto") 
  345.       (progn
  346.         (setq s (read-line rtfile))
  347.         (setq lc (1+ lc))
  348.         (if s 
  349.           (progn
  350.             (if (= lc (1+ nl)) 
  351.               (1ltxt) 
  352.               (progn
  353.                 (if (member '1 opt) 
  354.                   (setq s (strcat "%%u" s "%%u"))
  355.                 ) 
  356.                 (if (member '2 opt) 
  357.                   (setq s (strcat "%%o" s "%%o"))
  358.                 ) 
  359.                 (if (member '4  opt) 
  360.                   (setq s (strcase s))
  361.                 ) 
  362.                 (if (member '8 opt) 
  363.                   (setq s (strcase s T))
  364.                 ) 
  365.                 (command "TEXT" "" s) 
  366.                 (setq c (1+ c))
  367.                 (if (= c n) 
  368.                   (setq eof T)
  369.                 )
  370.               )
  371.             )
  372.           ) 
  373.           (setq eof T)
  374.         )
  375.       ) 
  376.       (progn
  377.         (setq s (read-line rtfile))
  378.         (setq lc (1+ lc))
  379.         (if s 
  380.           (1ltxt) 
  381.           (setq eof T)
  382.         )
  383.       )
  384.     )
  385.   ) 
  386.   (close rtfile) 
  387.   (setq rtfile nil)
  388.   (moder)                             ; Restore modified modes
  389.   (setq *error* olderr)               ; Restore old *error* handler
  390.   (princ)
  391.  
  392. (defun c:at () (vmon) (asctxt))
  393. (defun c:asctext () (vmon) (asctxt))
  394. (princ "\n\tc:AscTxt loaded.  Start command with AT or ASCTEXT.")
  395. (princ)
  396.  
  397.