home *** CD-ROM | disk | FTP | other *** search
/ Windows 95 v2.4 Fix / W95-v2.4fix.iso / ACADWIN / SUPPORT / XPLODE.LSP < prev    next >
Encoding:
Text File  |  1995-02-08  |  16.8 KB  |  552 lines

  1. ;;;--------------------------------------------------------------------------;
  2. ;;; XPLODE.LSP                                  
  3. ;;;    Copyright (C) 1990, 1992, 1994 by Autodesk, Inc.
  4. ;;;    
  5. ;;;    Permission to use, copy, modify, and distribute this software 
  6. ;;;    for any purpose and without fee is hereby granted, provided
  7. ;;;    that the above copyright notice appears in all copies and 
  8. ;;;    that both that copyright notice and the limited warranty and 
  9. ;;;    restricted rights notice below appear in all supporting 
  10. ;;;    documentation.
  11. ;;;    
  12. ;;;    AUTODESK PROVIDES THIS PROGRAM "AS IS" AND WITH ALL FAULTS.  
  13. ;;;    AUTODESK SPECIFICALLY DISCLAIMS ANY IMPLIED WARRANTY OF 
  14. ;;;    MERCHANTABILITY OR FITNESS FOR A PARTICULAR USE.  AUTODESK, INC. 
  15. ;;;    DOES NOT WARRANT THAT THE OPERATION OF THE PROGRAM WILL BE 
  16. ;;;    UNINTERRUPTED OR ERROR FREE.
  17. ;;;    
  18. ;;;    Use, duplication, or disclosure by the U.S. Government is subject to 
  19. ;;;    restrictions set forth in FAR 52.227-19 (Commercial Computer 
  20. ;;;    Software - Restricted Rights) and DFAR 252.227-7013(c)(1)(ii) 
  21. ;;;    (Rights in Technical Data and Computer Software), as applicable. 
  22. ;;; --------------------------------------------------------------------------;
  23. ;;; DESCRIPTION
  24. ;;;
  25. ;;;
  26. ;;;   This is a replacement for the EXPLODE command in AutoCAD.  It allows
  27. ;;;   you to control all of the properties of the component entities of a
  28. ;;;   block or set of blocks while exploding them.  There are several major
  29. ;;;   differences between XPlode and the EXPLODE command in AutoCAD.
  30. ;;;   
  31. ;;;   First, you can select as many entities as you wish; all dimensions,
  32. ;;;   polyline and polymeshes, and block insertions will be extracted from
  33. ;;;   your selection set, and you will be asked to XPlode them either
  34. ;;;   globally or individually.  If you chose to explode them globally, you
  35. ;;;   will see the following prompt for all of the candidate entities:
  36. ;;;   
  37. ;;;     All/Color/LAyer/LType/Inherit from parent block/<Explode>: 
  38. ;;;   
  39. ;;;   If, on the other hand, you elect to operate on each element of the
  40. ;;;   selection set individually, you will need to make a selection from this
  41. ;;;   prompt for each entity to be exploded.
  42. ;;;   
  43. ;;;   Second, the EXPLODE command in AutoCAD does not allow you to specify
  44. ;;;   any of the properties for the resulting entities generated from the
  45. ;;;   EXPLODE command.  Nor does it allow you to let the component entities
  46. ;;;   inherit the attributes of the parent block.
  47. ;;;   
  48. ;;;   Third, this routine allows blocks inserted with equal absolute scale
  49. ;;;   factors but differing signs to be exploded (i.e. -1,1,1).  This allows
  50. ;;;   mirrored blocks to be exploded.
  51. ;;;
  52. ;;;   ALL
  53. ;;;   
  54. ;;;   This option allows you to specify a color, linetype, and layer for the
  55. ;;;   new entities.
  56. ;;;   
  57. ;;;   COLOR
  58. ;;;   
  59. ;;;   This option prompts you for a new color for the component entities.
  60. ;;;   
  61. ;;;     New color for exploded entities.
  62. ;;;     Red/Yellow/Green/Cyan/Blue/Magenta/White/BYLayer/BYBlock/<cecolor>:
  63. ;;;   
  64. ;;;   You may enter any color number from 1 through 255, or one of the 
  65. ;;;   standard color names listed.  "Cecolor" is the current entity color
  66. ;;;   from the CECOLOR system variable.
  67. ;;;   
  68. ;;;   LAYER
  69. ;;;   
  70. ;;;   This option prompts you to enter the name of the layer on which you 
  71. ;;;   want the component entities to be placed.
  72. ;;;   
  73. ;;;     XPlode onto what layer?  <clayer>:
  74. ;;;   
  75. ;;;   The layer name entered is verified and if it does not exist you are
  76. ;;;   reprompted for a layer name.  Pressing RETURN causes the current 
  77. ;;;   layer to be used.
  78. ;;;   
  79. ;;;   LTYPE
  80. ;;;   
  81. ;;;   This option lists all of the loaded linetypes in the current drawing,
  82. ;;;   and prompts you to choose one of them.  You must type the entire 
  83. ;;;   linetype name (sorry), or you may press RETURN to use the current one.
  84. ;;;   
  85. ;;;     Choose from the following list of linetypes.
  86. ;;;     CONTinuous/...others.../<CONTINUOUS>:
  87. ;;;   
  88. ;;;   INHERIT
  89. ;;;   
  90. ;;;   Inherit from parent block means that the attributes of the block
  91. ;;;   being XPloded will be the attributes of component entities.  No other
  92. ;;;   choices are required.
  93. ;;;   
  94. ;;;   EXPLODE
  95. ;;;   
  96. ;;;   This option issues the current EXPLODE command for each of the entities
  97. ;;;   in the selection set.
  98. ;;;   
  99. ;;; --------------------------------------------------------------------------;
  100.  
  101. ;;; ------------------------ INTERNAL ERROR HANDLER --------------------------;
  102.  
  103. (defun xp_err (s)                     ; If an error (such as CTRL-C) occurs
  104.   ;; while this command is active...
  105.   (if (/= s "Funci≤n cancelada") 
  106.     (princ (strcat "\nError: " s))
  107.   ) 
  108.   (if xp_oce (setvar "cmdecho" xp_oce)) ; restore old cmdecho value
  109.   (setq *error* olderr)               ; restore old *error* handler
  110.   (princ)
  111.  
  112. ;;; ---------------------------- COMMON FUNCTION -----------------------------;
  113.  
  114. (defun xp_val (n e f) 
  115.   (if f ; if f then e is an entity list.
  116.     (cdr (assoc n e))
  117.     (cdr (assoc n (entget e)))
  118.   )
  119.  
  120. ;;; ------------------------- GET ENTITY TO EXPLODE --------------------------;
  121. ;;; ---------------------------- MAIN PROGRAM --------------------------------;
  122.  
  123. (defun explode ( / oce ohl e0 en e1 s0) 
  124.  
  125.   (setq xp_oer *error* 
  126.         *error* xp_err)
  127.   (setq xp_oce (getvar "cmdecho"))    ; save value of cmdecho
  128.   (setvar "cmdecho" 0)                ; turn cmdecho off
  129.   (graphscr)
  130.  
  131.   (princ "\nDesigne los objetos a los que aplicar XPLODE. ")
  132.   (setq ss (ssget))
  133.  
  134.   (if ss
  135.     (progn
  136.       ;; Sort out any entities not explodeable...
  137.       (setq ss (xp_sxe)) ; DLine_Sort_Xplodable_Entities
  138.     
  139.       ;; XPlode Individually or Globally?
  140.     
  141.       (if (> (sslength ss) 0)
  142.         (progn
  143.           (if (> (sslength ss) 1)
  144.             (progn
  145.               (initget "Individualmente Globalmente")
  146.               (setq ans (getkword "\n\nDescomponer Individualmente/<Globalmente>: "))
  147.             )
  148.             (setq ans "Globalmente")
  149.           )
  150.         
  151.         
  152.           (cond
  153.             ((= ans "Individualmente")
  154.               (setq sslen (sslength ss)
  155.                     j    0
  156.               )
  157.               (while (< j sslen)
  158.                 (setq temp  (ssname ss j)
  159.                       prmpt T
  160.                 )
  161.         
  162.                 (redraw temp 3)
  163.                 (setq typ (xp_gxt))
  164.                 (xp_xpe temp typ)
  165.                 (redraw temp 4)
  166.                 (setq j (1+ j))
  167.               )
  168.             )
  169.             (T
  170.               (setq sslen (sslength ss)
  171.                     j     0
  172.                     ans   "Globalmente"
  173.                     prmpt T
  174.               )
  175.               (setq typ (xp_gxt))
  176.               (while (< j sslen)
  177.                 (setq temp (ssname ss j))
  178.                 (xp_xpe temp typ)
  179.                 (setq j (1+ j))
  180.               )
  181.             )
  182.           )
  183.         )
  184.       )
  185.     )
  186.   )
  187.   
  188.   (if xp_oce (setvar "cmdecho" xp_oce)) ; restore old cmdecho value
  189.   (setq *error* xp_err)               ; restore old *error* handler
  190.   (prin1)
  191. ;;;
  192. ;;; Sort out all of the entities which can be exploded from the selection
  193. ;;; set.  Also ensure that block insertions have equal X, Y and Z scale factors.
  194. ;;;
  195. ;;; xp_sxe == DLine_Sort_Xplodable_Entities
  196. ;;;
  197. (defun xp_sxe (/ temp bad)
  198.  
  199.   (setq sslen (sslength ss)
  200.         j     0
  201.         ss1   (ssadd)
  202.   )
  203.   (while (< j sslen)
  204.     (setq temp (ssname ss j))
  205.     (setq j (1+ j))
  206.     (if (member (xp_val 0 temp nil) '("DIMENSION" "POLYLINE" "MLINE" 
  207.                                       "3DSOLID" "REGION" "BODY"))
  208.       (ssadd temp ss1)
  209.       (progn
  210.         ;; If it is an INSERT but not a MINSERT or XREF, add it.
  211.         (if (member (xp_val 0 temp nil) '("INSERT"))
  212.           (cond 
  213.             ( (= 4 (logand 4 (cdr (assoc 70 (tblsearch "block" (cdr (assoc 2 (entget temp))))))))
  214.             )
  215.             ( (< 1 (cdr (assoc 70 (entget temp)))) )
  216.             ( (< 1 (cdr (assoc 71 (entget temp)))) )
  217.             ( T (ssadd temp ss1))
  218.           )
  219.         )
  220.       )
  221.     )
  222.   )
  223.   (setq sslen (sslength ss)
  224.         bad (sslength ss1)
  225.   )
  226.   (princ "\n")
  227.   (princ sslen)
  228.   (princ " objeto(s) encontrado(s). ")
  229.   (if (> (- sslen bad) 0)
  230.     (progn
  231.       (princ (- sslen bad))
  232.       (princ " no vßlido(s). ")
  233.     )
  234.   )
  235.   ss1
  236. )
  237. ;;;
  238. ;;; Set the type of explode to do.
  239. ;;;
  240. ;;; xp_gxt == XPlode_Get_Xplode_Type
  241. ;;;
  242. (defun xp_gxt (/ temp)
  243.   
  244.   (initget "Todo cOlor Capa tLφnea Heredar Descomp")
  245.   (setq temp (getkword
  246.     "\n\nTodo/cOlor/Capa/tLφnea/Heredar de un bloque superior/<Descomp>: "))
  247.  
  248.   (if (or (= temp "") (null temp))
  249.     (setq temp "Descomp")
  250.   )
  251.   temp
  252. )
  253. ;;;
  254. ;;; Do the explosion of an entity.
  255. ;;;
  256. ;;; xp_xpe == XPlode_XPlode_Entity
  257. ;;;
  258. (defun xp_xpe (ent typ /  )
  259.   (cond 
  260.     ((= typ "Todo")
  261.       (if prmpt
  262.         (progn
  263.           (setq color (xp_scn))
  264.           (setq ltype (xp_slt))
  265.           (setq layer (xp_sla))
  266.           (setq prmpt nil)
  267.         )
  268.       )
  269.  
  270.       (xp_xfa)
  271.       (if (or (= ans "Individualmente") (= j (1- sslen)))
  272.         (progn
  273.           (if (and (> sslen 1) (= ans "Globalmente"))
  274.             (princ "\nObjetos ")
  275.             (princ "\nObjeto ")
  276.           )
  277.           (princ (strcat "descompuesto(s) del color " 
  278.                          (if (= (type color) 'INT) (itoa color) color) ", "
  279.                          "tφpo de lφnea " ltype ", "
  280.                          "y capa " layer "."))
  281.         )
  282.       )
  283.     )
  284.     ((= typ "cOlor")
  285.       (if prmpt
  286.         (progn
  287.           (setq color (xp_scn))
  288.           (setq ltype (getvar "celtype"))
  289.           (setq layer (getvar "clayer"))
  290.           (setq prmpt nil)
  291.         )
  292.       )
  293.  
  294.       (xp_xfa)
  295.       (if (or (= ans "Individualmente") (= j (1- sslen)))
  296.         (progn
  297.           (if (and (> sslen 1) (= ans "Globalmente"))
  298.             (princ "\nObjetos ")
  299.             (princ "\nObjeto ")
  300.           )
  301.           (princ (strcat "descompuesto(s) del color " 
  302.                          (if (= (type color) 'INT) (itoa color) color) ".")) 
  303.         )
  304.       )
  305.     )
  306.     ((= 
  307.     typ "Capa")
  308.       (if prmpt
  309.         (progn
  310.           (setq color (getvar "cecolor"))
  311.           (setq ltype (getvar "celtype"))
  312.           (setq layer (xp_sla))
  313.           (setq prmpt nil)
  314.         )
  315.       )
  316.  
  317.       (xp_xfa)
  318.       (if (or (= ans "Individualmente") (= j (1- sslen)))
  319.         (progn
  320.           (if (and (> sslen 1) (= ans "Globalmente"))
  321.             (princ "\nObjetos ")
  322.             (princ "\nObjeto ")
  323.           )
  324.           (princ (strcat "descompuesto(s) en la capa " layer ".")) 
  325.         )
  326.       )
  327.     )
  328.     ((= typ "tLφnea")
  329.       (if prmpt
  330.         (progn
  331.           (setq color (getvar "cecolor"))
  332.           (setq ltype (xp_slt))
  333.           (setq layer (getvar "clayer"))
  334.           (setq prmpt nil)
  335.         )
  336.       )
  337.  
  338.       (xp_xfa)
  339.       (if (or (= ans "Individualmente") (= j (1- sslen)))
  340.         (progn
  341.           (if (and (> sslen 1) (= ans "Globalmente"))
  342.             (princ "\nObjetos ")
  343.             (princ "\nObjeto ")
  344.           )
  345.           (princ (strcat "descompuesto(s) con tipo de lφnea " ltype ".")) 
  346.         )
  347.       )
  348.     )
  349.     ((= typ "Heredar")
  350.       (xp_iap ent)
  351.     )
  352.     (T
  353.       (command "_.EXPLODE" (xp_val -1 ent nil))  ; explode
  354.     )
  355.   )
  356. )
  357. ;;;
  358. ;;; Force the color, linetype and layer attributes after exploding.
  359. ;;;
  360. ;;; xp_xea == XPlode_Xplode_Force_All
  361. ;;;
  362. (defun xp_xfa ()
  363.  
  364.   (setq e0 (entlast))
  365.   (setq en (entnext e0))
  366.   (while (not (null en))              ; find the last entity              
  367.     (setq e0 en)
  368.     (setq en (entnext e0))
  369.   ) 
  370.  
  371.   (command "_.EXPLODE" (xp_val -1 ent nil))  ; explode
  372.  
  373.   (setq s0 (ssadd))
  374.   
  375.   (while (entnext e0) 
  376.     (ssadd (setq e0 (entnext e0))
  377.            s0
  378.     )
  379.   ) 
  380.  
  381.   (command "_.CHPROP" s0 ""             ; change entities to the proper layer
  382.            "_C"  color                 ; color, and linetype, regardless
  383.            "_LT" ltype                 ; of their extrusion direction
  384.            "_LA" layer
  385.            ""
  386.   ) 
  387. )
  388. ;;;
  389. ;;; Inherit attributes (if BYBLOCK) from parent.
  390. ;;;
  391. ;;; xp_iap == XPlode_Inherit_Attributes_from_Parent
  392. ;;;
  393. (defun xp_iap (t1 / t1cl t1lt t1ly s0ly s0lt s0cl t0e)
  394.   (setq yyy t1)
  395.   (setq t0 (entlast))
  396.   (setq tn (entnext t0))
  397.   (while (not (null tn))              ; find the last entity              
  398.     (setq t0 tn)
  399.     (setq tn (entnext t0))
  400.   ) 
  401.       
  402.   (setq t1cl (xp_val 62 t1 nil))      ; record the attributes of the block
  403.   (setq t1lt (xp_val 6  t1 nil))
  404.   (setq t1ly (xp_val 8  t1 nil))
  405.   (command "_.EXPLODE" (xp_val -1 ent nil))  ; explode
  406.   (setq s0ly (ssadd))                 ; create nil selection sets for layer
  407.   (setq s0lt (ssadd))                 ; linetype and color changes
  408.   (setq s0cl (ssadd))
  409.   (setq t0 (entnext t0))
  410.   (while t0                           ; can exploded entities
  411.     (setq t0e (entget t0))            ; and build selection sets
  412.     
  413.     (if (=  (xp_val 62 t0e T) "BYBLOCK") (ssadd t0 s0cl))
  414.     (if (=  (xp_val 6  t0e T) "BYBLOCK") (ssadd t0 s0lt))
  415.     (if (=  (xp_val 8  t0e T) "0")       (ssadd t0 s0ly))
  416.     (setq t0 (entnext t0))
  417.   )
  418.   (if (> (sslength s0cl) 0)           ; is selection set non-nil...
  419.       (command "_.CHPROP" s0cl ""       ; Change exploded entities with color
  420.                "_CO" t1cl "")          ; BYBLOCK to color of old block
  421.   )
  422.   (if (> (sslength s0lt) 0)
  423.       (command "_.CHPROP" s0lt ""       ; Change exploded entities with linetype
  424.                "_LT" t1lt "")          ; BYBLOCK to linetype of old block
  425.   )
  426.   (if (> (sslength s0ly) 0)
  427.       (command "_.CHPROP" s0ly ""       ; Change exploded entities with linetype
  428.                "_LA" t1ly "")          ; BYBLOCK to linetype of old block
  429.   )
  430.   (if (or (= ans "Individualmente") (= j (1- sslen)))
  431.     (progn
  432.       (if (and (> sslen 1) (= ans "Globalmente"))
  433.         (princ "\nObjetos ")
  434.         (princ "\nObjeto ")
  435.       )
  436.       (princ "descompuesto(s).") 
  437.     )
  438.   )
  439. )
  440.  
  441. ;;;
  442. ;;; Set the color for the exploded entities.
  443. ;;;
  444. ;;; xp_scn == XPlode_Set_Color_Number
  445. ;;;
  446. (defun xp_scn ()
  447.   (setq arg 257)
  448.   (while (> arg 256)
  449.     (initget 2 "Rojo Amarillo Verde cIano aZul Magenta bLanco porCapa porBloque")
  450.     (setq arg (getint (strcat
  451.       "\n\nNuevo color para los objetos descompuestos."
  452.       "\nRojo/Amarillo/Verde/cIano/aZul/Magenta/bLanco/porCapa/porBloque <"
  453.       (if (= (type (getvar "cecolor")) 'INT)
  454.         (itoa (getvar "cecolor")) 
  455.         (getvar "cecolor")
  456.       ) 
  457.       ">: ")))
  458.     (cond
  459.       ((= arg "porBloque") (setq arg 0))
  460.       ((= arg "Rojo")     (setq arg 1))
  461.       ((= arg "Amarillo")  (setq arg 2))
  462.       ((= arg "Verde")   (setq arg 3))
  463.       ((= arg "cIano")    (setq arg 4))
  464.       ((= arg "aZul")    (setq arg 5))
  465.       ((= arg "Magenta") (setq arg 6))
  466.       ((= arg "bLanco")   (setq arg 7))
  467.       ((= arg "porCapa") (setq arg 256))
  468.       (T
  469.         (if (= (type arg) 'INT)
  470.           (if (> arg 255)
  471.             (progn
  472.               (princ "\nN║ de color no comprendido entre 1 y 255. ")
  473.               (setq arg 257) ; kludge
  474.             )
  475.           )
  476.           (setq arg (if (= (type (setq arg (getvar "cecolor"))) 'INT)
  477.                       (getvar "cecolor") 
  478.                       (cond
  479.                         ((= arg "BYBLOCK") (setq arg 0))
  480.                         ((= arg "BYLAYER") (setq arg 256))
  481.                       )
  482.                     )
  483.           )
  484.         )
  485.       )
  486.     )
  487.   )
  488.   (cond
  489.     ((= arg 0) (setq arg "BYBLOCK"))
  490.     ((= arg 256) (setq arg "BYLAYER"))
  491.   )
  492.   arg
  493. )
  494. ;;;
  495. ;;; Set the linetype from the loaded linetypes.
  496. ;;;
  497. ;;; xp_slt == XPlode_Set_Line_Type
  498. ;;;
  499. (defun xp_slt (/ temp)
  500.   (while (null temp)
  501.     (initget 1)
  502.     (setq temp (strcase (getstring (strcat 
  503.     "\nIndique el nombre del nuevo tipo de lφnea. <" (getvar "celtype") "> : ") )))
  504.     (if (or (= temp "") (null temp))
  505.       (setq temp (getvar "celtype"))
  506.       (if (not (or (tblsearch "ltype" temp) 
  507.                    (= temp "BYBLOCK") 
  508.                    (= temp "BYLAYER")
  509.                    (= temp "CONTINUOUS")
  510.           ))
  511.         (progn
  512.           (princ "\nNombre de tipo de lφnea no vßlido.")
  513.           (setq temp nil)
  514.         )
  515.       )
  516.     )
  517.   )
  518.   temp
  519. )
  520.  
  521. ;;;
  522. ;;; Set a layer if it exists.
  523. ;;;
  524. ;;; xp_sla == XPlode_Set_LAyer
  525. ;;;
  526. (defun xp_sla (/ temp)
  527.   (while (null temp)
  528.     (initget 1)
  529.     (setq temp (getstring (strcat
  530.       "\n\n┐En quΘ capa desea descomponerlo? <" (getvar "clayer") ">: ")))
  531.     (if (or (= temp "") (null temp))
  532.       (setq temp (getvar "clayer"))
  533.       (if (not (tblsearch "layer" temp))
  534.         (progn
  535.           (princ "\nNombre de capa no vßlido. ")
  536.           (setq temp nil)
  537.         )
  538.       )
  539.     )
  540.   )
  541.   temp
  542. )
  543.  
  544. ;;; --------------------------------------------------------------------------;
  545. (defun c:xp       () (explode))
  546. (defun c:xplode   () (explode))
  547. (princ "\nC:XPlode cargada.")
  548. (princ)
  549.