home *** CD-ROM | disk | FTP | other *** search
/ Monster Media 1993 #2 / Image.iso / cad / jun93.zip / DTAB.LSP next >
Lisp/Scheme  |  1993-03-30  |  6KB  |  206 lines

  1. ;==========================================================
  2. ; DTAB.LSP Copyright 1993 by Looking Glass Microproducts
  3. ;==========================================================
  4. ; Justify Text its Decimal Point 
  5. ;=============================================================
  6. (defun C:DTAB (/ ERROR PUSHVARS POPVARS SYSVARS OLD-ERROR NOTRANS
  7.                ITEM SS1 FILTER DTAB ONE_DTAB REPLACE BS SP BP PER
  8. )
  9.    (setq
  10.       BS  "\010" ; back space
  11.       SP  "\040" ; space
  12.       BP  "\011" ; back period
  13.       PER "."   ; period
  14.    )
  15.    ;==========================================================
  16.    ; Error Handler
  17.    (defun ERROR (S)
  18.       (if (not
  19.              (member
  20.                 S
  21.                 '("Function cancelled" "console break")
  22.              )
  23.           )
  24.          (princ S)
  25.       )
  26.       (if UNDOIT
  27.          (progn
  28.             (princ "\nUndoing...")
  29.             (command
  30.                "_undo" "_end" "_undo" 1
  31.             )
  32.          )
  33.       )
  34.       (POPVARS)
  35.       (princ)
  36.    )
  37.    ;==========================================================
  38.    ; Set and Save System Variables
  39.    (defun PUSHVARS (VLIST)
  40.       (foreach PAIR VLIST
  41.          (setq
  42.             SYSVARS (cons
  43.                        (cons
  44.                           (strcase (car PAIR))
  45.                           (getvar
  46.                              (car PAIR)
  47.                           )
  48.                        )
  49.                        SYSVARS
  50.                     )
  51.          )
  52.          (if (cdr PAIR) (setvar (car PAIR) (cdr PAIR)))
  53.       )
  54.    )
  55.    ;==========================================================
  56.    ; Restore System Variables
  57.    (defun POPVARS ()
  58.       (foreach PAIR SYSVARS (setvar (car PAIR) (cdr PAIR)))
  59.       (setq
  60.          *error* OLD-ERROR
  61.       )
  62.       (setq SYSVARS nil)
  63.    )
  64.    ;==========================================================
  65.    ; Disallow transparent invocation of routine.
  66.    (defun NOTRANS ()
  67.       (cond
  68.          ((zerop (logand (getvar "cmdactive") (+ 1 2 4 8))))
  69.          ((alert
  70.              "This command may not be invoked transparently."
  71.           )
  72.          )
  73.       )
  74.    )
  75.    ;==========================================================
  76.    ; Item from association list
  77.    (defun ITEM (A B) (cdr (assoc A B)))
  78.    ;============================================================
  79.    ; Something for the eyes on the status line
  80.    (defun ENTERTAIN (PRMPT I SUFFIX)
  81.       (setvar "modemacro" (strcat PRMPT (itoa I) SUFFIX))
  82.    )
  83.    ;=========================================================
  84.    ; Apply func to every entity in ss
  85.    (defun MAPSET (FUNC SS PRMPT / I L SUFFIX ENAME MM)
  86.       (if SS
  87.          (progn
  88.             (setq
  89.                FUNC   (eval FUNC)
  90.                I      0
  91.                L      (sslength SS)
  92.                SUFFIX (strcat ":" (itoa L))
  93.                MM     (getvar "modemacro")
  94.             )
  95.             (repeat
  96.                L
  97.                (setq ENAME (ssname SS 0) I (1+ I))
  98.                (ssdel
  99.                   ENAME
  100.                   SS
  101.                )
  102.                (if PRMPT (ENTERTAIN PRMPT I SUFFIX))
  103.                (FUNC
  104.                   ENAME
  105.                )
  106.             )
  107.             (setvar "modemacro" MM)
  108.          )
  109.       )
  110.    )
  111.    ;========================================================
  112.    ; Return copy of selection set
  113.    (defun SSCOPY (SS)
  114.       (if SS (progn (command "_select" SS "") (ssget "p")))
  115.    )
  116.    ;==========================================================
  117.    ; Replace item in association list
  118.    (defun REPLACE (NEW_ITEM ALIST / OLD_ITEM)
  119.       (if (setq OLD_ITEM (assoc (car NEW_ITEM) ALIST))
  120.          (subst
  121.             NEW_ITEM
  122.             OLD_ITEM
  123.             ALIST
  124.          )
  125.          (append ALIST (list NEW_ITEM))
  126.       )
  127.    )
  128.    ;==========================================================
  129.    ; Decimal tab one text entity
  130.    (defun ONE_DTAB (ENAME / ENT VALUE I PREFIX)
  131.       (setq ENT (entget ENAME) VALUE (ITEM 1 ENT))
  132.       ; Strip leading control characters
  133.       (while (< (substr VALUE 1 1) SP)
  134.          (setq
  135.             VALUE (substr VALUE 2)
  136.          )
  137.       )
  138.       ; Add a backperiod plus backspace for each character before the period
  139.       (setq PREFIX BP I 1)
  140.       (while (/= (substr VALUE I 1) PER)
  141.          (setq
  142.             PREFIX (strcat BS PREFIX)
  143.             I      (1+ I)
  144.          )
  145.       )
  146.       (setq VALUE (strcat PREFIX VALUE))
  147.       (entmod
  148.          (REPLACE (cons 1 VALUE) ENT)
  149.       )
  150.    )
  151.    ;==========================================================
  152.    ; Main Routine
  153.    (defun DTAB (/ SS2)
  154.       (if (null SS1)
  155.          (setq SS1 (ssget FILTER))
  156.          (princ
  157.             (strcat "\n" (itoa (sslength SS1)) " found.")
  158.          )
  159.       )
  160.       (cond
  161.          ((null SS1))
  162.          (t
  163.             (setvar "highlight" 0)
  164.             (setq SS2 (SSCOPY SS1))
  165.             (MAPSET
  166.                'ONE_DTAB
  167.                SS1
  168.                "Justifying "
  169.             )
  170.             (command "_select" SS2 "")
  171.             (setq SS1 nil SS2 nil)
  172.          )
  173.       )
  174.    )
  175.    ;==========================================================
  176.    ; Body of c:dtab  
  177.    (if (NOTRANS)
  178.       (progn
  179.          (setq OLD-ERROR *error* *error* ERROR UNDOIT t)
  180.          (setvar
  181.             "cmdecho" 0
  182.          )
  183.          (setq
  184.             FILTER '((0 . "TEXT")
  185.                       (1 . "*`.*")
  186.                       (72 . 0)
  187.                       (73 . 0)
  188.                    )
  189.             SS1    (ssget "I" FILTER)
  190.          )
  191.          (command "_undo" "_group")
  192.          (PUSHVARS
  193.             '(("modemacro") ("highlight"))
  194.          )
  195.          (DTAB)
  196.          (POPVARS)
  197.          (command "_undo" "_end")
  198.       )
  199.    )
  200.    (princ)
  201. )
  202. (princ
  203.    "  DTAB.LSP (Copyright 1993 by Looking Glass Microproducts) loaded."
  204. )
  205. (princ)
  206.