Advertisement
btronic

chg lsp

Jun 25th, 2012
2,988
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
CAD Lisp 14.20 KB | None | 0 0
  1. ;;; -*-  Mode: LISP -*- Syntax: AutoLISP (C) Benjamin Olasov 1988, 1989
  2. ;;; Entity edit function C:CHG
  3. ;;; Displays and modifies the properties of individual entities.
  4.  
  5. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  6. ;;; File: CHG.LSP Copyright (C) Benjamin Olasov 1989 All Rights Reserved    ;;;
  7. ;;; Research/ commercial/ support inquiries:                                ;;;
  8. ;;;       Benjamin Olasov  236 East 28th Street   New York, NY  10025       ;;;
  9. ;;;                        PH (212) 725-4617                                ;;;
  10. ;;;                        MCI-Mail:  344-4003                              ;;;
  11. ;;;                        Arpanet Mailstop: olasov @ cs.columbia.edu       ;;;
  12. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  13.  
  14. ;; This program is provided 'as is' without warranty of any kind, either
  15. ;; expressed or implied, including, but not limited to the implied warranties of
  16. ;; merchantability and fitness for a particular purpose.  The entire risk as to
  17. ;; the quality and performance of the program is with the user.  Should the
  18. ;; program prove defective, the user assumes the entire cost of all necessary
  19. ;; servicing, repair or correction.
  20. ;; AutoLisp and AutoCad are registered trademarks of AutoDesk, Inc.
  21.  
  22. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  23. ;; CHG displays and modifies the properties of individual entities.          ;;
  24. ;;                                                                           ;;
  25. ;; CHG creates a numbered menu of the selected entities properties, and      ;;
  26. ;; then prompts the user to select the number of the property to modify.     ;;
  27. ;; CHG then prompts for a new value for that property, which may be a        ;;
  28. ;; point (list), real, integer, or string.                                   ;;
  29. ;;                                                                           ;;
  30. ;; Any changes made by CHG can be undone using AutoCad's 'U' command.        ;;
  31. ;; Doing so will return the drawing to its state before using CHG.           ;;
  32. ;;                                                                           ;;
  33. ;; A random example of using CHG:                                            ;;
  34. ;; In a drawing containing two valid blocks A and B, an individual           ;;
  35. ;; iteration of block A can be transformed to an iteration of block B by     ;;
  36. ;; giving B as its new name. All of its previous insertion parameters will   ;;
  37. ;; remain the same, but its identity will be changed to block B. If the      ;;
  38. ;; name of the layer in which the entity resides is changed to the name of   ;;
  39. ;; an existing layer, the entity will change its residence to that layer.    ;;
  40. ;; However, if the new layer name is the name of a non-existing layer, a     ;;
  41. ;; layer with that name will be created, and the entity will be transferred  ;;
  42. ;; to that layer.                                                            ;;
  43. ;;                                                                           ;;
  44. ;; Syntax: CHG                                                               ;;
  45. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  46.  
  47. (gc)
  48. (vmon)
  49. (princ "\nLoading- please wait.. -")
  50.  
  51. (defun descriptor (key e_type)
  52.        (cond ((null key) nil)
  53.              ((= key -1) "ENTITY NAME <RO>")
  54.              ((= key 0) "ENTITY TYPE")
  55.              ((= key 1) "TEXT VALUE")
  56.              ((and (= key 2)
  57.                    (= e_type "ATTDEF")) "ATTRIBUTE TAG")
  58.              ((and (= key 2)
  59.                    (= e_type "INSERT")) "BLOCK NAME")
  60.              ((= key 2) "NAME")
  61.              ((or (= key 3)
  62.                   (= key 4)) "OTHER NAME VALUES")
  63.              ((= key 5) "HANDLE <RO>")
  64.              ((= key 6) "LINETYPE NAME <RO>")
  65.              ((= key 7) "TEXT STYLE NAME <RO>")
  66.              ((= key 8) "LAYER")
  67.              ((= key 9) "VARIABLE NAME IDENTIFIER")
  68.              ((and (= key 10)
  69.                    (= e_type "INSERT")) "INSERTION BASE")
  70.              ((= key 10) "ORIGIN POINT")
  71.              ((and (>= key 11)
  72.                    (<= key 18)) "OTHER POINT COORDINATE")
  73.              ((= key 20) "PRIMARY Y COORDINATE")
  74.              ((and (>= key 21) (<= key 28)) "OTHER Y COORDINATE")
  75.              ((and (>= key 31) (<= key 36)) "OTHER Z COORDINATE")
  76.              ((= key 38) "ELEVATION")
  77.              ((= key 39) "THICKNESS")
  78.              ((and (>= key 40)
  79.                    (<= key 48)
  80.                    (or (= e_type "CIRCLE")
  81.                        (= e_type "ARC"))) "RADIUS")
  82.              ((and (>= key 40)
  83.                    (<= key 75)
  84.                    (= e_type "POLYLINE")) (pline_handler key ent))
  85.              ((and (>= key 40)
  86.                    (<= key 72)
  87.                    (or (= e_type "TEXT")
  88.                        (= e_type "ATTDEF"))) (text_handler key ent))
  89.              ((and (= key 41)
  90.                    (= e_type "INSERT")) "X SCALE FACTOR")
  91.              ((and (= key 42)
  92.                    (= e_type "INSERT")) "Y SCALE FACTOR")
  93.              ((and (= key 43)
  94.                    (= e_type "INSERT")) "Z SCALE FACTOR")
  95.              ((and (>= key 40)
  96.                    (<= key 48)) "FLOATING POINT VALUE")
  97.              ((= key 49) "REPEATED VALUE")
  98.              ((and (>= key 50)
  99.                    (<= key 58)) "ANGLE")
  100.              ((= key 62) "COLOR NUMBER <RO>")
  101.              ((= key 66) "VERTICES FOLLOW <RO>")
  102.              ((and (= key 70)
  103.                    (= e_type "3DFACE")) (3dface_handler key ent))
  104.              ((= key 71) "MIRROR DIRECTION")
  105.              ((and (>= key 70) (<= key 78)) "INTEGER VALUE")
  106.              ((or (= key 210)
  107.                   (= key 220)
  108.                   (= key 230)) "EXTRUSION DIRECTION COORDINATES")
  109.              ((= key 999) "COMMENTS")
  110.              (T "UNCLASSIFIED VALUE")))
  111.  
  112. (princ "\rLoading- please wait.. \\")
  113.  
  114. (defun format-input (key / val label)
  115.        (if (null key) nil
  116.            (progn (setq val (cdr (assoc key entity)))
  117.                   (graphscr)
  118.                   (cond ((= (type val) 'STR)
  119.                          (setq label (strcat (descriptor key etyp) ": "))
  120.                          (princ (strcat "\nCurrent " label))
  121.                          (princ val)
  122.                          (getstring T (strcat "\nNew " label)))
  123.                         ((= (type val) 'REAL)
  124.                          (cond ((and (>= key 40)
  125.                                      (<= key 48)
  126.                                 (or (= etyp "CIRCLE")
  127.                                     (= etyp "ARC")))
  128.                                 (setvar "coords" 2)
  129.                                 (princ "\nCurrent angle: ")
  130.                                 (princ val)
  131.                                 (getdist (cdr (assoc 10 entity)) "\nNew radius: "))
  132.                                ((and (>= key 50) (<= key 58))
  133.                                 (setvar "coords" 2)
  134.                                 (princ "\nCurrent angle: ")
  135.                                 (princ val)
  136.                                 (getangle (cdr (assoc 10 entity)) "\nNew angle: "))
  137.                               (T (setq label (strcat (descriptor key etyp) ": "))
  138.                                  (princ (strcat "\nCurrent " label))
  139.                                  (princ val)
  140.                                  (getreal (strcat "\nNew " label)))))
  141.                          ((= (type val)  'INT)
  142.                           (setq label (strcat (descriptor key etyp) ": "))
  143.                           (princ (strcat "\nCurrent " label))
  144.                           (princ val)
  145.                           (getint (strcat "\nNew " label)))
  146.                          ((= (type val) 'LIST)
  147.                           (setvar "coords" 2)
  148.                           (princ "\nCurrent point value: ")
  149.                           (princ val)
  150.                           (getpoint val "\nNew point: "))))))
  151.  
  152. (princ "\rLoading- please wait.. \|")
  153.  
  154. (defun C:CHG (/ entity counter ctr num tag new)
  155.        (if (setq ename (entsel))
  156.            (progn (setq ent (entget (car ename))
  157.                         entity (aux_remove (assoc 0 ent) ent)
  158.                         etyp (cdr (assoc 0 ent))
  159.                         header (strcat etyp " PROPERTY TABLE")
  160.                         num_props (length entity)
  161.                         counter 0
  162.                         ctr 0)
  163.                   (textscr)
  164.                   (repeat 5 (terpri))
  165.                   (repeat (- 38 (/ (strlen header) 2)) (princ "\260"))
  166.                   (princ (strcat " " header " "))
  167.                   (repeat (- 38 (/ (strlen header) 2)) (princ "\260"))
  168.                   (repeat (fix (/ (- 24 num_props) 2.0)) (terpri))
  169.                   (mapcar '(lambda (e)
  170.                                    (setq counter (1+ counter))
  171.                                    (princ (strcat (if (< counter 10)
  172.                                                       (strcat " " (itoa counter))
  173.                                                       (itoa counter))
  174.                                                   "]  "
  175.                                                   (strcat (descriptor (car e) etyp) ": ")))
  176.                                    (princ (cdr e))
  177.                                    (princ "\n"))
  178.                           entity)
  179.                   (repeat (fix (/ (- 24 num_props) 2.0)) (terpri))
  180.                   (setq num (getint "Number of property to change: "))
  181.                   (if (and num
  182.                            (> num 0)
  183.                            (<= num num_props))
  184.                       (progn (setq tag (car (nth (1- num) entity))
  185.                                    new (format-input tag)
  186.                                    ent (subst (cons tag new)
  187.                                               (assoc tag entity) ent)
  188.                                    cmd (getvar "cmdecho"))
  189.                              (setvar "cmdecho" 0)
  190.                              (command "undo" "mark")
  191.                              (setvar "cmdecho" cmd)
  192.                              (entmod ent))
  193.                       (princ "\nInvalid number.")))
  194.            (princ "\nNo entity selected."))
  195.        (princ))
  196.  
  197. (princ "\rLoading- please wait.. \/")
  198.  
  199. (defun text_handler (key elist)
  200.        (setq bit_code (cdr (assoc key elist)))
  201.        (cond ((= key 40) "TEXT HEIGHT")
  202.              ((= key 41) "RELATIVE X SCALE FACTOR")
  203.              ((= key 50) "ROTATION ANGLE")
  204.              ((= key 51) "OBLIQUING ANGLE")
  205.              ((= key 70)
  206.               (strcat "ATTRIBUTE FLAG "
  207.                       (cond ((= bit_code 1) "<INVISIBLE>")
  208.                             ((= bit_code 2) "<CONSTANT>")
  209.                             ((= bit_code 4) "<VERIFICATION REQD>")
  210.                             ((= bit_code 8) "<PRESET>")
  211.                             (T "<UNKNOWN BIT CODE>"))))
  212.              ((= key 71)
  213.               (strcat "TEXT GENERATION FLAG "
  214.                       (cond ((= bit_code 0) "")
  215.                             ((= bit_code 2) "<BACKWARDS>")
  216.                             ((= bit_code 4) "<UPSIDE DOWN>")
  217.                             (T "<UNKNOWN BIT CODE>"))))
  218.              ((= key 72)
  219.               (strcat "TEXT JUSTIFICATION FLAG "
  220.                       (cond ((= bit_code 0) "<LEFT JUSTIFIED>")
  221.                             ((= bit_code 1) "<CENTERED ALONG BASELINE>")
  222.                             ((= bit_code 2) "<RIGHT JUSTIFIED>")
  223.                             ((= bit_code 3) "<ALIGNED BETWEEN TWO POINTS>")
  224.                             ((= bit_code 4) "<MIDDLE CENTERED>")
  225.                             ((= bit_code 5) "<FIT BETWEEN TWO POINTS>")
  226.                             (T "<UNKNOWN CODE>"))))
  227.             (T "UNKNOWN TEXT FLAG")))
  228.  
  229. (princ "\rLoading- please wait.. \-")
  230.  
  231. (defun pline_handler (key elist)
  232.        (setq bit_code (cdr (assoc key elist)))
  233.        (cond ((= key 40) "STARTING WIDTH")
  234.              ((= key 41) "ENDING WIDTH")
  235.              ((= key 66) "VERTICES FOLLOW FLAG")
  236.              ((= key 70)
  237.               (strcat "POLYLINE FLAG "
  238.                       (cond ((= bit_code 1)  "<CLOSED>")
  239.                             ((= bit_code 2)  "<CURVE-FIT VERTICES ADDED>")
  240.                             ((= bit_code 4)  "<SPLINE-FIT VERTICES ADDED>")
  241.                             ((= bit_code 8)  "<3D POLYLINE>")
  242.                             ((= bit_code 16) "<3D MESH>")
  243.                             ((= bit_code 32) "<3D MESH CLOSED IN N DIRECTION>")
  244.                             (T "<UNKNOWN BIT CODE>"))))
  245.              ((or (= key 71)
  246.                   (= key 72)) (strcat "POLYGON MESH "
  247.                                       (if (= key 71) "M" "N")
  248.                                      " COUNT"))
  249.              ((or (= key 73)
  250.                   (= key 74)) (strcat "POLYGON MESH "
  251.                                       (if (= key 73) "M" "N")
  252.                                       " DENSITY"))
  253.              ((= key 75)
  254.               (strcat "SMOOTH SURFACE TYPE "
  255.                       (cond ((= bit_code 0)  "<NO SMOOTH SURFACE FITTED>")
  256.                             ((= bit_code 5)  "<QUADRATIC B-SPLINE>")
  257.                             ((= bit_code 6)  "<CUBIC B-SPLINE>")
  258.                             ((= bit_code 8)  "<BEZIER SURFACE>")
  259.                             (T "<UNKNOWN BIT CODE>"))))
  260.              (T "UNKNOWN POLYLINE FLAG")))
  261.  
  262. (princ "\rLoading- please wait.. \\")
  263.  
  264. (defun 3dface_handler (key elist)
  265.        (setq bit_code (cdr (assoc key elist)))
  266.        (cond ((= key 70)
  267.               (strcat "INVISIBLE EDGE FLAG "
  268.                       (cond ((= bit_code 0)  "<NO")
  269.                             ((= bit_code 1)  "<1ST")
  270.                             ((= bit_code 2)  "<2ND")
  271.                             ((= bit_code 4)  "<3RD")
  272.                             ((= bit_code 8)  "<4TH")
  273.                             (T "UNIDENTIFIED"))
  274.                       " EDGE INVISIBLE>"))))
  275.  
  276. (princ "\rLoading- please wait.. \|")
  277.  
  278. (defun aux_remove (atm lst)
  279.        (cond ((null lst) nil)
  280.              ((null (member atm lst)) lst)
  281.              ((equal atm (car lst)) (cdr lst))
  282.              (t (append (reverse (cdr (member atm (reverse lst))))
  283.                         (cdr (member atm lst))))))
  284.  
  285. (princ "\rFunction C:CHG loaded. Type CHG to start.")
  286. (princ)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement