+ Reply to Thread
Results 1 to 7 of 7
  1. #1
    Full Member Manila Wolf's Avatar
    Discipline
    Construction
    Using
    AutoCAD 2009
    Join Date
    Oct 2011
    Location
    Philippines
    Posts
    93

    Default Explode but keep colours.

    A very hopeful question because my lisp skills are very limited indeed.

    Anybody have a lisp in their library that could do the following: -

    Allow selection of a block or a selection of a number of objects that may contain blocks and fully explode it (including the exploding of all levels of nested blocks within the selection), to layer zero or a specified layer, but keep all the on screen colours of the original block?

    Why would you want to do that I hear you say?

    I like to paste detailed parts of drawings into another drawing maintaining all the object colours, but I do not want to clog up the destination drawing with lots of layers.

  2. #2
    Forum Deity rkent's Avatar
    Computer Details
    rkent's Computer Details
    Operating System:
    WIN7 PRO 64bit
    Computer:
    Dell Precision T7500
    CPU:
    Xeon Dual Core E5503 2.0Ghz
    RAM:
    6GB DDR3 ECC SDRAM, 1333MHz, 6x1GB
    Graphics:
    nVidia Quadro 3800
    Primary Storage:
    300Gb, 10K rpm
    Monitor:
    Dell 24" FS (2x)
    Discipline
    Mechanical
    rkent's Discipline Details
    Occupation
    Facilities Design - Semi-conductor manufacturing
    Discipline
    Mechanical
    Details
    Designer: Process Piping, P&ID's, Machine Part Design, Planning / General Arrangement. Facilities Management. Drafting: Electrical, Controls, Architectural.
    Using
    Mechanical 2015
    Join Date
    Nov 2007
    Location
    Lat:35, Long:-106, Elev: 5164'
    Posts
    3,904

    Default

    XPLODE will get you a little closer if not there, watch the command line.
    Sometimes there's a man... I won't say a hero, 'cause, what's a hero? But sometimes, there's a man. And I'm talkin' about the Dude here. Sometimes, there's a man, well, he's the man for his time and place. He fits right in there. And that's the Dude, in Los Angeles. - The Stranger, The Big Lebowski

  3. #3
    Super Member marko_ribar's Avatar
    Computer Details
    marko_ribar's Computer Details
    Operating System:
    Windows 7 Ultimate X64
    Computer:
    Intel quad core CPU 4x2.66GHz, 8GB RAM
    Motherboard:
    INTEL compatibile
    CPU:
    quad core 4x2.66GHz
    RAM:
    8GB
    Graphics:
    NVIDIA GeForce 6600 GT
    Primary Storage:
    250 GB
    Secondary Storage:
    500 GB
    Monitor:
    Samsung 17''
    Discipline
    Architectural
    marko_ribar's Discipline Details
    Occupation
    Architecture, project designer, project visualisation
    Discipline
    Architectural
    Details
    space design - modeling and animations
    Using
    AutoCAD 2014
    Join Date
    Feb 2010
    Location
    Belgrade, Serbia, Europe
    Posts
    609

    Default

    Maybe, try this :

    Code:
    (defun c:xallblkslay2col (/ ss k e laye collaye sse n ess)
      (vl-load-com)
      (vl-cmdf "_.zoom" "e")
      (vl-cmdf "_.-xref" "u" "*")
      (while (setq ss (ssget "_W"
                             (getvar 'extmin)
                             (getvar 'extmax)
                             '((0 . "INSERT"))
                      )
             )
        (setq k (sslength ss))
        (while (setq e (ssname ss (setq k (1- k))))
          (setq laye (cdr (assoc 8 (entget e))))
          (setq collaye (cdr (assoc 62 (tblsearch "LAYER" laye))))
          (vl-cmdf "_.explode" e)           ; A2009 and higher
                                            ;(vl-cmdf "_.explode" e "") ; A2008 and lower
          (setq sse (ssget "_P"))
          (setq n (sslength sse))
          (while (setq ess (ssname sse (setq n (1- n))))
            (if (/= (cdr (assoc 0 (entget ess))) "INSERT")
              (progn
                (entmod
                  (subst (cons 8 "0") (assoc 8 (entget ess)) (entget ess))
                )
                (if (not (assoc 62 (entget ess)))
                  (vla-put-color (vlax-ename->vla-object ess) collaye)
                )
                (entupd ess)
              )
            )
          )
        )
      )
      (vl-cmdf "_.-xref" "r" "*")
      (princ)
    )
    (defun c:xall nil (c:xallblkslay2col))
    (prompt "\nShortcut for c:xallblkslay2col is c:xall")
    (princ)
    M.R.

    Marko Ribar, d.i.a. (graduated engineer of architecture)
    M.R. on YouTube

  4. #4
    Super Member marko_ribar's Avatar
    Computer Details
    marko_ribar's Computer Details
    Operating System:
    Windows 7 Ultimate X64
    Computer:
    Intel quad core CPU 4x2.66GHz, 8GB RAM
    Motherboard:
    INTEL compatibile
    CPU:
    quad core 4x2.66GHz
    RAM:
    8GB
    Graphics:
    NVIDIA GeForce 6600 GT
    Primary Storage:
    250 GB
    Secondary Storage:
    500 GB
    Monitor:
    Samsung 17''
    Discipline
    Architectural
    marko_ribar's Discipline Details
    Occupation
    Architecture, project designer, project visualisation
    Discipline
    Architectural
    Details
    space design - modeling and animations
    Using
    AutoCAD 2014
    Join Date
    Feb 2010
    Location
    Belgrade, Serbia, Europe
    Posts
    609

    Default

    This should work also - not to influence on XREFs :

    Code:
    (defun c:xallblkslay2col (/ loop ss k e laye collaye sse n ess)
      (vl-load-com)
      (setq loop T)
      (while (and loop
                  (setq ss (ssget "_X"
                                  '((0 . "INSERT"))
                           )
                  )
             )
        (repeat (setq k (sslength ss))
          (setq e (ssname ss (setq k (1- k))))
          (if (vlax-property-available-p (vlax-ename->vla-object e) 'Path)
            (ssdel e ss)
          )
        )
        (setq k (sslength ss))
        (if (/= k 0)
          (progn
            (while (setq e (ssname ss (setq k (1- k))))
              (setq laye (cdr (assoc 8 (entget e))))
              (setq collaye (cdr (assoc 62 (tblsearch "LAYER" laye))))
              (vl-cmdf "_.explode" e)       ; A2009 and higher
                                            ;(vl-cmdf "_.explode" e "") ; A2008 and lower
              (setq sse (ssget "_P"))
              (setq n (sslength sse))
              (while (setq ess (ssname sse (setq n (1- n))))
                (if (/= (cdr (assoc 0 (entget ess))) "INSERT")
                  (progn
                    (entmod
                      (subst (cons 8 "0")
                             (assoc 8 (entget ess))
                             (entget ess)
                      )
                    )
                    (if (not (assoc 62 (entget ess)))
                      (vla-put-color (vlax-ename->vla-object ess) collaye)
                    )
                    (entupd ess)
                  )
                )
              )
            )
          )
          (setq loop nil)
        )
      )
      (princ)
    )
    (defun c:xall nil (c:xallblkslay2col))
    (prompt "\nShortcut for c:xallblkslay2col is c:xall")
    (princ)
    M.R.

    Marko Ribar, d.i.a. (graduated engineer of architecture)
    M.R. on YouTube

  5. #5
    Full Member Manila Wolf's Avatar
    Discipline
    Construction
    Using
    AutoCAD 2009
    Join Date
    Oct 2011
    Location
    Philippines
    Posts
    93

    Default

    rkent: - Thank you for your suggestion. I remember looking at Xplode some time ago. Your reply prompted me to take a further look, but I could not arrive at what I am looking for.

    marko: - Many thanks for your prompt replies offering coding. I did try both codes, but unfortunately the codes only work in some instances.

    I attach a simple drawing that I created to act as a test.
    When I ran the code, the series of lines were indeed all sent to layer zero, but some colours did also change to the layer zero colour which in this test case is white.

    I think a lot is dependent on what layer the original objects were created on in the first place before being nested into blocks.
    In my test drawing, with the series of lines on the left, each line was drawn on a separate individual layer, with colour bylayer before being nested into a block.
    With the series of lines on the right of the drawing, each line was drawn on layer zero with the colour of each being changed but still on layer zero, all before being nested into a block.
    Attached Files

  6. #6
    Super Member marko_ribar's Avatar
    Computer Details
    marko_ribar's Computer Details
    Operating System:
    Windows 7 Ultimate X64
    Computer:
    Intel quad core CPU 4x2.66GHz, 8GB RAM
    Motherboard:
    INTEL compatibile
    CPU:
    quad core 4x2.66GHz
    RAM:
    8GB
    Graphics:
    NVIDIA GeForce 6600 GT
    Primary Storage:
    250 GB
    Secondary Storage:
    500 GB
    Monitor:
    Samsung 17''
    Discipline
    Architectural
    marko_ribar's Discipline Details
    Occupation
    Architecture, project designer, project visualisation
    Discipline
    Architectural
    Details
    space design - modeling and animations
    Using
    AutoCAD 2014
    Join Date
    Feb 2010
    Location
    Belgrade, Serbia, Europe
    Posts
    609

    Default

    Thank you for your testing, I think that now it will work...

    Code:
    (defun c:xallblkslay2col (/ loop ss k e laye layess collaye collayess sse n ess)
      (vl-load-com)
      (setq loop T)
      (while (and loop
                  (setq ss (ssget "_X"
                                  '((0 . "INSERT"))
                           )
                  )
             )
        (repeat (setq k (sslength ss))
          (setq e (ssname ss (setq k (1- k))))
          (if (vlax-property-available-p (vlax-ename->vla-object e) 'Path)
            (ssdel e ss)
          )
        )
        (setq k (sslength ss))
        (if (/= k 0)
          (progn
            (while (setq e (ssname ss (setq k (1- k))))
              (setq laye (cdr (assoc 8 (entget e))))
              (setq collaye (cdr (assoc 62 (tblsearch "LAYER" laye))))
              (vl-cmdf "_.explode" e)       ; A2009 and higher
                                            ;(vl-cmdf "_.explode" e "") ; A2008 and lower
              (setq sse (ssget "_P"))
              (setq n (sslength sse))
              (while (setq ess (ssname sse (setq n (1- n))))
                (if (/= (cdr (assoc 0 (entget ess))) "INSERT")
                  (progn
                    (setq layess (cdr (assoc 8 (entget ess))))
                    (setq collayess (cdr (assoc 62 (tblsearch "LAYER" layess))))
                    (if (and (/= (cdr (assoc 8 (entget ess))) "0") (not (assoc 62 (entget ess))))
                      (vla-put-color (vlax-ename->vla-object ess) collayess)
                    )
                    (if (and (= (cdr (assoc 8 (entget ess))) "0") (not (assoc 62 (entget ess))))
                      (vla-put-color (vlax-ename->vla-object ess) collaye)
                    )
                    (entmod
                      (subst (cons 8 "0")
                             (assoc 8 (entget ess))
                             (entget ess)
                      )
                    )
                    (entupd ess)
                  )
                )
              )
            )
          )
          (setq loop nil)
        )
      )
      (princ)
    )
    (defun c:xall nil (c:xallblkslay2col))
    (prompt "\nShortcut for c:xallblkslay2col is c:xall")
    (princ)
    M.R.

    Marko Ribar, d.i.a. (graduated engineer of architecture)
    M.R. on YouTube

  7. #7
    Full Member Manila Wolf's Avatar
    Discipline
    Construction
    Using
    AutoCAD 2009
    Join Date
    Oct 2011
    Location
    Philippines
    Posts
    93

    Default

    Registered forum members do not see this ad.

    Marko, This works very well indeed. You made my day!

    I tested it not just on my own simple test drawing, but on other more detailed drawings. It worked in every scenario.

    I shall now be using this code extensively, so sincere thanks for your impressive coding skills and for your valuable time spent helping me.

    Cheers.

Similar Threads

  1. Convert from index colours to true colours
    By djguinan in forum AutoLISP, Visual LISP & DCL
    Replies: 9
    Last Post: 6th Jan 2012, 05:50 pm
  2. Can Block colours correspond to different layer colours?
    By BenGoble in forum AutoCAD 2D Drafting, Object Properties & Interface
    Replies: 1
    Last Post: 18th Apr 2010, 02:04 pm
  3. Explode block / explode text command
    By repelectric in forum AutoCAD General
    Replies: 1
    Last Post: 3rd Aug 2009, 09:52 pm
  4. layer colours and screen colours
    By alec in forum AutoCAD Beginners' Area
    Replies: 5
    Last Post: 13th Jun 2008, 12:49 pm
  5. colours
    By chrisdarmanin in forum AutoCAD General
    Replies: 9
    Last Post: 27th May 2008, 04:48 pm

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts