home *** CD-ROM | disk | FTP | other *** search
/ Liren Large Software Subsidy 13 / 13.iso / p / p024 / 5.img / SUPPORT2.LIB / DDCHPROP.LSP < prev    next >
Encoding:
Text File  |  1992-09-08  |  29.9 KB  |  952 lines

  1. ;;;----------------------------------------------------------------------------
  2. ;;;
  3. ;;;   DDCHPROP.LSP   ¬⌐Ñ╗ 0.5
  4. ;;;
  5. ;;;   ¬⌐┼v (C) 1991-1992  Autodesk ñ╜Ñq
  6. ;;;
  7. ;;;   Ñ╗│n┼ΘºK╢O¿╤▒z╢iªµÑ⌠ª≤Ñ╬│~╗▌¿D¬║½■¿⌐íB¡╫º∩ñ╬╡oªµ, ª²¼O░╚╜╨┐φ┤`ñU¡z
  8. ;;;   ¡∞½h :
  9. ;;;
  10. ;;;   1)  ñWªC¬║¬⌐┼v│qºi░╚╗▌ÑX▓{ªb¿Cñ@Ñ≈½■¿⌐∙╪íC
  11. ;;;   2)  ¼█├÷¬║╗í⌐·ñσÑ≤ñ]Ñ▓╢╖⌐·╕ⁿ¬⌐┼v│qºiñ╬Ñ╗╢╡│\Ñi│qºiíC
  12. ;;;
  13. ;;;   Ñ╗│n┼Θ╢╚┤ú¿╤º@¼░└│Ñ╬ñW¬║░╤ª╥, ª╙Ñ╝┴n⌐·⌐╬┴⌠ºtÑ⌠ª≤½O├╥; ╣∩⌐≤Ñ⌠ª≤»S«φ
  14. ;;;   Ñ╬│~ñº╛A║┘⌐╩, ÑHñ╬░╙╖~╛P░Γ⌐╥┴⌠ºtÑX¿π¬║½O├╥, ªbª╣ñ@╖ºñ⌐ÑHº_╗{íC
  15. ;;;
  16. ;;;
  17. ;;;   2 February 1992
  18. ;;;
  19. ;;;----------------------------------------------------------------------------
  20. ;;;   DESCRIPTION
  21. ;;;----------------------------------------------------------------------------
  22. ;;;   C:DDCHPROP is a dialogue interface for the CHPROP command.
  23. ;;;
  24. ;;;   The command looks similar to DDEMODES.  The main dialogue has an image
  25. ;;;   tile, 3 buttons (layer, color, linetype), and an editbox (thickness).
  26. ;;;   The 3 buttons each launch a sub-dialogue containing a list and edit box.
  27. ;;;   The dialogues are all defined in the DDCHPROP.DCL file.
  28. ;;;
  29. ;;;
  30. ;;;----------------------------------------------------------------------------
  31. ;;;----------------------------------------------------------------------------
  32. ;;;   Prefixes in command and keyword strings:
  33. ;;;      "."  specifies the built-in AutoCAD command in case it has been
  34. ;;;           redefined.
  35. ;;;      "_"  denotes an AutoCAD command or keyword in the native language
  36. ;;;           version, English.
  37. ;;;----------------------------------------------------------------------------
  38. ;;;
  39. ;;;
  40. ;;; ===========================================================================
  41. ;;; ===================== load-time error checking ============================
  42. ;;;
  43.  
  44.   (defun ai_abort (app msg)
  45.      (defun *error* (s)
  46.         (if old_error (setq *error* old_error))
  47.         (princ)
  48.      )
  49.      (if msg
  50.        (alert (strcat " └│Ñ╬╡{ªí┐∙╗~: "
  51.                       app
  52.                       " \n\n  "
  53.                       msg
  54.                       "  \n"
  55.               )
  56.        )
  57.      )
  58.      (exit)
  59.   )
  60.  
  61. ;;; Check to see if AI_UTILS is loaded, If not, try to find it,
  62. ;;; and then try to load it.
  63. ;;;
  64. ;;; If it can't be found or it can't be loaded, then abort the
  65. ;;; loading of this file immediately, preserving the (autoload)
  66. ;;; stub function.
  67.  
  68.   (cond
  69.      (  (and ai_dcl (listp ai_dcl)))          ; it's already loaded.
  70.  
  71.      (  (not (findfile "ai_utils.lsp"))                     ; find it
  72.         (ai_abort "DDCHPROP"
  73.                   (strcat "ºΣñú¿∞íuAI_UTILS.LSPív└╔«╫;"
  74.                           "\n  ╜╨└╦¼díusupportívÑ╪┐²íC")))
  75.  
  76.      (  (eq "failed" (load "ai_utils" "failed"))            ; load it
  77.         (ai_abort "DDCHPROP" "╡L¬k╕ⁿñJíuAI_UTILS.LSPív└╔«╫"))
  78.   )
  79.  
  80.   (if (not (ai_acadapp))               ; defined in AI_UTILS.LSP
  81.       (ai_abort "DDCHPROP" nil)        ; a Nil <msg> supresses
  82.   )                                    ; ai_abort's alert box dialog.
  83.  
  84. ;;; ==================== end load-time operations ===========================
  85.  
  86. ;;; Initialize program subroutines and variables.
  87.  
  88. (defun ddchprop_init ()
  89.  
  90.   ;;
  91.   ;; Define buttons and set values in CHPROP dialogue box
  92.   ;;
  93.   (defun call_chp ()
  94.     (if (not (new_dialog "ch_prop" dcl_id)) (exit))
  95.     (set_tile "error" "")
  96.     ;; Set initial dialogue tile values
  97.     (set_col_tile)
  98.     (if (= lay-idx nil)
  99.       (set_tile "t_layer" "Varies")
  100.       (set_tile "t_layer" (nth lay-idx laynmlst))
  101.     )
  102.     (cond
  103.       ((= lt-idx nil)
  104.         (set_tile "t_ltype" "Varies")
  105.       )
  106.       ((= lt-idx 0) ; set tile "By layer & layer linetype"
  107.         (set_tile "t_ltype" (bylayer_lt))
  108.       )
  109.       (T
  110.         (set_tile "t_ltype" (nth lt-idx ltnmlst))
  111.       )
  112.     )
  113.     (if (or (= ethickness nil) (= ethickness "Varies"))
  114.       (set_tile "eb_thickness" "Varies")
  115.       (set_tile "eb_thickness" (rtos ethickness))
  116.     )
  117.     ;; Define action for tiles
  118.     (action_tile "b_color" "(setq ecolor (getcolor))")
  119.     (action_tile "show_image" "(setq ecolor (getcolor))")
  120.     (action_tile "b_name" "(setq elayer (getlayer))")
  121.     (action_tile "b_line" "(setq eltype (getltype))")
  122.     (action_tile "eb_thickness"  "(getthickness $value)")
  123.     (action_tile "help" "(acad_helpdlg \"acad.hlp\"  \"ddchprop\")")
  124.     (action_tile "accept" "(test-ok)")
  125.     (if (= (start_dialog) 1)
  126.       (progn
  127.         (command "_.chprop" ss "")
  128.         (if ecolor
  129.           (progn
  130.             (if (= 0 ecolor )   (setq ecolor "BYBLOCK"))
  131.             (if (= 256 ecolor ) (setq ecolor "BYLAYER"))
  132.             (command "_c" ecolor)
  133.           )
  134.         )
  135.         (if (and (/= eltype "Varies") lt-idx)
  136.           (command "_lt" eltype)
  137.         )
  138.         (if (and (/= elayer "Varies") lay-idx)
  139.           (command "_la" elayer)
  140.         )
  141.         (if (and (/= ethickness "Varies") ethickness)
  142.           (command "_t" ethickness)
  143.         )
  144.         (command "")
  145.       )
  146.       (princ "\níu⌐╩╜ΦívÑ╝┼▄º≤")
  147.     )
  148.     (princ)
  149.   )
  150.   ;;
  151.   ;; Function to set the Color text tile and swab to the current color value.
  152.   ;;
  153.   (defun set_col_tile()
  154.     (cond
  155.       ((= ecolor nil)
  156.         (set_tile "t_color" "Varies")
  157.         (col_tile "show_image" 0 nil)
  158.       )
  159.       ((= ecolor 0)
  160.         (set_tile "t_color" "BYBLOCK")
  161.         (col_tile "show_image" 0 nil)
  162.       )
  163.       ((= ecolor 1)
  164.         (set_tile "t_color" "1 red")
  165.         (col_tile "show_image" 1 nil)
  166.       )
  167.       ((= ecolor 2)
  168.         (set_tile "t_color" "2 yellow")
  169.         (col_tile "show_image" 2 nil)
  170.       )
  171.       ((= ecolor 3)
  172.         (set_tile "t_color" "3 green")
  173.         (col_tile "show_image" 3 nil)
  174.       )
  175.       ((= ecolor 4)
  176.         (set_tile "t_color" "4 cyan")
  177.         (col_tile "show_image" 4 nil)
  178.       )
  179.       ((= ecolor 5)
  180.         (set_tile "t_color" "5 blue")
  181.         (col_tile "show_image" 5 nil)
  182.       )
  183.       ((= ecolor 6)
  184.         (set_tile "t_color" "6 magenta")
  185.         (col_tile "show_image" 6 nil)
  186.       )
  187.       ((= ecolor 7)
  188.         (set_tile "t_color" "7 white")
  189.         (col_tile "show_image" 7 nil)
  190.       )
  191.       ;; If the color is "BYLAYER", then set the tile to
  192.       ;; show it's set By layer, but also indicate the
  193.       ;; color of the layer - i.e. By layer (red)
  194.       ((= ecolor 256)
  195.         (set_tile "t_color" (bylayer_col))
  196.         (col_tile "show_image" cn nil)
  197.       )
  198.       (T
  199.         (set_tile "t_color" (itoa ecolor))
  200.         (col_tile "show_image" ecolor nil)
  201.       )
  202.     )
  203.   )
  204.   ;;
  205.   ;;  Function to put up the standard color dialogue.
  206.   ;;
  207.   (defun getcolor(/ col_def temp_color)
  208.     ;; col_def is the default color used when rq_color is called.  If ecolor
  209.     ;; is nil (varies) then set it to 1, else use the value of ecolor.
  210.     (if ecolor
  211.       (setq col_def ecolor)
  212.       (setq col_def 1)
  213.     )
  214.     (if (numberp (setq temp_color (acad_colordlg col_def t)))
  215.       (progn
  216.         (setq ecolor temp_color)
  217.         (set_col_tile)
  218.         ecolor
  219.       )
  220.       ecolor
  221.     )
  222.   )
  223.   ;;
  224.   ;; This function pops a dialogue box consisting of a list box, image tile,
  225.   ;; and edit box to allow the user to select or type a linetype.  It returns
  226.   ;; the linetype selected.
  227.   ;;
  228.   (defun getltype (/ old-idx ltname)
  229.     ;; Initialize a dialogue from dialogue file
  230.     (if (not (new_dialog "setltype" dcl_id)) (exit))
  231.     (start_list "list_lt")
  232.     (mapcar 'add_list ltnmlst)         ; initialize list box
  233.     (end_list)
  234.     (setq old-idx lt-idx)
  235.     ;; Show initial ltype in image tile, list box, and edit box
  236.     (if (/= lt-idx nil)
  237.       (ltlist_act (itoa lt-idx))
  238.       (progn
  239.         (set_tile "edit_lt" "Varies")
  240.         (col_tile "show_image" 0 nil)
  241.       )
  242.     )
  243.     (action_tile "list_lt" "(ltlist_act $value)")
  244.     (action_tile "edit_lt" "(ltedit_act $value)")
  245.     (action_tile "accept" "(test-ok)")
  246.     (action_tile "cancel" "(reset-lt)")
  247.     (if (= (start_dialog) 1)           ; User pressed OK
  248.       (cond
  249.         ((= lt-idx nil)
  250.           (set_tile "t_ltype" "Varies")
  251.           "Varies"
  252.         )
  253.         ((= lt-idx 0)
  254.           (set_tile "t_ltype" (bylayer_lt))
  255.           "BYLAYER"
  256.         )
  257.         ((= lt-idx 1)
  258.           (set_tile "t_ltype" "BYBLOCK")
  259.           "BYBLOCK"
  260.         )
  261.         (T
  262.           (set_tile "t_ltype" ltname)
  263.           ltname
  264.         )
  265.       )
  266.       eltype
  267.     )
  268.   )
  269.   ;;
  270.   ;; Edit box entries end up here
  271.   ;;
  272.   (defun ltedit_act (ltvalue)
  273.     ;; If linetype name,is valid, then clear error string,
  274.     ;; call ltlist_act function, and change focus to list box.
  275.     ;; Else print error message.
  276.     (setq ltvalue (strcase ltvalue))
  277.     (if (or (= ltvalue "BYLAYER") (= ltvalue "BY LAYER"))
  278.       (setq ltvalue "BYLAYER")
  279.     )
  280.     (if (or (= ltvalue "BYBLOCK") (= ltvalue "BY BLOCK"))
  281.       (setq ltvalue "BYBLOCK")
  282.     )
  283.     (if (setq lt-idx (getindex ltvalue ltnmlst))
  284.       (progn
  285.         (set_tile "error" "")
  286.         (ltlist_act (itoa lt-idx))
  287.         (mode_tile "list_lt" 2)
  288.       )
  289.       (progn
  290.         (if (/= ltvalue "VARIES")
  291.           (set_tile "error" "íu╜u½¼ív╡L«─íC")
  292.         )
  293.         (setq lt-idx old-idx)
  294.       )
  295.     )
  296.   )
  297.   ;;
  298.   ;; List selections end up here
  299.   ;;
  300.   (defun ltlist_act (index / dashdata)
  301.     ;; Update the list box, edit box, and color tile
  302.     (set_tile "error" "")
  303.     (setq lt-idx (atoi index))
  304.     (setq ltname (nth lt-idx ltnmlst))
  305.     (setq dashdata (nth lt-idx mdashlist))
  306.     (col_tile "show_image" 0 dashdata)
  307.     (set_tile "list_lt" (itoa lt-idx))
  308.     (set_tile "edit_lt" ltname)
  309.   )
  310.   ;;
  311.   ;; Reset to original linetype when cancel it selected
  312.   ;;
  313.   (defun reset-lt ()
  314.     (setq lt-idx old-idx)
  315.     (done_dialog 0)
  316.   )
  317.   ;;
  318.   ;; This function pops a dialogue box consisting of a list box and edit box to
  319.   ;; allow the user to select or type a layer name.  It returns the layer name
  320.   ;; selected.  It also the status (On, Off, Frozen, etc.) of all layer in the
  321.   ;; drawing.
  322.   ;;
  323.   (defun getlayer (/ old-idx layname on off frozth linetype colname)
  324.     ;; Load a dialogue from dialogue file
  325.     (if (not (new_dialog "setlayer" dcl_id)) (exit))
  326.     (start_list "list_lay")
  327.     (mapcar 'add_list longlist)        ; initialize list box
  328.     (end_list)
  329.     ;; Display current layer, show initial layer name in edit
  330.     ;; box, and highlight list box.
  331.     (setq old-idx lay-idx)
  332.     (if (/= lay-idx nil) (laylist_act (itoa lay-idx)))
  333.     (set_tile "cur_layer" (getvar "clayer"))
  334.     (action_tile "list_lay" "(laylist_act $value)")
  335.     (action_tile "edit_lay" "(layedit_act $value)")
  336.     (action_tile "accept" "(test-ok)")
  337.     (action_tile "cancel" "(reset-lay)")
  338.     (if (= (start_dialog) 1)           ; User pressed OK
  339.       (progn
  340.         (if (= lay-idx nil) (setq layname "Varies"))
  341.         (set_tile "t_layer" layname)
  342.         ; If layer or ltype equals bylayer reset their tiles
  343.         (if (= lt-idx 0)
  344.           (set_tile "t_ltype" (bylayer_lt))
  345.         )
  346.         (if (= ecolor 256)
  347.           (progn
  348.             (set_tile "t_color" (bylayer_col))
  349.             (col_tile "show_image" cn nil)
  350.           )
  351.         )
  352.         layname
  353.       )
  354.       elayer
  355.     )
  356.   )
  357.   ;;
  358.   ;; Edit box selections end up here
  359.   ;;
  360.   (defun layedit_act (layvalue)
  361.     ;; Convert layer entry to upper case.  If layer name is
  362.     ;; valid, clear error string, call (laylist_act) function,
  363.     ;; and change focus to list box.  Else print error message.
  364.     (setq layvalue (strcase layvalue))
  365.     (if (setq lay-idx (getindex layvalue laynmlst))
  366.       (progn
  367.         (set_tile "error" "")
  368.         (laylist_act (itoa lay-idx))
  369.       )
  370.       (progn
  371.         (set_tile "error" "íu╝hªWív╡L«─íC")
  372.         (setq lay-idx old-idx)
  373.       )
  374.     )
  375.   )
  376.   ;;
  377.   ;; List entry selections end up here
  378.   ;;
  379.   (defun laylist_act (index / layinfo color dashdata)
  380.     ;; Update the list box, edit box, and color tile
  381.     (set_tile "error" "")
  382.     (setq lay-idx (atoi index))
  383.     (setq layname (nth lay-idx laynmlst))
  384.     (setq layinfo (tblsearch "layer" layname))
  385.     (if (= (logand (cdr (assoc 70 layinfo)) 4) 4)
  386.       (set_tile "error" "╡L¬k▒N╣╧ñ╕┼▄º≤ª▄íu┬Ω┼@ív¬║╣╧╝hñWíC")
  387.       (progn
  388.         (setq color (cdr (assoc 62 layinfo)))
  389.         (setq color (abs color))
  390.         (setq colname (colorname color))
  391.         (set_tile "list_lay" (itoa lay-idx))
  392.         (set_tile "edit_lay" layname)
  393.         (mode_tile "list_lay" 2)
  394.       )
  395.     )
  396.   )
  397.   ;;
  398.   ;; Reset to original layer when cancel is selected
  399.   ;;
  400.   (defun reset-lay ()
  401.     (setq lay-idx old-idx)
  402.     (done_dialog 0)
  403.   )
  404.   ;;
  405.   ;; Checks validity of thickness from edit box. Since (atof) returns 0 when a
  406.   ;; string can't be converted to a real, this routine checks if the first
  407.   ;; character is "0".  It also checks to see if the value equals "Varies".
  408.   ;;
  409.   (defun getthickness (value)
  410.     (setq value (strcase value))
  411.     (if (or (= value "VARIES")
  412.             (distof value)
  413.         )
  414.       (progn
  415.         (set_tile "error" "")
  416.         (if (= value "VARIES")
  417.           (progn
  418.             (set_tile "eb_thickness" "Varies")
  419.             (setq ethickness nil)
  420.           )
  421.           (progn
  422.             (setq ethickness (distof value))
  423.             (set_tile "eb_thickness" (rtos ethickness))
  424.             ethickness
  425.           )
  426.         )
  427.       )
  428.       (progn
  429.         (set_tile "error" "íu½p½╫ív╡L«─íC")
  430.         nil
  431.       )
  432.     )
  433.   )
  434.   ;;
  435.   ;; This function make a list called laynmlst which consists of all the layer
  436.   ;; names in the drawing.  It also creates a list called longlist which
  437.   ;; consists of strings which contain the layer name, color, linetype, etc.
  438.   ;; Longlist is later mapped into the layer listbox.  Both are ordered the
  439.   ;; same.
  440.   ;;
  441.   (defun makelaylists (/ layname onoff frozth color linetype vpf vpn ss cvpname
  442.                          xdlist vpldata sortlist name templist bit-70
  443.                       )
  444.     (if (= (setq tilemode (getvar "tilemode")) 0)
  445.       (progn
  446.         (setq ss (ssget "x" (list (cons 0 "VIEWPORT")
  447.                                   (cons 69 (getvar "CVPORT"))
  448.                             )
  449.                  )
  450.         )
  451.         (setq cvpname (ssname ss 0))
  452.         (setq xdlist (assoc -3 (entget cvpname '("acad"))))
  453.         (setq vpldata (cdadr xdlist))
  454.       )
  455.     )
  456.     (setq sortlist nil)
  457.     (setq templist (tblnext "LAYER" T))
  458.     (while templist
  459.       (setq name (cdr (assoc 2 templist)))
  460.       (setq sortlist (cons name sortlist))
  461.       (setq templist (tblnext "LAYER"))
  462.     )
  463.     (if (>= (getvar "maxsort") (length sortlist))
  464.       (setq sortlist (acad_strlsort sortlist))
  465.       (setq sortlist (reverse sortlist))
  466.     )
  467.     (setq laynmlst sortlist)
  468.     (setq longlist nil)
  469.     (setq layname (car sortlist))
  470.     (while layname
  471.       (setq laylist (tblsearch "LAYER" layname))
  472.       (setq color (cdr (assoc 62 laylist)))
  473.       (if (minusp color)
  474.         (setq onoff ".")
  475.         (setq onoff "On")
  476.       )
  477.       (setq color (abs color))
  478.       (setq colname (colorname color))
  479.       (setq bit-70 (cdr (assoc 70 laylist)))
  480.       (if (= (logand bit-70 1) 1)
  481.         (setq frozth "F" fchk laylist)
  482.         (setq frozth ".")
  483.       )
  484.       (if (= (logand bit-70 2) 2)
  485.         (setq vpn "N")
  486.         (setq vpn ".")
  487.       )
  488.       (if (= (logand bit-70 4) 4)
  489.         (setq lock "L")
  490.         (setq lock ".")
  491.       )
  492.       (setq linetype (cdr (assoc 6 laylist)))
  493.       (setq layname (substr layname 1 31))
  494.       (if (= tilemode 0)
  495.         (progn
  496.           (if (member (cons 1003 layname) vpldata)
  497.             (setq vpf "C")
  498.             (setq vpf ".")
  499.           )
  500.         )
  501.         (setq vpf ".")
  502.       )
  503.       (setq ltabstr (strcat layname "\t"
  504.                               onoff "\t"
  505.                              frozth "\t"
  506.                                lock "\t"
  507.                                 vpf "\t"
  508.                                 vpn "\t"
  509.                             colname "\t"
  510.                            linetype
  511.                     )
  512.       )
  513.       (setq longlist (append longlist (list ltabstr)))
  514.       (setq sortlist (cdr sortlist))
  515.       (setq layname (car sortlist))
  516.     )
  517.   )
  518.   ;;
  519.   ;; This function makes 2 lists - ltnmlst & mdashlist.  Ltnmlst is a list of
  520.   ;; linetype names read from the symbol table.  Mdashlist is list consisting
  521.   ;; of lists which define the linetype pattern - numbers that indicate dots,
  522.   ;; dashes, and spaces taken from group code 49.  The list corresponds to the
  523.   ;; order of names in ltnmlst.
  524.   ;;
  525.   (defun makeltlists (/ ltlist ltname)
  526.     (setq mdashlist nil)
  527.     (setq ltlist (tblnext "LTYPE" T))
  528.     (setq ltname (cdr (assoc 2 ltlist)))
  529.     (setq ltnmlst (list ltname))
  530.  
  531.     (if (= ltname "CONTINUOUS")
  532.       (setq mdashlist (list "CONT"))
  533.       (setq mdashlist
  534.             (append mdashlist (list (add-mdash ltlist)))
  535.       )
  536.     )
  537.     (while (setq ltlist (tblnext "LTYPE"))
  538.            (setq ltname (cdr (assoc 2 ltlist)))
  539.            (setq ltnmlst (append ltnmlst (list ltname)))
  540.            (setq mdashlist
  541.                 (append mdashlist (list (add-mdash ltlist)))
  542.            )
  543.     )
  544.     (setq ltnmlst (cons "BYBLOCK" ltnmlst))
  545.     (setq mdashlist  (cons nil mdashlist))
  546.     (setq ltnmlst (cons "BYLAYER" ltnmlst))
  547.     (setq mdashlist  (cons nil mdashlist))
  548.   )
  549.   ;;
  550.   ;; Get all the group code 49 values for a linetype and put them in a list
  551.   ;; (pen-up, pen-down info)
  552.   ;;
  553.   (defun add-mdash (ltlist1 / dashlist assoclist dashsize)
  554.     (setq dashlist nil)
  555.     (while (setq assoclist (car ltlist1))
  556.       (if (= (car assoclist) 49)
  557.         (progn
  558.           (setq dashsize (cdr assoclist))
  559.           (setq dashlist (cons dashsize dashlist))
  560.         )
  561.       )
  562.       (setq ltlist1 (cdr ltlist1))
  563.     )
  564.     (setq dashlist (reverse dashlist))
  565.   )
  566.   ;;
  567.   ;; Color a tile, draw linetype, and draw a border around it
  568.   ;;
  569.   (defun col_tile (tile color patlist / x y)
  570.     (setq x (dimx_tile tile))
  571.     (setq y (dimy_tile tile))
  572.     (start_image tile)
  573.     (fill_image 0 0 x y color)
  574.     (if (= color 7)
  575.       (progn
  576.         (if patlist (drawpattern x (/ y 2) patlist 0))
  577.         (tile_rect 0 0 x y 0)
  578.       )
  579.       (progn
  580.         (if patlist (drawpattern x (/ y 2) patlist 7))
  581.         (tile_rect 0 0 x y 7)
  582.       )
  583.     )
  584.     (end_image)
  585.   )
  586.   ;;
  587.   ;; Draw a border around a tile
  588.   ;;
  589.   (defun tile_rect (x1 y1 x2 y2 color)
  590.     (setq x2 (- x2 1))
  591.     (setq y2 (- y2 1))
  592.     (vector_image x1 y1 x2 y1 color)
  593.     (vector_image x2 y1 x2 y2 color)
  594.     (vector_image x2 y2 x1 y2 color)
  595.     (vector_image x1 y2 x1 y1 color)
  596.   )
  597.   ;;
  598.   ;; Draw the linetype pattern in a tile.  Boxlength is the length of the image
  599.   ;; tile, y2 is the midpoint of the height of the image tile, pattern is a
  600.   ;; list of numbers that define the linetype, and color is the color of the
  601.   ;; tile.
  602.   ;;
  603.   (defun drawpattern (boxlength y2 pattern color / x1 x2
  604.                       patlist dash)
  605.     (setq x1 0 x2 0)
  606.     (setq patlist pattern)
  607.     (if (= patlist "CONT")
  608.       (progn
  609.         (setq dash boxlength)
  610.         (vi)
  611.         (setq x1 boxlength)
  612.       )
  613.     )
  614.     (while (< x1 boxlength)
  615.       (if (setq dash (car patlist))
  616.         (progn
  617.           (setq dash (fix (* 30 dash)))
  618.           (cond
  619.             ((= dash 0)
  620.               (setq dash 1)
  621.               (vi)
  622.             )
  623.             ((> dash 0)
  624.               (vi)
  625.             )
  626.             (T
  627.               (if (< (abs dash) 2) (setq dash 2))
  628.               (setq x2 (+ x2 (abs dash)))
  629.             )
  630.           )
  631.           (setq patlist (cdr patlist))
  632.           (setq x1 x2)
  633.         )
  634.         (setq patlist pattern)
  635.       )
  636.     )
  637.   )
  638.   ;;
  639.   ;; Draw a dash or dot in image tile
  640.   ;;
  641.   (defun vi ()
  642.     (setq x2 (+ x2 dash))
  643.     (vector_image x1 y2 x2 y2 color)
  644.   )
  645.   ;;
  646.   ;; This function takes a selection and returns a list of the color, linetype,
  647.   ;; layer, and thickness properties that are common to every entities in the
  648.   ;; selection set - (color linetype layer thickness).  If all entities do not
  649.   ;; share the same property value it returns "Varies" in place of the
  650.   ;; property value.  i.e. ("BYLAYER" "DASHED" "Varies" 0)
  651.   ;;
  652.   (defun getprops (selset / sslen elist color ltype layer
  653.                             thickness go chk-col chk-lt chk-lay chk-th ctr)
  654.     (setq sslen (sslength selset))
  655.     (setq elist (entget (ssname selset 0)))
  656.     (setq color (cdr (assoc 62 elist)))
  657.     (if (not color) (setq color 256))
  658.     (setq ltype (cdr (assoc 6 elist)))
  659.     (if (not ltype) (setq ltype "BYLAYER"))
  660.     (setq layer (cdr (assoc 8 elist)))
  661.     (setq thickness (cdr (assoc 39 elist)))
  662.     (if (not thickness) (setq thickness 0))
  663.     (setq go T chk-col T chk-lt T chk-lay T chk-th T ctr 1)
  664.  
  665.     ;; Page through the selection set.  When a property
  666.     ;; does not match, stop checking for that property.
  667.     ;; If all properties vary, stop paging.
  668.  
  669.     (while (and (> sslen ctr) go)
  670.       (setq elist (entget (setq en (ssname selset ctr))))
  671.       (if chk-col (match-col))
  672.       (if chk-lt (match-lt))
  673.       (if chk-lay (match-lay))
  674.       (if chk-th (match-th))
  675.       (setq ctr (1+ ctr))
  676.       (if (and (not chk-col) (not chk-lt) (not chk-lay) (not chk-th))
  677.         (setq go nil)
  678.       )
  679.     )
  680.     (list color ltype layer thickness)
  681.   )
  682.  
  683.   (defun match-col (/ ncolor)
  684.     (setq ncolor (cdr (assoc 62 elist)))
  685.     (if (not ncolor) (setq ncolor 256))
  686.     (if (/= color ncolor)
  687.       (progn
  688.         (setq chk-col nil)
  689.         (setq color nil)
  690.       )
  691.     )
  692.   )
  693.  
  694.   (defun match-lt (/ nltype)
  695.     (setq nltype (cdr (assoc 6 elist)))
  696.     (if (not nltype) (setq nltype "BYLAYER"))
  697.     (if (/= ltype nltype)
  698.       (progn
  699.         (setq chk-lt nil)
  700.         (setq ltype "Varies")
  701.       )
  702.     )
  703.   )
  704.  
  705.   (defun match-lay (/ nlayer)
  706.     (setq nlayer (cdr (assoc 8 elist)))
  707.     (if (/= layer nlayer)
  708.       (progn
  709.         (setq chk-lay nil)
  710.         (setq layer "Varies")
  711.       )
  712.     )
  713.   )
  714.  
  715.   (defun match-th (/ nthickness)
  716.     (setq nthickness (cdr (assoc 39 elist)))
  717.     (if (not nthickness) (setq nthickness 0))
  718.     (if (/= thickness nthickness)
  719.       (progn
  720.         (setq chk-th nil)
  721.         (setq thickness "Varies")
  722.       )
  723.     )
  724.   )
  725.  
  726.   ;;
  727.   ;; If an item is a member of the list, then return its index number, else
  728.   ;; return nil.
  729.   ;;
  730.   (defun getindex (item itemlist / m n)
  731.     (setq n (length itemlist))
  732.     (if (> (setq m (length (member item itemlist))) 0)
  733.         (- n m)
  734.         nil
  735.     )
  736.   )
  737.   ;;
  738.   ;; This function is called if the linetype is set "BYLAYER". It finds the
  739.   ;; ltype of the layer so it can be displayed beside the linetype button.
  740.   ;;
  741.   (defun bylayer_lt (/ layname layinfo ltype)
  742.     (if lay-idx
  743.       (progn
  744.         (setq layname (nth lay-idx laynmlst))
  745.         (setq layinfo (tblsearch "layer" layname))
  746.         (setq ltype (cdr (assoc 6 layinfo)))
  747.         (strcat "BYLAYER (" ltype ")")
  748.       )
  749.       "BYLAYER"
  750.     )
  751.   )
  752.   ;;
  753.   ;; This function is called if the color is set "BYLAYER".  It finds the
  754.   ;; color of the layer so it can be displayed  beside the color button.
  755.   ;;
  756.   (defun bylayer_col (/ layname layinfo color)
  757.     (if lay-idx
  758.       (progn
  759.         (setq layname (nth lay-idx laynmlst))
  760.         (setq layinfo (tblsearch "layer" layname))
  761.         (setq color (abs (cdr (assoc 62 layinfo))))
  762.         (setq cn color)
  763.         (strcat "BYLAYER (" (colorname color) ")")
  764.       )
  765.       (progn
  766.         (setq cn 0)
  767.         "BYLAYER"
  768.       )
  769.     )
  770.   )
  771.   ;;
  772.   ;; If there is no error message, then close the dialogue
  773.   ;;
  774.   ;; If there is an error message, then set focus to the tile
  775.   ;; that's associated with the error message.
  776.   ;;
  777.   (defun test-ok ( / errtile)
  778.     (setq errtile (get_tile "error"))
  779.     (cond
  780.       (  (= errtile "")
  781.          (done_dialog 1))
  782.       (  (= errtile "íu½p½╫ív╡L«─íC")
  783.          (mode_tile "eb_thickness" 2))
  784.     )
  785.   )
  786.   ;;
  787.   ;; A color function used by getlayer.
  788.   ;;
  789.   (defun colorname (colnum)
  790.     (setq cn (abs colnum))
  791.     (cond ((= cn 1) "red")
  792.           ((= cn 2) "yellow")
  793.           ((= cn 3) "green")
  794.           ((= cn 4) "cyan")
  795.           ((= cn 5) "blue")
  796.           ((= cn 6) "magenta")
  797.           ((= cn 7) "white")
  798.           (T (itoa cn))
  799.     )
  800.   )
  801.  
  802. ;;; Construct layer and ltype lists and initialize all
  803. ;;; program variables:
  804.  
  805.   (makelaylists)                     ; layer list - laynmlst
  806.   (makeltlists)                      ; linetype lists - ltnmlst, mdashlist
  807.   ;; Find the property values of the selection set.
  808.   ;; (getprops ss) returns a list of properties from
  809.   ;; a selection set - (color ltype layer thickness).
  810.   (setq proplist (getprops ss))
  811.   (setq ecolor (car proplist))
  812.   (setq eltype (cadr proplist))
  813.   (setq elayer (caddr proplist))
  814.   (setq ethickness (cadddr proplist))
  815.   ;; Find index of linetype, and layer lists
  816.   (cond
  817.     ((= eltype "Varies") (setq lt-idx nil))
  818. ;   ((= eltype "BYLAYER") (setq lt-idx (getindex "BYLAYER" ltnmlst)))
  819. ;   ((= eltype "BYBLOCK") (setq lt-idx (getindex "BYBLOCK" ltnmlst)))
  820.     (T (setq lt-idx (getindex eltype ltnmlst)))
  821.   )
  822.   (if (= elayer "Varies")
  823.       (setq lay-idx nil)
  824.       (setq lay-idx (getindex elayer laynmlst))
  825.   )
  826.   (if (= ethickness "Varies")
  827.       (setq ethickness nil)
  828.   )
  829.  
  830. )   ; end (ddchprop_init)
  831.  
  832. ;;; (ddchprop_select)
  833. ;;;
  834. ;;; Aquires selection set for DDCHPROP, in one of three ways:
  835. ;;;
  836. ;;;   1 - Autoselected.
  837. ;;;   2 - Prompted for.
  838. ;;;   3 - Passed as an argument in a call to (ddchprop <ss> )
  839. ;;;
  840. ;;; The (ddchprop_select) function also sets the value of the
  841. ;;; global symbol AI_SELTYPE to one of the above three values to
  842. ;;; indicate the method thru which the entity was aquired.
  843.  
  844.  
  845. (defun ddchprop_select ()
  846.    (cond
  847.       (  (and ss (eq (type ss) 'pickset))        ; selection set passed to
  848.          (cond                                   ; (ddchprop) as argument
  849.             (  (not (zerop (sslength ss)))       ;   If not empty, then
  850.                (setq ai_seltype 3)               ;   then return pickset.
  851.                (ai_return ss))))
  852.  
  853.       (  (ai_aselect))                          ; Use current selection
  854.                                                 ; set or prompt for objects
  855.  
  856.       (t (princ "\nÑ╝┐∩¿∞¬½┼ΘíC")
  857.          (ai_return nil))
  858.    )
  859. )
  860.  
  861. ;;; Define command function.
  862.  
  863. (defun C:DDCHPROP ()
  864.    (ddchprop nil)
  865.    (princ)
  866. )
  867.  
  868.  
  869. ;;; Main program function - callable as a subroutine.
  870. ;;;
  871. ;;; (ddchprop <pickset> )
  872. ;;;
  873. ;;; <pickset> is the selection set of objects to be changed.
  874. ;;;
  875. ;;; If <pickset> is nil, then the current selection set is
  876. ;;; aquired, if one exists.  Otherwise, the user is prompted
  877. ;;; to select the objects to be changed.
  878. ;;;
  879. ;;; Before (ddchprop) can be called as a subroutine, it must
  880. ;;; be loaded first.  It is up to the calling application to
  881. ;;; first determine this, and load it if necessary.
  882.  
  883. (defun ddchprop (ss  /
  884.  
  885.                   add-mdash      ecolor          ltedit_act      s
  886.                   assoclist      elayer          ltidx           selset
  887.                   bit-70         elist           ltlist          set_col_tile
  888.                   boxlength      eltype          ltlist1
  889.                   bylayer-lt     en              ltlist_act      sortlist
  890.                   bylayer_col    ethickness      ltname
  891.                   bylayer_lt     fchk            ltnmlst         sslen
  892.                   call_chp       frozth          ltvalue         templist
  893.                   chk-col        getcolor        ltype           temp_color
  894.                   chk-lay        getindex        m               test-ok
  895.                   chk-lt         getlayer        makelaylists    testidx
  896.                   chk-th         getltype        makeltlists     testlay
  897.                   cmd            getprops        match-col       th-value
  898.                   cmdecho        getthickness    match-in        thickness
  899.                   cn             globals         match-lay       tile
  900.                   cnum           go              match-lt        tilemode
  901.                   col-idx        index           match-th        tile_rect
  902.                   colname        item            match_col       vi
  903.                   colnum         item1           mdashlist       vpf
  904.                   color          item2           n               vpldata
  905.                   colorname      itemlist        name            vpn
  906.                   col_def        lay-idx         ncolor          x
  907.                   col_tile       layedit_act     nlayer          x1
  908.                   ctr            layer           nltype          x2
  909.                   cvpname        layinfo         nthickness      xdlist
  910.                   dash           laylist         off             y
  911.                   dashdata       laylist_act     old-idx         y1
  912.                   dashlist       layname         olderr          y2
  913.                   dashsize       laynmlst        on              undo_init
  914.                   dcl_id         layvalue        onoff
  915.                                  linetype        patlist
  916.                   ddchprop-err   list1           pattern
  917.                   longlist       proplist
  918.                   lt-idx         reset-lay
  919.                   drawpattern    ltabstr         reset-lt
  920.                 )
  921.  
  922.   (setq old_cmd (getvar "cmdecho")    ; save current setting of cmdecho
  923.         old_error  *error*            ; save current error function
  924.         *error* ai_error              ; new error function
  925.   )
  926.  
  927.   (setvar "cmdecho" 0)
  928.  
  929.   (cond
  930.      (  (not (ai_notrans)))                      ; Not transparent?
  931.      (  (not (ai_acadapp)))                      ; ACADAPP.EXP xloaded?
  932.      (  (not (setq dcl_id (ai_dcl "ddchprop")))) ; is .DCL file loaded?
  933.      (  (not (setq ss (ddchprop_select))))       ; objects to modify?
  934.  
  935.      (t (ai_undo_push)
  936.         (ddchprop_init)                          ; Everything's cool,
  937.         (call_chp)                               ; so proceed!
  938.         (ai_undo_pop)
  939.      )
  940.   )
  941.  
  942.   (setq *error* old_error)
  943.   (setvar "cmdecho" old_cmd)
  944.   (princ)
  945. )
  946.  
  947. ;;;----------------------------------------------------------------------------
  948.  
  949. (princ "   íuDDCHPROPívñw╕ⁿñJíC")
  950. (princ)
  951.  
  952.