home *** CD-ROM | disk | FTP | other *** search
/ Liren Large Software Subsidy 13 / 13.iso / p / p024 / 5.img / SUPPORT2.LIB / ASCTEXT.LSP next >
Encoding:
Text File  |  1993-02-09  |  11.8 KB  |  416 lines

  1. ;;; --------------------------------------------------------------------------;
  2. ;;;   ASCTEXT.LSP
  3. ;;;   ¬⌐┼v (C) 1986-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. ;;;   Use ASCTEXT.LSP to insert ASCII text files into AutoCAD drawings.
  19. ;;;   The blocks of text can be either Left, Center, Middle or Right
  20. ;;;   Justified.
  21. ;;;
  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. ;;;  GLOBAL variables
  35. ;;;  at_ang    : Last angle (for default value)
  36. ;;;  at_fnm    : Last file  (for default value)
  37. ;;;---------------------------------------------------------------------------;
  38.  
  39. ;;;
  40. ;;; Save modes
  41. ;;;
  42. (defun MODES (a)
  43.   (setq MLST '
  44.         ())
  45.   (repeat (length a)
  46.     (setq MLST (append MLST (list (list (car a) (getvar (car a))))))
  47.     (setq a (cdr a))
  48.   )
  49. )
  50. ;;;
  51. ;;; Restore modes
  52. ;;;
  53. (defun MODER ()
  54.   (repeat (length MLST)
  55.     (setvar (caar MLST) (cadar MLST))
  56.     (setq MLST (cdr MLST))
  57.   )
  58. )
  59. ;;;
  60. ;;; Ascii Text error handler
  61. ;;;
  62. (defun at_err (st)                    ; If an error (such as CTRL-C) occurs
  63.                                       ; while this command is active...
  64.   (if (and (/= st "Function cancelled")
  65.            (/= st "quit / exit abort")
  66.       )
  67.     (princ (strcat "\n┐∙╗~: " st))
  68.   )
  69.   (moder)                             ; Restore modified modes
  70.   (if (= (type rtfile) 'FILE)
  71.     (close rtfile)
  72.   )
  73.   (setq rtfile nil)
  74.   (setq *error* olderr)               ; Restore old *error* handler
  75.   (princ)
  76. )
  77. ;;;
  78. ;;; Function for inserting text a recalculation of insertion point.
  79. ;;;
  80. (defun 1LTXT ()
  81.   (if (member '1 opt)
  82.     (setq s (strcat "%%u" s "%%u"))
  83.   )
  84.   (if (member '2 opt)
  85.     (setq s (strcat "%%o" s "%%o"))
  86.   )
  87.   (if (member '4 opt)
  88.     (setq s (strcase s))
  89.   )
  90.   (if (member '8 opt)
  91.     (setq s (strcase s T))
  92.   )
  93.   (if (and (= lc (1+ nl)) (/= nl 0))
  94.     (progn
  95.       (setq lc 1)
  96.       (setq pt (polar pt1 ang cd))
  97.       (setq pt1 pt)
  98.     )
  99.   )
  100.   (cond
  101.     ((and (= j "Aligned") h)        (command "_.TEXT" j  pt pt2 s))
  102.     ((and (= j "Aligned") (null h)) (command "_.TEXT" j  pt pt2 s))
  103.     ((and (= j "Fit")     h)        (command "_.TEXT" j  pt pt2 h s))
  104.     ((and (= j "Fit")     (null h)) (command "_.TEXT" j  pt pt2 s))
  105.     ((and (= (substr j 1 1) "L")        h) (command "_.TEXT" pt h (rtd ang) s))
  106.     ((and (= (substr j 1 1) "L") (null h)) (command "_.TEXT" pt (rtd ang) s))
  107.     ((and (/= (substr j 1 1) "L")       h) (command "_.TEXT" j  pt h (rtd ang) s))
  108.     ((and (/= (substr j 1 1) "L")(null h)) (command "_.TEXT" j  pt (rtd ang) s))
  109.   )
  110.   (if (/= d "Auto")
  111.     (if (= (cdr (assoc 70 ts)) 4)
  112.       (setq pt (polar pt (+ (dtr 90) ang) d))
  113.       (setq pt (polar pt (+ (dtr 270) ang) d))
  114.     )
  115.   )
  116.   (setq c (1+ c))
  117.   (if (= c n)
  118.     (setq eof T)
  119.   )
  120. )
  121. ;;;
  122. ;;; Degrees to radians conversion
  123. ;;;
  124. (defun DTR (y)
  125.   (* pi (/ y 180.0))
  126. )
  127. ;;;
  128. ;;; Radians to degrees conversion
  129. ;;;
  130. (defun RTD (Y)
  131.   (* 180.0 (/ y pi))
  132. )
  133. ;;;
  134. ;;; List the options.
  135. ;;;
  136. (defun justpn ()
  137.   (if (getvar "DIMCLRD") (textpage))
  138.   (princ "\n╜╒╗⌠┐∩╢╡: ")
  139.   (princ "\n\t TL│╗Ѭ   TC│╗ññ   TR│╗Ñk ")
  140.   (princ "\n\t ML╕yѬ   MC╕yññ   MR╕yÑk ")
  141.   (princ "\n\t BL⌐│Ѭ   BC⌐│ññ   BR⌐│Ñk ")
  142.   (princ "\n\t  LѬ      Cññ      RÑk   ")
  143.   (princ "\n\t  A╣∩╗⌠    MÑ┐ññ    F╢±╗⌠ ")
  144.   (if (not (getvar "DIMCLRD")) (textscr))
  145.   (princ "\n\n½÷Ñ⌠╖N┴ΣÑH¬≡ª^íu╣╧º╬╡e¡▒ívíC")
  146.   (grread)
  147.   (princ "\r                                           ")
  148.   (graphscr)
  149. )
  150. ;;;
  151. ;;; -------------------------- MAIN PROGRAM ----------------------------------
  152. ;;;
  153. (defun asctxt (/ olderr ang c cd d eof rtfile rf rfa h j l1 opt pt pt1 ts n nl
  154.                     lc s ul)          ; at_ang holds default ANGLE
  155.                                       ; at_fnm holds default FILE
  156.   (setq olderr *error*
  157.         *error* at_err)
  158.   (modes '("BLIPMODE" "CMDECHO" "HIGHLIGHT"))
  159.   (while (null rtfile)                ; Prompt for file to be inserted
  160.     (if (null at_fnm)
  161.       (if (= 1 (getvar "FILEDIA"))
  162.         (setq rf (getfiled "╣w│╞┼¬ñJ¬║└╔«╫" "" "" 12))
  163.         (progn
  164.           (initget 1)
  165.           (princ "\n┼¬ñJ└╔ªW (ºtíu⌐╡ª∙└╔ªWív): ")
  166.           (setq rf (getstring))
  167.         )
  168.       )
  169.       (if (= 1 (getvar "FILEDIA"))
  170.         (setq rf (getfiled "╣w│╞┼¬ñJ¬║└╔«╫" at_fnm "" 12))
  171.         (progn
  172.           (princ "\n┼¬ñJ└╔ªW (ºtíu⌐╡ª∙└╔ªWív)/<")
  173.           (princ (strcat at_fnm ">: "))
  174.           (setq rf (getstring))
  175.         )
  176.       )
  177.     )
  178.     (if (= rf nil) (exit))
  179.     (if (= rf 1)
  180.       (if (null at_fnm)
  181.         (progn
  182.           (initget 1)
  183.           (princ "\n┼¬ñJ└╔ªW (ºtíu⌐╡ª∙└╔ªWív): ")
  184.           (setq rf (getstring))
  185.         )
  186.         (progn
  187.           (princ "\n┼¬ñJ└╔ªW (ºtíu⌐╡ª∙└╔ªWív)/<")
  188.           (princ (strcat at_fnm ">: "))
  189.           (setq rf (getstring))
  190.         )
  191.       )
  192.     )
  193.     (if (and (= rf "") (/= nil at_fnm))
  194.       (setq rf at_fnm)
  195.     )
  196.     (setq rfa (findfile rf))
  197.     (if (= "~" rf)
  198.       (progn
  199.         (setq rfa nil)
  200.         (setq rtfile nil)
  201.       )
  202.     )
  203.     (if rfa
  204.       (progn
  205.         (setq at_fnm rfa)
  206.         (if (null (setq rtfile (open rfa "r")))
  207.           (princ (strcat
  208.             "\n\t└╔«╫┴÷┤M└≥, ª²╡L¬k╢}▒╥íu" at_fnm "ív¿╙┼¬¿·íC"))
  209.         )
  210.       )
  211.       (if (/= "~" rf)
  212.         (if (and (< 4 (strlen rf))
  213.                  (/= (substr rf (- (strlen rf) 3) 1) ".")
  214.             )
  215.           (princ "\nºΣñú¿∞└╔«╫, Ñi»α║|»╩ñFíu⌐╡ª∙└╔ªWívíC")
  216.           (princ "\nºΣñú¿∞└╔«╫íC")
  217.         )
  218.       )
  219.     )
  220.   )
  221.   (setq cont T)
  222.   ;; Prompt for start point or justification
  223.   (while cont
  224.     (if (getvar "DIMCLRD")
  225.       (initget 1 (strcat "TLeft TCenter TRight "
  226.                          "MLeft MCenter Mright "
  227.                          "BLeft BCenter Bright "
  228.                          "Aligned Center Fit Left Middle Right ?"))
  229.       (initget 1 "Aligned Center Fit Left Middle Right ?")
  230.     )
  231.     (setq pt (getpoint
  232.              "\níu░_⌐l┬Iív⌐╬íuCññ/MÑ┐ññ/RÑk/?ív: "))
  233.     (if (/= (type pt) 'LIST)
  234.       (if (= pt "?")
  235.         (progn
  236.           (justpn)
  237.           (setq cont T)
  238.         )
  239.         (progn
  240.           (setq cont nil)
  241.           ;;(setq j (substr pt 1 2))
  242.           (setq j pt)
  243.           (if (= j "Center") (setq j "MCenter"))
  244.           (initget 1)
  245.           (setq pt (getpoint (strcat "\níu" ptc "ív┬I: ")))
  246.           (if (or (= j "Aligned") (= j "Fit"))
  247.             (progn
  248.               (initget 1)
  249.               (setq pt2 (getpoint pt (strcat "\nÑtñ@┬I: ")))
  250.               (setq at_ang (* (/ 180 pi) (angle pt pt2)))
  251.             )
  252.           )
  253.         )
  254.       )
  255.       (setq j    "L"
  256.             cont nil
  257.       )
  258.     )
  259.   )                                   ; Prompt for an insertion point
  260.   (setq pt1 pt)                       ; First insertion point
  261.  
  262.   ;; Prompt for a text height
  263.  
  264.   (setq ts (tblsearch "STYLE" (getvar "TEXTSTYLE"))
  265.         h  nil)
  266.   (if (and (/= j "Aligned") (= (cdr (assoc 40 ts)) 0.0))
  267.     (progn
  268.       (initget 6)
  269.       (setq h (getdist pt (strcat "\nªr░¬ <"
  270.                                   (rtos (getvar "TEXTSIZE")) ">: ")))
  271.       (if (null h)
  272.         (setq h (getvar "TEXTSIZE"))
  273.       )
  274.     )
  275.   )                                   ;Prompt for rotation angle of text
  276.   (if (null at_ang)
  277.     (progn
  278.       (if (= (cdr (assoc 70 ts)) 4)   ; Vertical style text
  279.         (progn
  280.           (setq at_ang 270)
  281.           (princ "\n▒█┬α¿ñ <270>: ")
  282.         )
  283.         (progn
  284.           (setq at_ang 0)
  285.           (princ "\n▒█┬α¿ñ <0>: ")
  286.         )
  287.       )
  288.     )
  289.     (if (and (/= j "Aligned") (/= j "Fit"))
  290.       (progn
  291.         (princ "\n▒█┬α¿ñ <")
  292.         (princ (strcat (angtos at_ang) ">: "))
  293.         (setq ang (getangle pt))
  294.       )
  295.     )
  296.   )
  297.   (if (null ang)
  298.     (setq ang at_ang)
  299.   )
  300.   (setq at_ang ang)
  301.   (setq d "Auto"
  302.         l1 1
  303.         n "All"
  304.         opt nil
  305.         lc 0
  306.         nl 0
  307.         c 0)
  308.   (initget "Yes No")
  309.   (if (= "Yes" (getkword "\nº≤º∩ñσªr┐∩╢╡? <N>: "))
  310.     (progn                            ; Prompt for distance between lines.
  311.       (initget "Auto")
  312.       (setq d (getdist pt "\n╛εªC╢í╢Z/<Aª█░╩>: "))
  313.       (if (= d nil)
  314.         (setq d "Auto")
  315.       )                               ; Prompt for first line to read.
  316.       (initget (+ 2 4))
  317.       (setq l1 (getint "\nÑ╤▓─┤XªC╢}⌐l┼¬ñJ/<1>: "))
  318.       (if (null l1)
  319.         (setq l1 1)
  320.       )                               ; Prompt for number of following lines.
  321.       (initget (+ 2 4) "All")
  322.       (setq n (getint "\n┼¬ñJ┤XªC/<AÑ■│í>: "))
  323.       (if (= n "All")
  324.         (setq n nil)
  325.       )
  326.       (initget "Yes No")
  327.       (if (= "Yes" (getkword "\n¿CªCÑ[íu⌐│╜uív? <N>: "))
  328.         (setq opt (append opt '(1)))
  329.       )
  330.       (initget "Yes No")
  331.       (if (= "Yes" (getkword "\n¿CªCÑ[íu│╗╜uív? <N>: "))
  332.         (setq opt (append opt '(2)))
  333.       )                               ; Option for global redefinition of text-
  334.                                       ; case.
  335.       (initget "Upper Lower No")
  336.       (princ "\nº∩┼▄ñσªríuñjñp╝gív? ")
  337.       (setq ul (getkword "  Uñj╝g/Lñp╝g/<Nñú┼▄>: "))
  338.       (cond ((= ul "Upper") (setq opt (append opt '(4))))
  339.         ((= ul "Lower") (setq opt (append opt '(8))))
  340.       )                               ; Option for setting up columns.
  341.       (initget "Yes No")
  342.       (if (= "Yes" (getkword "\n│]⌐wíu¬╜ªµív? <N>: "))
  343.         (progn
  344.           (setq opt (append opt '(16)))
  345.           (initget (+ 1 2))
  346.           (setq cd (getdist pt "\n¬╜ªµ╢í╢Z: "))
  347.           (initget (+ 1 2 4))
  348.           (setq nl (getint "\n¿Cªµíu╛εªC╝╞ív: "))
  349.         )
  350.       )
  351.     )
  352.   )
  353.   (setvar "BLIPMODE" 0)
  354.   (setvar "HIGHLIGHT" 0)
  355.   (setvar "CMDECHO" 0)
  356.   (setq eof nil)
  357.   (setq s (repeat l1
  358.             (read-line rtfile)
  359.           ))
  360.   (setq lc (1+ lc))
  361.   (1ltxt)
  362.   (while (null eof)
  363.     (if (= d "Auto")
  364.       (progn
  365.         (setq s (read-line rtfile))
  366.         (setq lc (1+ lc))
  367.         (if s
  368.           (progn
  369.             (if (= lc (1+ nl))
  370.               (1ltxt)
  371.               (progn
  372.                 (if (member '1 opt)
  373.                   (setq s (strcat "%%u" s "%%u"))
  374.                 )
  375.                 (if (member '2 opt)
  376.                   (setq s (strcat "%%o" s "%%o"))
  377.                 )
  378.                 (if (member '4  opt)
  379.                   (setq s (strcase s))
  380.                 )
  381.                 (if (member '8 opt)
  382.                   (setq s (strcase s T))
  383.                 )
  384.                 (command "_.TEXT" "" s)
  385.                 (setq c (1+ c))
  386.                 (if (= c n)
  387.                   (setq eof T)
  388.                 )
  389.               )
  390.             )
  391.           )
  392.           (setq eof T)
  393.         )
  394.       )
  395.       (progn
  396.         (setq s (read-line rtfile))
  397.         (setq lc (1+ lc))
  398.         (if s
  399.           (1ltxt)
  400.           (setq eof T)
  401.         )
  402.       )
  403.     )
  404.   )
  405.   (close rtfile)
  406.   (setq rtfile nil)
  407.   (moder)                             ; Restore modified modes
  408.   (setq *error* olderr)               ; Restore old *error* handler
  409.   (princ)
  410. )
  411.  
  412. ;(defun c:at () (asctxt))
  413. (defun c:asctext () (asctxt))
  414. (princ "\n  íuASCTEXTívñw╕ⁿñJíC")
  415. (princ)
  416.