home *** CD-ROM | disk | FTP | other *** search
/ Liren Large Software Subsidy 13 / 13.iso / p / p024 / 10.img / BONUS3.LIB / TABLES.LSP < prev    next >
Encoding:
Text File  |  1993-02-08  |  16.8 KB  |  584 lines

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