home *** CD-ROM | disk | FTP | other *** search
/ Windows 95 v2.4 Fix / W95-v2.4fix.iso / ACADWIN / SUPPORT / DDCHPROP.LSP < prev    next >
Encoding:
Lisp/Scheme  |  1995-02-08  |  36.8 KB  |  1,161 lines

  1. ; Next available MSG number is    41 
  2. ; MODULE_ID DDCHPROP_LSP_
  3. ;;;----------------------------------------------------------------------------
  4. ;;;
  5. ;;;    DDCHPROP.LSP   Version 0.5
  6. ;;;
  7. ;;;    Copyright (C) 1991, 1992, 1993, 1994 by Autodesk, Inc.
  8. ;;;
  9. ;;;    Permission to use, copy, modify, and distribute this software
  10. ;;;    for any purpose and without fee is hereby granted, provided
  11. ;;;    that the above copyright notice appears in all copies and
  12. ;;;    that both that copyright notice and the limited warranty and
  13. ;;;    restricted rights notice below appear in all supporting
  14. ;;;    documentation.
  15. ;;;
  16. ;;;    AUTODESK PROVIDES THIS PROGRAM "AS IS" AND WITH ALL FAULTS.
  17. ;;;    AUTODESK SPECIFICALLY DISCLAIMS ANY IMPLIED WARRANTY OF
  18. ;;;    MERCHANTABILITY OR FITNESS FOR A PARTICULAR USE.  AUTODESK, INC.
  19. ;;;    DOES NOT WARRANT THAT THE OPERATION OF THE PROGRAM WILL BE
  20. ;;;    UNINTERRUPTED OR ERROR FREE.
  21. ;;;
  22. ;;;    Use, duplication, or disclosure by the U.S. Government is subject to
  23. ;;;    restrictions set forth in FAR 52.227-19 (Commercial Computer
  24. ;;;    Software - Restricted Rights) and DFAR 252.227-7013(c)(1)(ii) 
  25. ;;;    (Rights in Technical Data and Computer Software), as applicable.
  26. ;;;
  27. ;;;.
  28. ;;;   2 February 1992
  29. ;;;   
  30. ;;;----------------------------------------------------------------------------
  31. ;;;   DESCRIPTION
  32. ;;;----------------------------------------------------------------------------
  33. ;;;   C:DDCHPROP is a dialogue interface for the CHPROP command.
  34. ;;;
  35. ;;;   The command looks similar to DDEMODES.  The main dialogue has an image 
  36. ;;;   tile, 3 buttons (layer, color, linetype), and an editbox (thickness).   
  37. ;;;   The 3 buttons each launch a sub-dialogue containing a list and edit box.  
  38. ;;;   The dialogues are all defined in the DDCHPROP.DCL file.
  39. ;;;
  40. ;;;
  41. ;;;----------------------------------------------------------------------------
  42. ;;;----------------------------------------------------------------------------
  43. ;;;   Prefixes in command and keyword strings: 
  44. ;;;      "."  specifies the built-in AutoCAD command in case it has been        
  45. ;;;           redefined.
  46. ;;;      "_"  denotes an AutoCAD command or keyword in the native language
  47. ;;;           version, English.
  48. ;;;----------------------------------------------------------------------------
  49. ;;;
  50. ;;;
  51. ;;; Avoid (gc)s on load to improve load time.
  52. ;;;
  53. (defun do_alloc (/ old_allod new_alloc)
  54.   (setq old_alloc (alloc 2000) new_alloc (alloc 2000))
  55.   (expand (1+ (/ 4750 new_alloc)))
  56.   (alloc old_alloc)
  57. )
  58. (do_alloc)
  59. (setq do_alloc nil)
  60. ;;;
  61. ;;; ===========================================================================
  62. ;;; ===================== load-time error checking ============================
  63. ;;;
  64.  
  65.   (defun ai_abort (app msg)
  66.      (defun *error* (s)
  67.         (if old_error (setq *error* old_error))
  68.         (princ)
  69.      )
  70.      (if msg
  71.        (alert (strcat " Error en la aplicaci≤n: "
  72.                       app
  73.                       " \n\n  "
  74.                       msg
  75.                       "  \n"
  76.               )
  77.        )
  78.      )
  79.      (exit)
  80.   )
  81.  
  82. ;;; Check to see if AI_UTILS is loaded, If not, try to find it,
  83. ;;; and then try to load it.
  84. ;;;
  85. ;;; If it can't be found or it can't be loaded, then abort the
  86. ;;; loading of this file immediately, preserving the (autoload)
  87. ;;; stub function.
  88.  
  89.   (cond
  90.      (  (and ai_dcl (listp ai_dcl)))          ; it's already loaded.
  91.  
  92.      (  (not (findfile "ai_utils.lsp"))                     ; find it
  93.         (ai_abort "DDCHPROP"
  94.                   (strcat "Imposible localizar el archivo AI_UTILS.LSP."
  95.                           "\n Compruebe el directorio de soporte.")))
  96.  
  97.      (  (eq "failed" (load "ai_utils" "failed"))            ; load it
  98.         (ai_abort "DDCHPROP" "Imposible cargar el archivo AI_UTILS.LSP"))
  99.   )
  100.  
  101.   (if (not (ai_acadapp))               ; defined in AI_UTILS.LSP
  102.       (ai_abort "DDCHPROP" nil)        ; a Nil <msg> supresses
  103.   )                                    ; ai_abort's alert box dialog.
  104.  
  105. ;;; ==================== end load-time operations ===========================
  106.  
  107. ;;; Initialize program subroutines and variables.
  108.  
  109. (defun ddchprop_init()
  110.  
  111.   ;;
  112.   ;; Define buttons and set values in CHPROP dialogue box 
  113.   ;;
  114.   (defun call_chp (/ cmdact)
  115.     (if (not (new_dialog "ch_prop" dcl_id)) (exit))
  116.     (set_tile "error" "")
  117.     ;; Set initial dialogue tile values
  118.     (set_col_tile)
  119.     (set_tile "t_layer" elayer)
  120.  
  121. ;    (if (= lay-idx nil)
  122. ;      (set_tile "t_layer" ;|DDCHPROP_LSP_6|;"Varies")
  123. ;      (set_tile "t_layer" (nth lay-idx laynmlst))
  124. ;      (set_tile "t_layer" (cdr (assoc '8 elist)))
  125. ;    )
  126.     (cond 
  127.       ((= lt-idx nil)
  128.         (set_tile "t_ltype" "varφa")
  129.       )
  130.       ((= lt-idx 0) ; set tile "By layer & layer linetype"
  131.         (set_tile "t_ltype" (bylayer_lt))
  132.       )
  133.       (T 
  134.         (set_tile "t_ltype" (nth lt-idx ltnmlst))
  135.       )
  136.     )
  137.     (if (or (= ethickness nil)
  138.             (= ethickness ;|MSG0|;"VARIES"))
  139.       (set_tile "eb_thickness" "varφa")
  140.       (set_tile "eb_thickness" (ai_rtos ethickness))
  141.     )
  142.     (if (or (= eltscale nil)
  143.             (= eltscale ;|MSG0|;"VARIES"))
  144.       (set_tile "eb_ltscale" "varφa")
  145.       (set_tile "eb_ltscale" (ai_rtos eltscale))
  146.     )
  147.     ;; Disable tiles if need be...
  148.     (setq a 0)
  149.     (while ( < a  (sslength ss))
  150.       (setq which_tiles
  151.             (ai_common_state (cdr (assoc '0 (entget (ssname ss a))))))
  152.  
  153.       ;; If all fields are enabled, don't bother checking anymore.
  154.       (if (/= which_tiles (logior 1 2 4 8 16))
  155.         (setq a (1+ a))
  156.         (setq a (sslength ss))
  157.       )
  158.     )
  159.     ;; Layer Button and Text Field
  160.     (if (/= 1 (logand 1 which_tiles))
  161.       (progn
  162.         (mode_tile "t_layer" 1)
  163.         (mode_tile "b_name" 1)
  164.       )
  165.     )
  166.     ;; Color Button and Text Field
  167.     (if (/= 2 (logand 2 which_tiles))
  168.       (progn
  169.         (mode_tile "t_color" 1)
  170.         (mode_tile "b_color" 1)
  171.         (mode_tile "show_image" 1)
  172.       )
  173.     )
  174.     ;; Linetype Button and Text Field
  175.     (if (/= 4 (logand 4 which_tiles))
  176.       (progn
  177.         (mode_tile "t_ltype" 1)
  178.         (mode_tile "b_line" 1)
  179.       )
  180.     )
  181.     ;; Linetype Scale Edit Field
  182.     (if (/= 8 (logand 8 which_tiles))
  183.       (progn
  184.         (mode_tile "eb_ltscale" 1)
  185.       )
  186.     )
  187.     ;; Thickness Edit Field.
  188.     (if (/= 16 (logand 16 which_tiles))
  189.       (progn
  190.         (mode_tile "eb_thickness" 1)
  191.       )
  192.     )
  193.  
  194.     ;; Define action for tiles
  195.     (action_tile "b_color" "(setq ecolor (getcolor))")
  196.     (action_tile "show_image" "(setq ecolor (getcolor))")
  197.     (action_tile "b_name" "(setq elayer (getlayer))")
  198.     (action_tile "b_line" "(setq eltype (getltype))")
  199.     (action_tile "eb_ltscale"  "(getscale $value)")
  200.     (action_tile "eb_thickness"  "(getthickness $value)")
  201.     (action_tile "help" "(help \"\" \"ddchprop\")")
  202.     (action_tile "accept" "(test-main-ok)")
  203.     (if (= (start_dialog) 1)
  204.       (progn
  205.         (setq cmdact (getvar "cmdactive"))
  206.         (command "_.chprop" ss "")
  207.         (if (/= cmdact (getvar "cmdactive"))  ; Is CHPROP actually running?
  208.           (progn
  209.             (if ecolor
  210.               (progn
  211.                 (if (= 0 ecolor)   (setq ecolor ;|MSG0|;"BYBLOCK"))
  212.                 (if (= 256 ecolor) (setq ecolor ;|MSG0|;"BYLAYER"))
  213.                 (command "_c" ecolor)
  214.               )
  215.             )
  216.             (if (and (/= eltype ;|MSG0|;"Varies") lt-idx)
  217.               (command "_lt" eltype)
  218.             )
  219.             (if (and (/= elayer ;|MSG0|;"Varies") lay-idx)
  220.               (command "_la" elayer)
  221.             )
  222.             (if (and (/= ethickness ;|MSG0|;"Varies") ethickness)
  223.               (command "_t" ethickness)
  224.             )
  225.             (if (and (/= eltscale ;|MSG0|;"Varies") eltscale)
  226.               (command "_lts" eltscale)
  227.             )
  228.             (command "")
  229.           )
  230.           (princ "\nPropiedades no modificadas")  ; CHPROP didn't like our SS set
  231.         )
  232.       )
  233.       ;; Fred GERBER - 25-AUG-94
  234.       ;; Don't print the "Properties unchanged" message when the user cancels
  235.       ;; the dialog because he knows that already (otherwise he would have
  236.       ;; hit the "OK" button). Display the message only if CHPROP fails for
  237.       ;; some reason, because it is not the expected behavior of the command.
  238.       ;;
  239.       ;; (princ ;|DDCHPROP_LSP_8|;"\nProperties unchanged")
  240.     )
  241.     (princ)
  242.   )
  243.   ;;
  244.   ;; Function to set the Color text tile and swab to the current color value.
  245.   ;;
  246.   (defun set_col_tile()
  247.     (cond 
  248.       ((= ecolor nil)
  249.         (set_tile "t_color" "varφa")
  250.         (col_tile "show_image" 0 nil)
  251.       )
  252.       ((= ecolor 0)
  253.         (set_tile "t_color" "PORBLOQUE")
  254.         (col_tile "show_image" 7 nil)    ; show BYBLOCK as white
  255.       )
  256.       ((= ecolor 1)
  257.         (set_tile "t_color" "1 rojo")
  258.         (col_tile "show_image" 1 nil)
  259.       )
  260.       ((= ecolor 2)
  261.         (set_tile "t_color" "2 amarillo")
  262.         (col_tile "show_image" 2 nil)
  263.       )
  264.       ((= ecolor 3)
  265.         (set_tile "t_color" "3 verde")
  266.         (col_tile "show_image" 3 nil)
  267.       )
  268.       ((= ecolor 4)
  269.         (set_tile "t_color" "4 ciano")
  270.         (col_tile "show_image" 4 nil)
  271.       )
  272.       ((= ecolor 5)
  273.         (set_tile "t_color" "5 azul")
  274.         (col_tile "show_image" 5 nil)
  275.       )
  276.       ((= ecolor 6)
  277.         (set_tile "t_color" "6 magenta")
  278.         (col_tile "show_image" 6 nil)
  279.       )
  280.       ((= ecolor 7)
  281.         (set_tile "t_color" "7 blanco")
  282.         (col_tile "show_image" 7 nil)
  283.       )
  284.       ;; If the color is "BYLAYER", then set the tile to
  285.       ;; show it's set By layer, but also indicate the
  286.       ;; color of the layer - i.e. By layer (red)
  287.       ((= ecolor 256)
  288.         (set_tile "t_color" (bylayer_col))
  289.         (col_tile "show_image" cn nil)
  290.       )
  291.       (T 
  292.         (set_tile "t_color" (itoa ecolor))
  293.         (col_tile "show_image" ecolor nil)
  294.       )
  295.     )
  296.   )
  297.   ;;
  298.   ;;  Function to put up the standard color dialogue.
  299.   ;;
  300.   (defun getcolor(/ col_def lay_clr temp_color)
  301.     ;; col_def is the default color used when rq_color is called.  If ecolor 
  302.     ;; is nil (varies) then set it to 1, else use the value of ecolor.
  303.     (if ecolor
  304.       (setq col_def ecolor)
  305.       (setq col_def 1)
  306.     )
  307.        
  308.     ;; If we're working with a single layer, get its color
  309.     ;; for use in the color swatch if the user selects color BYLAYER.
  310.     (if (/= elayer ;|MSG0|;"Varies")
  311.       (setq lay_clr (cdr (assoc 62 (tblsearch "layer" elayer))))
  312.       (setq lay_clr 0)
  313.     )
  314.     (if (numberp (setq temp_color (acad_colordlg col_def T lay_clr)))
  315.       (progn
  316.         (setq ecolor temp_color)
  317.         (set_col_tile)
  318.         ecolor
  319.       )
  320.       ecolor
  321.     )  
  322.   )
  323.   ;;
  324.   ;; This function pops a dialogue box consisting of a list box, image tile, 
  325.   ;; and edit box to allow the user to select or type a linetype.  It returns 
  326.   ;; the linetype selected.
  327.   ;;
  328.   (defun getltype (/ old-idx ltname)
  329.     ;; Initialize a dialogue from dialogue file
  330.     (if (not (new_dialog "setltype" dcl_id)) (exit))
  331.     (start_list "list_lt")
  332.     (mapcar 'add_list ltnmlst)         ; initialize list box
  333.     (end_list)
  334.     (setq old-idx lt-idx)
  335.     ;; Show initial ltype in image tile, list box, and edit box
  336.     (if (/= lt-idx nil)
  337.       (ltlist_act (itoa lt-idx))
  338.       (progn
  339.         (set_tile "edit_lt" "varφa")
  340.         (col_tile "show_image" 0 nil)
  341.       )
  342.     )
  343.     (action_tile "list_lt" "(ltlist_act $value)")
  344.     (action_tile "edit_lt" "(ltedit_act)")
  345.     (action_tile "accept" "(test-ok)")
  346.     (action_tile "cancel" "(reset-lt)")
  347.     (if (= (start_dialog) 1)           ; User pressed OK
  348.       (cond 
  349.         ((= lt-idx nil)
  350.           (set_tile "t_ltype" "varφa")
  351.           ;|MSG0|;"Varies"
  352.         )
  353.         ((= lt-idx 0)
  354.           (set_tile "t_ltype" (bylayer_lt))
  355.           ;|MSG0|;"BYLAYER"
  356.         )
  357.         ((= lt-idx 1)
  358.           (set_tile "t_ltype" "PORBLOQUE")
  359.           ;|MSG0|;"BYBLOCK"
  360.         )
  361.         (T  
  362.           (set_tile "t_ltype" ltname) 
  363.           ltname
  364.         )
  365.       )
  366.       eltype
  367.     )
  368.   )
  369.   ;;
  370.   ;; Edit box entries end up here
  371.   ;;
  372.   (defun ltedit_act ()
  373.     ;; If linetype name,is valid, then clear error string, 
  374.     ;; call ltlist_act function, and change focus to list box.
  375.     ;; Else print error message.
  376.     (setq ltvalue (xstrcase (get_tile "edit_lt")))
  377.     (if (or (= ltvalue ;|MSG0|;"BYLAYER") 
  378.             (= ltvalue "PORCAPA"))
  379.       (setq ltvalue "PORCAPA")
  380.     )
  381.     (if (or (= ltvalue ;|MSG0|;"BYBLOCK")
  382.             (= ltvalue "PORBLOQUE"))
  383.       (setq ltvalue "PORBLOQUE")
  384.     )
  385.     (if (setq lt-idx (getindex ltvalue ltnmlst))
  386.       (progn
  387.         (set_tile "error" "")
  388.         (ltlist_act (itoa lt-idx))
  389.         (mode_tile "list_lt" 2)
  390.       )
  391.       (progn
  392.         (if (/= ltvalue ;|MSG0|;"VARIES")
  393.           (set_tile "error" "Tipo de lφnea no vßlido.")
  394.         )
  395.         (setq lt-idx old-idx)
  396.       ) 
  397.     )
  398.   )
  399.   ;;
  400.   ;; List selections end up here
  401.   ;;
  402.   (defun ltlist_act (index / dashdata)
  403.     ;; Update the list box, edit box, and color tile
  404.     (set_tile "error" "")
  405.     (setq lt-idx (atoi index))
  406.     (setq ltname (nth lt-idx ltnmlst))
  407.     (setq dashdata (nth lt-idx mdashlist))
  408.     (col_tile "show_image" 0 dashdata)
  409.     (set_tile "list_lt" (itoa lt-idx))
  410.     (set_tile "edit_lt" ltname)
  411.   )
  412.   ;;
  413.   ;; Reset to original linetype when cancel it selected
  414.   ;;
  415.   (defun reset-lt ()
  416.     (setq lt-idx old-idx)
  417.     (done_dialog 0)
  418.   )
  419.   ;;
  420.   ;; This function pops a dialogue box consisting of a list box and edit box to 
  421.   ;; allow the user to select or type a layer name.  It returns the layer name 
  422.   ;; selected.  It also the status (On, Off, Frozen, etc.) of all layer in the 
  423.   ;; drawing.
  424.   ;;
  425.   (defun getlayer (/ old-idx layname on off frozth linetype colname)
  426.     ;; Create layer list the first time the layer
  427.     ;; dialogue is called.
  428.     (if (not lay-idx) 
  429.       (progn 
  430.         (makelaylists)                     ; layer list - laynmlst
  431.         (setq lay-idx (getindex elayer laynmlst))
  432.       )
  433.     )
  434.  
  435.     ;; Load a dialogue from dialogue file
  436.     (if (not (new_dialog "setlayer" dcl_id)) (exit))
  437.     (start_list "list_lay")
  438.     (mapcar 'add_list longlist)        ; initialize list box
  439.     (end_list)
  440.     ;; Display current layer, show initial layer name in edit 
  441.     ;; box, and highlight list box.
  442.     (setq old-idx lay-idx)
  443.     (if (/= lay-idx nil) (laylist_act (itoa lay-idx)))
  444.     (set_tile "cur_layer" (getvar "clayer"))
  445.     (action_tile "list_lay" "(laylist_act $value)")
  446.     (action_tile "edit_lay" "(layedit_act)")
  447.     (action_tile "accept" "(test-ok)")
  448.     (action_tile "cancel" "(reset-lay)")
  449.     (if (= (start_dialog) 1)           ; User pressed OK
  450.       (progn
  451.         (if (= lay-idx nil) 
  452.             (progn (setq layname ;|MSG0|;"VARIES")
  453.                    (set_tile "t_layer" "varφa"))
  454.             (set_tile "t_layer" layname)
  455.         )
  456.         ; If layer or ltype equals bylayer reset their tiles
  457.         (if (= lt-idx 0)
  458.           (set_tile "t_ltype" (bylayer_lt))
  459.         )
  460.         (if (= ecolor 256)
  461.           (progn
  462.             (set_tile "t_color" (bylayer_col))
  463.             (col_tile "show_image" cn nil)
  464.           )
  465.         )
  466.         layname
  467.       )
  468.       elayer
  469.     )
  470.   )
  471.   ;;
  472.   ;; Edit box selections end up here
  473.   ;;
  474.   (defun layedit_act()
  475.     ;; Convert layer entry to upper case.  If layer name is
  476.     ;; valid, clear error string, call (laylist_act) function,
  477.     ;; and change focus to list box.  Else print error message.
  478.     (setq layvalue (xstrcase (get_tile "edit_lay")))
  479.     (if (setq lay-idx (getindex layvalue laynmlst))
  480.       (progn
  481.         (set_tile "error" "")
  482.         (laylist_act (itoa lay-idx))
  483.       )
  484.       (progn
  485.         (set_tile "error" "Nombre de capa no vßlido.")
  486.         (setq lay-idx old-idx)
  487.       )
  488.     )
  489.   )
  490.   ;;
  491.   ;; List entry selections end up here
  492.   ;;
  493.   (defun laylist_act (index / layinfo color dashdata)
  494.     ;; Update the list box, edit box, and color tile
  495.     (set_tile "error" "")
  496.     (setq lay-idx (atoi index))
  497.     (setq layname (nth lay-idx laynmlst))
  498.     (setq layinfo (tblsearch "layer" layname))
  499.     (setq color (cdr (assoc 62 layinfo)))
  500.     (setq color (abs color))
  501.     (setq colname (colorname color))
  502.     (set_tile "list_lay" (itoa lay-idx))
  503.     (set_tile "edit_lay" layname)
  504.     (mode_tile "list_lay" 2)
  505.   )
  506.   ;;
  507.   ;; Reset to original layer when cancel is selected
  508.   ;;
  509.   (defun reset-lay ()
  510.     (setq lay-idx old-idx)
  511.     (done_dialog 0)
  512.   )
  513.  
  514.   ;; Checks validity of linetype scale from edit box.  It checks to
  515.   ;; see if the value equals "Varies".
  516.  
  517.   (defun getscale (value / rval)
  518.     (setq value (strcase value)
  519.           rval (distof value))
  520.     (if (or (= value ;|MSG0|;"VARIES")
  521.             (> rval 0.0))
  522.         (progn
  523.           (set_tile "error" "")
  524.           (if (= value ;|MSG0|;"VARIES")
  525.               (progn
  526.                 (set_tile "eb_ltscale" "varφa")
  527.                 (setq eltscale nil))
  528.             (progn
  529.               (setq eltscale (distof value))
  530.               (set_tile "eb_ltscale" (ai_rtos eltscale))
  531.               eltscale)))
  532.       (progn
  533.         (set_tile "error" "Escala Tlφnea no vßlido.")
  534.         nil)))
  535.   ;;
  536.   ;; Checks validity of thickness from edit box. Since (atof) returns 0 when a 
  537.   ;; string can't be converted to a real, this routine checks if the first 
  538.   ;; character is "0".  It also checks to see if the value equals "Varies".
  539.   ;;
  540.   (defun getthickness (value)
  541.     (setq value (strcase value))
  542.     (if (or (= value ;|MSG0|;"VARIES")
  543.             (distof value))
  544.       (progn
  545.         (set_tile "error" "")
  546.         (if (= value ;|MSG0|;"VARIES")
  547.           (progn
  548.             (set_tile "eb_thickness" "varφa")
  549.             (setq ethickness nil))
  550.           (progn
  551.             (setq ethickness (distof value))
  552.             (set_tile "eb_thickness" (ai_rtos ethickness))
  553.             ethickness)))
  554.       (progn
  555.         (set_tile "error" "Grosor no vßlido.")
  556.         nil)))
  557.   ;;
  558.   ;; This function make a list called laynmlst which consists of all the layer 
  559.   ;; names in the drawing.  It also creates a list called longlist which 
  560.   ;; consists of strings which contain the layer name, color, linetype, etc.  
  561.   ;; Longlist is later mapped into the layer listbox.  Both are ordered the 
  562.   ;; same.
  563.   ;;
  564.   (defun makelaylists (/ layname onoff frozth color linetype vpf vpn ss cvpname 
  565.                          xdlist vpldata sortlist name templist bit-70
  566.                          layer_number
  567.                       )
  568.     (if (= (setq tilemode (getvar "tilemode")) 0)
  569.       (progn
  570.         (setq ss (ssget "_x" (list (cons 0 "VIEWPORT")
  571.                                   (cons 69 (getvar "CVPORT"))
  572.                             )
  573.                  )
  574.         )     
  575.         (setq cvpname (ssname ss 0))
  576.         (setq xdlist (assoc -3 (entget cvpname '("acad"))))
  577.         (setq vpldata (cdadr xdlist))
  578.       )
  579.     )
  580.     (setq sortlist nil)
  581.     (setq templist (tblnext "LAYER" T))
  582.     (setq layer_number 1)
  583.     (while templist
  584.       (setq name (cdr (assoc 2 templist)))
  585.       (setq sortlist (cons name sortlist))
  586.       (setq templist (tblnext "LAYER"))
  587.       ;; Not dead message...
  588.       (if (= (/ layer_number 50.0) (fix (/ layer_number 50.0)))
  589.         (set_tile "error" (strcat "Reuniendo..." (itoa layer_number)))
  590.       )
  591.       (setq layer_number (1+ layer_number))
  592.     ) 
  593.     (set_tile "error" "")
  594.     (if (>= (getvar "maxsort") (length sortlist))
  595.       (progn
  596.         (if (> layer_number 50) 
  597.           (set_tile "error" "Ordenando...")
  598.         )
  599.         (setq sortlist (acad_strlsort sortlist))
  600.       )
  601.       (setq sortlist (reverse sortlist))
  602.     )
  603.     (set_tile "error" "")
  604.     (setq laynmlst sortlist)
  605.     (setq longlist nil)
  606.     (setq layname (car sortlist))
  607.     (setq layer_number 1)
  608.     (while layname
  609.       (if (= (/ layer_number 50.0) (fix (/ layer_number 50.0)))
  610.         (set_tile "error" (strcat "Analizando..." (itoa layer_number)))
  611.       )
  612.       (setq layer_number (1+ layer_number))
  613.       (setq laylist (tblsearch "LAYER" layname))
  614.       (setq color (cdr (assoc 62 laylist)))
  615.       (if (minusp color)
  616.         (setq onoff ".")
  617.         (setq onoff "Act")
  618.       )
  619.       (setq color (abs color))
  620.       (setq colname (colorname color))
  621.       (setq bit-70 (cdr (assoc 70 laylist)))
  622.       (if (= (logand bit-70 1) 1)
  623.         (setq frozth "I" fchk laylist)
  624.         (setq frozth ".")
  625.       )
  626.       (if (= (logand bit-70 2) 2)
  627.         (setq vpn "N")
  628.         (setq vpn ".")
  629.       )
  630.       (if (= (logand bit-70 4) 4)
  631.         (setq lock "B")
  632.         (setq lock ".")
  633.       )
  634.       (setq linetype (cdr (assoc 6 laylist)))
  635.       (setq layname (substr layname 1 31))
  636.       (if (= tilemode 0)
  637.         (progn
  638.           (if (member (cons 1003 layname) vpldata)
  639.             (setq vpf "A")
  640.             (setq vpf ".")
  641.           )
  642.         )
  643.         (setq vpf ".")
  644.       )
  645.       (setq ltabstr (strcat layname "\t"
  646.                               onoff "\t"
  647.                              frozth "\t"
  648.                                lock "\t"
  649.                                 vpf "\t"
  650.                                 vpn "\t"
  651.                             colname "\t"
  652.                            linetype
  653.                     )
  654.       )
  655.       (setq longlist (append longlist (list ltabstr)))
  656.       (setq sortlist (cdr sortlist))
  657.       (setq layname (car sortlist))
  658.     )
  659.     (set_tile "error" "")
  660.   )
  661.   ;;
  662.   ;; This function makes 2 lists - ltnmlst & mdashlist.  Ltnmlst is a list of 
  663.   ;; linetype names read from the symbol table.  Mdashlist is list consisting 
  664.   ;; of lists which define the linetype pattern - numbers that indicate dots, 
  665.   ;; dashes, and spaces taken from group code 49.  The list corresponds to the 
  666.   ;; order of names in ltnmlst.
  667.   ;;
  668.   (defun makeltlists (/ ltlist ltname)
  669.     (setq mdashlist nil)
  670.     (setq ltlist (tblnext "LTYPE" T))
  671.     (setq ltname (cdr (assoc 2 ltlist)))
  672.     (setq ltnmlst (list ltname))
  673.     (while (setq ltlist (tblnext "LTYPE"))
  674.       (setq ltname (cdr (assoc 2 ltlist)))
  675.       (setq ltnmlst (append ltnmlst (list ltname)))
  676.     )
  677.     (setq ltnmlst (acad_strlsort ltnmlst))
  678.     (foreach ltname ltnmlst
  679.       (setq ltlist (tblsearch "LTYPE" ltname))
  680.       (if (= ltname "CONTINUOUS")
  681.         (setq mdashlist (append mdashlist (list "CONT")))
  682.         (setq mdashlist 
  683.             (append mdashlist (list (add-mdash ltlist)))
  684.         )
  685.       )
  686.     )
  687.     (setq ltnmlst (cons "PORBLOQUE" ltnmlst))
  688.     (setq mdashlist  (cons nil mdashlist))
  689.     (setq ltnmlst (cons "PORCAPA" ltnmlst))
  690.     (setq mdashlist  (cons nil mdashlist))
  691.   )
  692.   ;;
  693.   ;; Get all the group code 49 values for a linetype and put them in a list 
  694.   ;; (pen-up, pen-down info)
  695.   ;;
  696.   (defun add-mdash (ltlist1 / dashlist assoclist dashsize)
  697.     (setq dashlist nil)
  698.     (while (setq assoclist (car ltlist1))
  699.       (if (= (car assoclist) 49)
  700.         (progn
  701.           (setq dashsize (cdr assoclist))
  702.           (setq dashlist (cons dashsize dashlist))
  703.         )
  704.       )
  705.       (setq ltlist1 (cdr ltlist1))
  706.     )
  707.     (setq dashlist (reverse dashlist))
  708.   )
  709.   ;;
  710.   ;; Color a tile, draw linetype, and draw a border around it
  711.   ;;
  712.   (defun col_tile (tile color patlist / x y)
  713.     (setq x (dimx_tile tile))
  714.     (setq y (dimy_tile tile))
  715.     (start_image tile)
  716.     (fill_image 0 0 x y color)
  717.     (if (= color 7)
  718.       (progn
  719.         (if patlist (drawpattern x (/ y 2) patlist 0))
  720.         (tile_rect 0 0 x y 0)
  721.       )
  722.       (progn
  723.         (if patlist (drawpattern x (/ y 2) patlist 7))
  724.         (tile_rect 0 0 x y 7)
  725.       )
  726.     )
  727.     (end_image)
  728.   )
  729.   ;;
  730.   ;; Draw a border around a tile
  731.   ;;
  732.   (defun tile_rect (x1 y1 x2 y2 color)
  733.     (setq x2 (- x2 1))
  734.     (setq y2 (- y2 1))
  735.     (vector_image x1 y1 x2 y1 color)
  736.     (vector_image x2 y1 x2 y2 color)
  737.     (vector_image x2 y2 x1 y2 color)
  738.     (vector_image x1 y2 x1 y1 color)
  739.   )
  740.   ;;
  741.   ;; Draw the linetype pattern in a tile.  Boxlength is the length of the image 
  742.   ;; tile, y2 is the midpoint of the height of the image tile, pattern is a 
  743.   ;; list of numbers that define the linetype, and color is the color of the 
  744.   ;; tile.
  745.   ;;
  746.   (defun drawpattern (boxlength y2 pattern color / x1 x2
  747.                       patlist dash)
  748.     (setq x1 0 x2 0)
  749.     (setq patlist pattern)
  750.     (setq fx 30)
  751.     (if (= patlist "CONT")
  752.       (progn 
  753.         (setq dash boxlength)
  754.         (vi)
  755.         (setq x1 boxlength)
  756.       )
  757.       (foreach dash patlist
  758.         (if (> (abs dash) 2.5)
  759.           (setq fx 2)
  760.         )
  761.       )
  762.     )
  763.     (while (< x1 boxlength)
  764.       (if (setq dash (car patlist))
  765.         (progn
  766.           (setq dash (fix (* fx dash)))
  767.           (cond 
  768.             ((= dash 0) 
  769.               (setq dash 1) 
  770.               (vi)
  771.             )
  772.             ((> dash 0) 
  773.               (vi)
  774.             )
  775.             (T 
  776.               (if (< (abs dash) 2) (setq dash 2))
  777.               (setq x2 (+ x2 (abs dash)))
  778.             )
  779.           )
  780.           (setq patlist (cdr patlist))
  781.           (setq x1 x2)
  782.         )
  783.         (setq patlist pattern)
  784.       )
  785.     )
  786.   )
  787.   ;;
  788.   ;; Draw a dash or dot in image tile
  789.   ;;
  790.   (defun vi ()
  791.     (setq x2 (+ x2 dash))
  792.     (vector_image x1 y2 x2 y2 color)
  793.   )
  794.  
  795.   ;; This function takes a selection and returns a list of the color,
  796.   ;; linetype, layer, linetype scale, and thickness properties that
  797.   ;; are common to every entities in the selection set - (color
  798.   ;; linetype layer thickness).  If all entities do not share the same
  799.   ;; property value it returns "Varies" in place of the property
  800.   ;; value.  i.e.  ("BYLAYER" "DASHED" "Varies" 0)
  801.  
  802.   (defun getprops (selset / sslen elist color ltype layer ltscale thickness
  803.                           go ctr)
  804.     (setq sslen (sslength selset)
  805.           elist (entget (ssname selset 0))
  806.           color (cdr (assoc 62 elist))
  807.           ltype (cdr (assoc 6 elist))
  808.           layer (cdr (assoc 8 elist))
  809.           thickness (cdr (assoc 39 elist))
  810.           ltscale (cdr (assoc 48 elist)))
  811.  
  812.     (if (not color)
  813.         (setq color 256))
  814.     (if (not ltype)
  815.         (setq ltype "BYLAYER"))
  816.     (if (not thickness)
  817.         (setq thickness 0))
  818.     (if (not ltscale)
  819.         (setq ltscale 1))
  820.     (setq go T chk-col T chk-lt T chk-lay T chk-lts T chk-th T ctr 1)
  821.  
  822.     ;; Page through the selection set.  When a property
  823.     ;; does not match, stop checking for that property.
  824.     ;; If all properties vary, stop paging.
  825.  
  826.     (while (and (> sslen ctr) go)
  827.       (setq elist (entget (setq en (ssname selset ctr))))
  828.       (if chk-col (match-col))
  829.       (if chk-lt (match-lt))
  830.       (if chk-lay (match-lay))
  831.       (if chk-lts (match-lts))
  832.       (if chk-th (match-th))
  833.       (setq ctr (1+ ctr))
  834.       (if (and (not chk-col)
  835.                (not chk-lt)
  836.                (not chk-lay)
  837.                (not chk-lts)
  838.                (not chk-th))
  839.         (setq go nil)
  840.       )
  841.     )
  842.     (list color ltype layer thickness ltscale)
  843.   )
  844.  
  845.   (defun match-col (/ ncolor)
  846.     (setq ncolor (cdr (assoc 62 elist)))
  847.     (if (not ncolor) (setq ncolor 256))
  848.     (if (/= color ncolor)
  849.       (progn
  850.         (setq chk-col nil)
  851.         (setq color nil)
  852.       )
  853.     )
  854.   )
  855.  
  856.   (defun match-lt (/ nltype)
  857.     (setq nltype (cdr (assoc 6 elist)))
  858.     (if (not nltype) (setq nltype "BYLAYER"))
  859.     (if (/= ltype nltype)
  860.       (progn
  861.         (setq chk-lt nil)
  862.         (setq ltype ;|MSG0|;"Varies")
  863.       )
  864.     )
  865.   )
  866.  
  867.   (defun match-lay (/ nlayer)
  868.     (setq nlayer (cdr (assoc 8 elist)))
  869.     (if (/= layer nlayer)
  870.       (progn
  871.         (setq chk-lay nil)
  872.         (setq layer ;|MSG0|;"Varies")
  873.       )
  874.     )
  875.   )
  876.  
  877.   (defun match-th (/ nthickness)
  878.     (setq nthickness (cdr (assoc 39 elist)))
  879.     (if (not nthickness) (setq nthickness 0))
  880.     (if (/= thickness nthickness)
  881.       (progn
  882.         (setq chk-th nil)
  883.         (setq thickness ;|MSG0|;"Varies")
  884.       )
  885.     )
  886.   )
  887.  
  888.   (defun match-lts (/ nltscale)
  889.     (setq nltscale (cdr (assoc 48 elist)))
  890.     (if (not nltscale) (setq nltscale 1))
  891.     (if (/= ltscale nltscale)
  892.       (progn
  893.         (setq chk-th nil)
  894.         (setq ltscale ;|MSG0|;"Varies")
  895.       )
  896.     )
  897.   )
  898.  
  899.   ;;
  900.   ;; If an item is a member of the list, then return its index number, else 
  901.   ;; return nil.
  902.   ;;
  903.   (defun getindex (item itemlist / m n)
  904.     (setq n (length itemlist))
  905.     (if (> (setq m (length (member item itemlist))) 0)
  906.         (- n m)
  907.         nil
  908.     )
  909.   )
  910.   ;;
  911.   ;; This function is called if the linetype is set "BYLAYER". It finds the 
  912.   ;; ltype of the layer so it can be displayed beside the linetype button.
  913.   ;;
  914.   (defun bylayer_lt (/ layname layinfo ltype)
  915.     (if lay-idx
  916.       (progn
  917.         (setq layname (nth lay-idx laynmlst))
  918.         (setq layinfo (tblsearch "layer" layname))
  919.         (setq ltype (cdr (assoc 6 layinfo)))
  920.         (strcat "PORCAPA" " (" ltype ")")
  921.       )
  922.       "PORCAPA"
  923.     )
  924.   )
  925.   ;;
  926.   ;; This function is called if the color is set "BYLAYER".  It finds the 
  927.   ;; color of the layer so it can be displayed  beside the color button.
  928.   ;;
  929.   (defun bylayer_col (/ layname layinfo color)
  930.     (if lay-idx
  931.       (progn
  932.         (setq layname (nth lay-idx laynmlst))
  933.         (setq layinfo (tblsearch "layer" layname))
  934.         (setq color (abs (cdr (assoc 62 layinfo))))
  935.         (setq cn color)
  936.         (strcat "PORCAPA" " (" (colorname color) ")")
  937.       )
  938.       (progn
  939.         (setq layname elayer)
  940.         (if (/= elayer "Varies")
  941.           (progn 
  942.             (setq layinfo (tblsearch "layer" elayer))
  943.             (setq color (abs (cdr (assoc 62 layinfo))))
  944.             (setq cn color)
  945.             (strcat "PORCAPA" " (" (colorname color) ")")
  946.           )
  947.           (progn
  948.             (setq cn 0) 
  949.             "BYLAYER"
  950.           )
  951.         )
  952.       )
  953.     )
  954.   )
  955.   ;;
  956.   ;; If there is no error message, then close the dialogue
  957.   ;;
  958.   ;; If there is an error message, then set focus to the tile
  959.   ;; that's associated with the error message.
  960.   ;;
  961.   (defun test-ok ( / errtile)
  962.     (setq errtile (get_tile "error"))
  963.     (cond
  964.       (  (= errtile "")
  965.          (done_dialog 1))
  966.       (  (= errtile "Grosor no vßlido.")
  967.          (mode_tile "eb_thickness" 2))
  968.     )
  969.   )
  970.   ;;
  971.   ;; OK in main dialogue.
  972.   ;;
  973.   (defun test-main-ok ()
  974.     (cond
  975.       ( (not (distof (get_tile "eb_thickness")))
  976.          (set_tile "error" "Invalid thickness.")
  977.          (mode_tile "eb_thickness" 2)
  978.       )
  979.       ( (not (distof (get_tile "eb_ltscale")))
  980.          (set_tile "error" "Invalid linetype scale.")
  981.          (mode_tile "eb_ltscale" 2)
  982.       )
  983.       ( T (done_dialog 1))
  984.     )
  985.   )
  986.  
  987.   ;;
  988.   ;; A color function used by getlayer.
  989.   ;;
  990.   (defun colorname (colnum)
  991.     (setq cn (abs colnum))
  992.     (cond ((= cn 1) "rojo")
  993.           ((= cn 2) "amarillo")
  994.           ((= cn 3) "verde")
  995.           ((= cn 4) "ciano")
  996.           ((= cn 5) "azul")
  997.           ((= cn 6) "magenta")
  998.           ((= cn 7) "blanco")
  999.           (T (itoa cn))
  1000.     )
  1001.   )
  1002.  
  1003. ;;; Construct layer and ltype lists and initialize all
  1004. ;;; program variables:
  1005.  
  1006. ;  (makelaylists)                     ; layer list - laynmlst
  1007.   (makeltlists)                      ; linetype lists - ltnmlst, mdashlist
  1008.   ;; Find the property values of the selection set.
  1009.   ;; (getprops ss) returns a list of properties from
  1010.   ;; a selection set - (color ltype layer thickness).
  1011.   (setq proplist (getprops ss)
  1012.         ecolor (car proplist)
  1013.         eltype (nth 1 proplist)
  1014.         elayer (nth 2 proplist)
  1015.         ethickness (nth 3 proplist)
  1016.         eltscale (nth 4 proplist))
  1017.  
  1018.   ;; Find index of linetype, and layer lists
  1019.   (cond
  1020.     ((= eltype "Varies") (setq lt-idx nil))
  1021.     ((= eltype "BYLAYER")
  1022.      (setq lt-idx (getindex "PORCAPA" ltnmlst)))
  1023.     ((= eltype "BYBLOCK")
  1024.      (setq lt-idx (getindex "PORBLOQUE" ltnmlst)))
  1025.     (T (setq lt-idx (getindex eltype ltnmlst)))
  1026.   )
  1027.   (if (= elayer "Varies")
  1028.       (setq lay-idx nil)
  1029.       (setq lay-idx (getindex elayer laynmlst))
  1030.   )
  1031.   (if (= ethickness "Varies")
  1032.       (setq ethickness nil)
  1033.   )
  1034.   (if (= eltscale "Varies")
  1035.       (setq eltscale nil)
  1036.   )
  1037.  
  1038. )   ; end (ddchprop_init)
  1039.  
  1040. ;;; (ddchprop_select)
  1041. ;;;
  1042. ;;; Aquires selection set for DDCHPROP, in one of three ways:
  1043. ;;;
  1044. ;;;   1 - Autoselected.
  1045. ;;;   2 - Prompted for.
  1046. ;;;   3 - Passed as an argument in a call to (ddchprop <ss> )
  1047. ;;;
  1048. ;;; The (ddchprop_select) function also sets the value of the
  1049. ;;; global symbol AI_SELTYPE to one of the above three values to
  1050. ;;; indicate the method thru which the entity was aquired.
  1051.  
  1052.  
  1053. (defun ddchprop_select ()
  1054.    (cond
  1055.       (  (and ss (eq (type ss) 'pickset))        ; selection set passed to
  1056.          (cond                                   ; (ddchprop) as argument
  1057.             (  (not (zerop (sslength ss)))       ;   If not empty, then
  1058.                (setq ai_seltype 3)               ;   then return pickset.
  1059.                (ai_return ss))))
  1060.  
  1061.       (  (ai_aselect))                          ; Use current selection
  1062.                                                 ; set or prompt for objects
  1063.  
  1064.       (t (princ "\nNo se ha seleccionado nada.")
  1065.          (ai_return nil))
  1066.    )
  1067. )
  1068.  
  1069. ;;; Define command function.
  1070.  
  1071. (defun C:DDCHPROP ()
  1072.    (ddchprop nil)
  1073.    (princ)
  1074. )
  1075.  
  1076.  
  1077. ;;; Main program function - callable as a subroutine.
  1078. ;;;
  1079. ;;; (ddchprop <pickset> )
  1080. ;;;
  1081. ;;; <pickset> is the selection set of objects to be changed.
  1082. ;;;
  1083. ;;; If <pickset> is nil, then the current selection set is
  1084. ;;; aquired, if one exists.  Otherwise, the user is prompted
  1085. ;;; to select the objects to be changed.
  1086. ;;;
  1087. ;;; Before (ddchprop) can be called as a subroutine, it must
  1088. ;;; be loaded first.  It is up to the calling application to
  1089. ;;; first determine this, and load it if necessary.
  1090.  
  1091. (defun ddchprop (ss  /
  1092.  
  1093.                   add-mdash      ecolor          ltedit_act      s
  1094.                   assoclist      elayer          ltidx           selset
  1095.                   bit-70         elist           ltlist          set_col_tile
  1096.                   boxlength      eltype          ltlist1
  1097.                   bylayer-lt     en              ltlist_act      sortlist
  1098.                   bylayer_col    ethickness      ltname
  1099.                   bylayer_lt     fchk            ltnmlst         sslen
  1100.                   call_chp       frozth          ltvalue         templist
  1101.                   chk-col        getcolor        ltype           temp_color
  1102.                   chk-lay        getindex        m               test-ok
  1103.                   chk-lt         getlayer        makelaylists    testidx
  1104.                   chk-th         getltype        makeltlists     testlay
  1105.                   cmd            getprops        match-col       th-value
  1106.                   cmdecho        getthickness    match-in        thickness
  1107.                   cn             globals         match-lay       tile
  1108.                   cnum                           match-lt        tilemode
  1109.                   col-idx        index           match-th        tile_rect
  1110.                   colname        item            match_col       vi
  1111.                   colnum         item1           mdashlist       vpf
  1112.                   color          item2           n               vpldata
  1113.                   colorname      itemlist        name            vpn
  1114.                   col_def        lay-idx         ncolor          x
  1115.                   col_tile       layedit_act     nlayer          x1
  1116.                                  layer           nltype          x2
  1117.                   cvpname        layinfo         nthickness      xdlist
  1118.                   dash           laylist         off             y
  1119.                   dashdata       laylist_act     old-idx         y1
  1120.                   dashlist       layname         olderr          y2
  1121.                   dashsize       laynmlst        on              undo_init
  1122.                   dcl_id         layvalue        onoff           fx
  1123.                   test-main-ok   linetype        patlist         which_tiles
  1124.                   ddchprop-err   list1           pattern         a
  1125.                   longlist       proplist
  1126.                   lt-idx         reset-lay
  1127.                   drawpattern    ltabstr         reset-lt
  1128.                   eltscale       match-lts
  1129.                 )
  1130.  
  1131.   (setq old_cmd (getvar "cmdecho")    ; save current setting of cmdecho
  1132.         old_error  *error*            ; save current error function
  1133.         *error* ai_error              ; new error function
  1134.   )
  1135.  
  1136.   (setvar "cmdecho" 0)
  1137.  
  1138.   (cond
  1139.      (  (not (ai_notrans)))                      ; Not transparent?
  1140.      (  (not (ai_acadapp)))                      ; ACADAPP.EXP xloaded?
  1141.      (  (not (setq dcl_id (ai_dcl "ddchprop")))) ; is .DCL file loaded?
  1142.      (  (not (setq ss (ddchprop_select))))       ; objects to modify?
  1143.  
  1144.      (t (ai_undo_push)
  1145.         (ddchprop_init)                          ; Everything's cool,
  1146.         (call_chp)                               ; so proceed!
  1147.         (ai_undo_pop)
  1148.      )
  1149.   )
  1150.   
  1151.   (setq *error* old_error) 
  1152.   (setvar "cmdecho" old_cmd)
  1153.   (princ)
  1154. )
  1155.  
  1156. ;;;----------------------------------------------------------------------------
  1157.  
  1158. (princ "   DDCHPROP cargada.")
  1159. (princ)
  1160.  
  1161.