home *** CD-ROM | disk | FTP | other *** search
/ Liren Large Software Subsidy 13 / 13.iso / p / p024 / 5.img / R11SUPP.EXE / TABLES.LSP < prev    next >
Encoding:
Lisp/Scheme  |  1990-09-24  |  16.6 KB  |  575 lines

  1. ;;;  TABLES.LSP
  2. ;;;   Copyright (C) 1990 by Autodesk, Inc.  
  3. ;;;    
  4. ;;;   Permission to use, copy, modify, and distribute this software and its
  5. ;;;   documentation for any purpose and without fee is hereby granted.  
  6. ;;;
  7. ;;;   THIS SOFTWARE IS PROVIDED "AS IS" WITHOUT EXPRESS OR IMPLIED WARRANTY. 
  8. ;;;   ALL IMPLIED WARRANTIES OF FITNESS FOR ANY PARTICULAR PURPOSE AND OF 
  9. ;;;   MERCHANTABILITY ARE HEREBY DISCLAIMED.
  10. ;;;   
  11. ;;;--------------------------------------------------------------------------
  12. ;;; DESCRIPTION
  13.  
  14. ;;;  This is a programming example.
  15. ;;;  Exerciser for (TBLNEXT) and (TBLSEARCH) functions.
  16.  
  17. ;;;  The functions (LAYER), (LTYPE), (VIEW), (STYLE), (BLOCK)
  18. ;;;  (UCS), and (VPORT) can be called independently.  Each lists the 
  19. ;;;  entries in the associated symbol table, optionally in alphabetical 
  20. ;;;  order.  The TABLES command ((C:TABLES) function) calls each of them 
  21. ;;;  in turn.
  22.  
  23. ;;;  For the layer, linetype, and text style tables, an asterisk in column
  24. ;;;  one marks the current setting.  If the current linetype is "BYLAYER",
  25. ;;;  the linetype corresponding to the current layer will be marked with
  26. ;;;  an "L" in column one.
  27.  
  28. ;;;  by Duff Kurland - Autodesk, Inc.
  29. ;;;  October 12, 1986
  30.  
  31. ;;;  Added (UCS) and (VPORT) - May 1988 
  32.  
  33. ;;;  (LAYER) - Dump the layer table
  34.  
  35. (defun myerror (s)                    ; If an error (such as CTRL-C) occurs
  36.                                       ; while this command is active...
  37.   (if (/= s "Function cancelled")
  38.     (princ (strcat "\nError: " s))
  39.   )
  40.   (setvar "cmdecho" ocmd)             ; Restore saved modes
  41.   (setvar "blipmode" oblp)
  42.   (setq *error* olderr)               ; Restore old *error* handler
  43.   (princ)
  44. )
  45.  
  46. (defun layer ( / c d f ln lt ly n x)
  47.   (tblset "layer")
  48.   (write-line "  Layer       Status  Color  Linetype    Description")
  49.   (terpri)
  50.   (setq cl (getvar "clayer"))         ; get current layer
  51.   (setq n  0)
  52.   (setq x  (next T))                  ; get first layer
  53.   (while x
  54.     (setq n  (1+ n)
  55.           ly (fld  2 x)               ; layer name
  56.           ln (fld  6 x)               ; linetype name
  57.           c  (fld 62 x)               ; color number
  58.           f  (logand (fld 70 x) 1)    ; "frozen" flag
  59.           lt (tblsearch "ltype" ln)   ; linetype table entry
  60.           d  (fld  3 lt)              ; linetype prose description
  61.     )
  62.     (write-line
  63.       (strcat
  64.         (if (= ly cl) "* " "  ")      ; flag current layer
  65.         (strfill ly 12)               ; edit layer name
  66.         (strfill
  67.           (cond 
  68.             ((= f 1) "Frozen") ; edit status
  69.             ((< c 0) "Off")
  70.             (T       "On")
  71.           ) 
  72.           8
  73.         )
  74.         (strfill (itoa (abs c)) 7)    ; edit color number
  75.         (strfill ln 12)               ; edit linetype name
  76.         (substr d 1 30)               ; edit linetype description
  77.       )
  78.     )
  79.     (setq x (next nil))               ; get next layer entry
  80.   )
  81.   (princ (if (= n 0) "  -None-\n\n" "\n"))
  82.   nil
  83. )
  84.  
  85.  
  86. ;;;  (LTYPE) - Dump the linetype table
  87.  
  88. (defun ltype ( / a cl d f lt n s x)
  89.   (tblset "ltype")
  90.   (write-line "  Linetype    Align  Segs  Description")
  91.   (terpri)
  92.   (setq cl (getvar "celtype"))        ; get current linetype
  93.   (setq f  "* ")                      ; set default "current" flag
  94.  
  95.   ;;  If current linetype is "BYLAYER", look up the linetype
  96.   ;;  associated with the current layer, and change the
  97.   ;;  "current" flag from "* " to "L ".
  98.  
  99.   (setq cl
  100.     (cond 
  101.       ((= cl "BYBLOCK") "")
  102.       ((= cl "BYLAYER") 
  103.         (setq f "L ")
  104.         (fld 6 (tblsearch "layer" (getvar "clayer")))
  105.       )
  106.       (T cl)
  107.     )
  108.   )
  109.   (setq n 0)
  110.   (setq x (next T))                   ; first linetype
  111.   (while x
  112.     (setq n  (1+ n)
  113.           lt (fld  2 x)               ; linetype name
  114.           d  (fld  3 x)               ; linetype prose description
  115.           a  (fld 72 x)               ; alignment code
  116.           s  (fld 73 x)               ; number of dash length items
  117.     )
  118.     (write-line
  119.       (strcat
  120.         (if (= lt cl) f "  ")         ; flag current entity linetype
  121.         (strfill lt 12)               ; edit layer name
  122.         (strfill (chr a) 7)           ; alignment code
  123.         (strfill (itoa s) 6)          ; number of dash length items
  124.         (substr d 1 30)               ; linetype description
  125.       )
  126.     )
  127.     (if (> s 0) 
  128.       (progn
  129.  
  130.         ;;;  Edit dash length items
  131.  
  132.         (setq x (member (assoc 49 x) x)) ; get list of dash items
  133.         (while x
  134.           (setq s (cdar x))           ; get dash length
  135.           (write-line
  136.             (strcat
  137.               (strfill " " 27)
  138.               (cond 
  139.                 ((= s 0) "Dot")
  140.                 ((> s 0) (strcat "Pen down " (rtos s 2 4)))
  141.                 (T       (strcat "Pen up   " (rtos (abs s) 2 4)))
  142.               )
  143.             )
  144.           )
  145.           (setq x (cdr x))            ; get next dash item
  146.         )
  147.       )
  148.     )
  149.     (setq x (next nil))               ; get next linetype entry
  150.   )
  151.   (princ (if (= n 0) "  -None-\n\n" "\n"))
  152.   nil
  153. )
  154.  
  155.  
  156. ;;;  (VIEW) - Dump the named view table
  157.  
  158. (defun view ( / c d h n v w x)
  159.   (tblset "view")
  160.   (write-line "  View        Height x Width    Center            Direction")
  161.   (terpri)
  162.   (setq n 0)
  163.   (setq x (next T))                   ; get first view
  164.   (while x
  165.     (setq n  (1+ n)
  166.           v  (fld  2 x)               ; view name
  167.           c  (fld 10 x)               ; center point
  168.           d  (fld 11 x)               ; view direction
  169.           h  (fld 40 x)               ; height
  170.           w  (fld 41 x)               ; width (valid only for windows)
  171.     )
  172.     (write-line
  173.       (strcat
  174.         "  "
  175.         (strfill v 12)                ; edit view name
  176.         (strfill (strcat (rtos h 2 4) ; edit height x width
  177.                          "x"
  178.                          (rtos w 2 4)) 18
  179.         )
  180.         (strfill (strcat (rtos (car c) 2 4) ; edit center point
  181.                          ","
  182.                          (rtos (cadr c) 2 4)) 18
  183.         )
  184.         (rtos (car d) 2 4)            ; edit X portion of direction
  185.         ","
  186.         (rtos (cadr d) 2 4)           ; edit Y portion of direction
  187.         ","
  188.         (rtos (caddr d) 2 4)          ; edit Z portion of direction
  189.       )
  190.     )
  191.     (setq x (next nil))               ; get next view entry
  192.   )
  193.   (princ (if (= n 0) "  -None-\n\n" "\n"))
  194.   nil
  195. )
  196.  
  197.  
  198. ;;;  (STYLE) - Dump the text style table
  199.  
  200. (defun style ( / cs fb ff g h n o s w x)
  201.   (tblset "style")
  202.   (write-line "  Text style  Height  Width   Slant  Flags  Font      Bigfont")
  203.   (terpri)
  204.   (setq cs (getvar "textstyle"))      ; get current style
  205.   (setq n  0)
  206.   (setq x  (next T))                  ; get first style
  207.   (while x
  208.     (setq n  (1+ n)
  209.           s  (fld  2 x)               ; style name
  210.           ff (fld  3 x)               ; primary font file
  211.           fb (fld  4 x)               ; big font file
  212.           h  (fld 40 x)               ; height
  213.           w  (fld 41 x)               ; width factor
  214.           o  (fld 50 x)               ; obliquing angle
  215.           g  (fld 71 x)               ; generation flags
  216.     )
  217.     (write-line
  218.       (strcat
  219.         (if (= s cs) "* " "  ")       ; flag current style
  220.         (strfill s 12)                ; edit style name
  221.         (strfill (rtos h 2 4) 8)      ; height
  222.         (strfill (rtos w 2 4) 8)      ; width factor
  223.         (strfill (angtos o 0 2) 7)    ; obliquing angle
  224.         (strfill (itoa g) 7)          ; generation flags
  225.         (strfill ff 10)               ; primary font file
  226.         fb                            ; big font file
  227.       )
  228.     )
  229.     (setq x (next nil))               ; get next style entry
  230.   )
  231.   (princ (if (= n 0) "  -None-\n\n" "\n"))
  232.   nil
  233. )
  234.  
  235.  
  236. ;;;  (BLOCK) - Dump the block definition table
  237.  
  238. (defun block ( / b e ec ed et f n o x)
  239.   (tblset "block")
  240.   (write-line "  Block       Flags  Origin")
  241.   (terpri)
  242.   (setq n 0)
  243.   (setq x (next T))                   ; get first block definition
  244.   (while x
  245.     (setq n  (1+ n)
  246.           b  (fld  2 x)               ; block name
  247.           o  (fld 10 x)               ; origin X,Y,Z
  248.           f  (fld 70 x)               ; flags
  249.     )
  250.     (write-line
  251.       (strcat
  252.         "  "
  253.         (strfill b 12)                ; edit block name
  254.         (strfill (itoa f) 7)          ; flags
  255.         (rtos (car o) 2 4)            ; origin X
  256.         ","
  257.         (rtos (cadr o) 2 4)           ; origin Y
  258.         ","
  259.         (rtos (caddr o) 2 4)          ; origin Z
  260.       )
  261.     )
  262.  
  263.     ;;;  Display interesting facts about the entities comprising
  264.     ;;;  this block definition.
  265.  
  266.     (setq e (fld -2 x))               ; point to first entity
  267.     (while e
  268.       (setq ed (entget e))            ; get the entity data
  269.       (setq et (fld  0 ed))           ; entity type
  270.       (setq ec (fld 62 ed))           ; entity color
  271.       (write-line
  272.         (strcat
  273.           (strfill " " 14)
  274.           (strfill et 9)              ; edit entity type
  275.           " on layer "
  276.           (fld 8 ed)                  ; edit layer name
  277.           " with color "
  278.           (cond 
  279.             ((= ec 0)  "BYBLOCK")     ; edit color number
  280.             ((null ec) "BYLAYER")
  281.             (T         (itoa ec))
  282.           )
  283.         )
  284.       )
  285.       (if (setq e (entnext e))        ; if there's another entity,
  286.           (setq ed (entget e))        ; read its data
  287.       )
  288.     )
  289.     (terpri)
  290.     (setq x (next nil))               ; get next block entry
  291.   )
  292.   (princ (if (= n 0) "  -None-\n\n" "\n"))
  293.   nil
  294. )
  295.  
  296. ;;;  (UCS) - Dump the UCS table
  297.  
  298. (defun ucs ( / n x na o xd yd)
  299.   (tblset "ucs")
  300.   (write-line 
  301.     "  UCS         Origin            X axis direction    Y axis direction")
  302.   (terpri)
  303.   (setq n  0)
  304.   (setq x  (next T))                  ; get first ucs
  305.   (while x
  306.     (setq n  (1+ n)
  307.           na (fld  2 x)               ; UCS name
  308.           o  (fld 10 x)               ; origin
  309.           xd (fld 11 x)               ; X axis direction
  310.           yd (fld 12 x)               ; Y axis direction
  311.     )
  312.     (write-line
  313.       (strcat
  314.         (if (= na cucs) "* " "  ")    ; flag current UCS
  315.         (strfill na 12)               ; edit UCS name
  316.         (strfill 
  317.           (strcat "("
  318.             (rtos (car o) 2 2)        ; edit UCS origin
  319.             ","
  320.             (rtos (cadr o) 2 2)
  321.             ","
  322.             (rtos (caddr o) 2 2)
  323.             ")"
  324.           ) 
  325.           18
  326.         )
  327.         (strfill 
  328.           (strcat "("
  329.             (rtos (car xd) 2 2)       ; edit X axis direction
  330.             ","
  331.             (rtos (cadr xd) 2 2)
  332.             ","
  333.             (rtos (caddr xd) 2 2)
  334.             ")"
  335.           ) 
  336.           20
  337.         )
  338.         "("
  339.         (rtos (car yd) 2 2)           ; edit Y axis direction
  340.         ","
  341.         (rtos (cadr yd) 2 2)        
  342.         ","
  343.         (rtos (caddr yd) 2 2)
  344.         ")"
  345.       )
  346.     )
  347.     (setq x (next nil))               ; get next UCS entry
  348.   )
  349.   (princ (if (= n 0) "  -None-\n\n" "\n"))
  350.   nil
  351. )
  352.  
  353. ;;;  (VPORT) - Dump the viewport table
  354.  
  355. (defun vport ( / n x na ll ur v)
  356.   (setq prev nil)
  357.   (tblset "vport")
  358.   (write-line "  Viewport    Lower left     Upper Right     View Mode")
  359.   (terpri)
  360.   (setq n  0)
  361.   (setq x  (nextvp T prev))           ; get first viewport
  362.   (while x
  363.     (setq n  (1+ n)
  364.           na (fld  2 x)               ; viewport name
  365.           ll (fld 10 x)               ; lower left corner
  366.           ur (fld 11 x)               ; upper right corner
  367.           v  (fld 71 x)               ; view mode
  368.     )
  369.     (write-line
  370.       (strcat
  371.         "  "
  372.         (strfill na 10)               ; edit viewport name
  373.         "  "
  374.         (strfill 
  375.           (strcat "("                 ; edit lower left corner
  376.             (rtos (car ll) 2 2)
  377.             ","
  378.             (rtos (cadr ll) 2 2)
  379.             ")"
  380.           ) 
  381.           15
  382.         )   
  383.         (strfill 
  384.           (strcat "("                 ; edit upper right corner
  385.             (rtos (car ur) 2 2)
  386.             ","
  387.             (rtos (cadr ur) 2 2)
  388.             ")"
  389.           ) 
  390.           15
  391.         )
  392.         " "
  393.         (rtos v 2 2)                  ; edit view mode
  394.       )
  395.     )
  396.     (setq x (nextvp nil prev))        ; get next viewport entry
  397.   )
  398.   (princ (if (= n 0) "  -None-\n\n" "\n"))
  399.   nil
  400. )
  401.  
  402. ;;;  Blank-fill the given string to a specified number of characters
  403.  
  404. (defun strfill (s len)
  405.   (substr (strcat s "                              ") 1 len)
  406. )
  407.  
  408. ;;;  Return the value associated with a particular entity field
  409.  
  410. (defun fld (num lst)
  411.   (cdr (assoc num lst))
  412. )
  413.  
  414. ;;;  Set up to process specified symbol table.  If TBLSORT is not yet
  415. ;;;  defined, ask user whether the entries should be sorted.  If sorting
  416. ;;;  is enabled, obtain all entries and sort them forming TBLENTS list.
  417.  
  418. (defun tblset (tbl / new s)
  419.   (textscr)
  420.   (setq tblname tbl)                  ; set table name
  421.   (if (null tblsort) 
  422.     (progn             ; sorting not yet determined
  423.       (initget 1 "Yes No")            ; Establish keywords, no null
  424.       (setq s (getkword "\nSort the entries (Y/N) ? "))
  425.       (setq tblsort (if (= s "Yes") 1 0))
  426.     )
  427.   )
  428.   (if (= tblsort 1) 
  429.     (progn              ; if sorting is enabled
  430.       (setq tblents nil)              ; start with null list
  431.       (setq new (cdr (assoc 2 (tblnext tbl T)))) ; get first entry name
  432.       (while new
  433.         (setq tblents (cons new tblents)) ; add to list
  434.         (setq new (cdr (assoc 2 (tblnext tbl)))) ; get next entry name
  435.       )
  436.       (setq tblents (str-sort tblents)) ; sort the name list
  437.     )
  438.   )
  439. )
  440.  
  441. ;;;  Obtain next (or first) entry from table, or from sorted entry list.
  442.  
  443. (defun next (first / temp)
  444.   (if (= tblsort 1) (progn            ; if sorting enabled
  445.      (setq temp (car tblents))        ; get next name from list
  446.      (if temp 
  447.        (progn                         ; if not end of list...
  448.          (setq tblents (cdr tblents)) ; chop from list
  449.          (tblsearch tblname temp)     ; get table entry for this name
  450.        )
  451.      )
  452.    )
  453.    (tblnext tblname first)            ; else get next (or first) table entry
  454.   )
  455. )
  456.  
  457. ;;;  Obtain next (or first) vports entry from table, or from sorted entry list.
  458.  
  459. (defun nextvp (first prev / temp)
  460.   (if (= tblsort 1) 
  461.     (progn             ; if sorting enabled
  462.       (if first
  463.         (setq temp (car tblents))     ; get first name from list
  464.         (progn
  465.           (setq prev (car tblents))   ; store previous name
  466.           (setq temp (cadr tblents))  ; get next name from list
  467.         )
  468.       )
  469.       (if temp 
  470.         (progn
  471.           (if (null first)
  472.             (setq tblents (cdr tblents)); chop from list
  473.           )
  474.           (if (= prev temp) 
  475.             (progn
  476.               (setq prev temp)
  477.               (tblnext tblname first) ; get next table entry
  478.             )
  479.             (progn
  480.               (setq prev temp)
  481.               (tblsearch tblname temp T) ; get table entry for this name
  482.             )
  483.           )
  484.         )
  485.       )
  486.     )
  487.     (tblnext tblname first)           ; else get next (or first) table entry
  488.   )
  489. )
  490.  
  491. ;;;  Sort a list of strings.
  492.  
  493. (defun str-sort (x)
  494.   (cond 
  495.     ((null (cdr x)) x)
  496.     (T (str-merge (str-sort (first-half x))
  497.                   (str-sort (last-half x)))
  498.     )
  499.   )
  500. )
  501.  
  502. (defun str-merge (a b)
  503.   (cond 
  504.     ((null a) b)
  505.     ((null b) a)
  506.     ((< (strcmp (car a) (car b)) 0)
  507.       (cons (car a) (str-merge (cdr a) b)))
  508.     (t 
  509.       (cons (car b) (str-merge a (cdr b)))
  510.     )
  511.   )
  512. )
  513.  
  514. (defun first-half (l)
  515.   (head l (1- (length l)))
  516. )
  517.  
  518. (defun head (l n)
  519.   (cond 
  520.     ((minusp n) nil)
  521.     (t (cons (car l) (head (cdr l) (- n 2))))
  522.   )
  523. )
  524.  
  525. (defun last-half (l)
  526.   (tail l (1- (length l)))
  527. )
  528.  
  529. (defun tail (l n)
  530.   (cond 
  531.     ((minusp n) l)
  532.     (t (tail (cdr l) (- n 2)))
  533.   )
  534. )
  535.  
  536. ;;;  Compare two strings.  Return 0 if they are equal, -1 if the
  537. ;;;  first string is less than the second in ASCII collating sequence,
  538. ;;;  and 1 if the second string is less than the first.
  539.  
  540. (defun strcmp (a b)
  541.   (cond 
  542.     ((= a b) 0)
  543.     (T 
  544.       (cond 
  545.         ((< (ascii a) (ascii b)) -1)
  546.         ((> (ascii a) (ascii b))  1)
  547.         (t (strcmp (substr a 2) (substr b 2)))
  548.       )
  549.     )
  550.   )
  551. )
  552.  
  553. ;;;  Dump all the symbol tables
  554.  
  555. (defun C:TABLES (/ olderr ocmd oblp)
  556.   (setq olderr  *error*
  557.         *error* myerror
  558.   )
  559.   (setq ocmd (getvar "cmdecho"))
  560.   (setq oblp (getvar "blipmode"))
  561.   (setvar "cmdecho" 0)
  562.   (setq tblsort nil)                  ; Force "Sort Y/N" query
  563.   (layer)
  564.   (ltype)
  565.   (view)
  566.   (style)
  567.   (block)
  568.   (ucs)
  569.   (vport)
  570.   (setvar "cmdecho" ocmd)
  571.   (setvar "blipmode" oblp)
  572.   (setq *error* olderr)               ; Restore old *error* handler
  573.   (princ)
  574. )
  575.