+ Reply to Thread
Results 1 to 3 of 3
  1. #1
    Full Member
    Using
    Civil 3D 2007
    Join Date
    May 2004
    Location
    Tampa, Florida, USA
    Posts
    41

    Default (code) erasing layers and what not

    Registered forum members do not see this ad.

    Code:
    ;;;
    ;;; several function for erasing and purging entities on a given layer
    ;;;
    
    (defun c:del-layer (/ ent l_name ss cntr amt ssent)
    
      ;;;
      ;;; erases all enities on selected layer then purges that layer
      ;;;
    
      (setvar 'clayer "0") ; set layer to 0
    
      (if
        ; make sure we get something
        (setq ent (car (entsel "\nSelect layer to remove: "))); test
        (progn
          ; extract the layer name from the entity
          (setq l_name (cdr (assoc 8 (entget ent))))
    
          ; create a selection set of all entites on layer 'l_name'
          (setq ss (ssget "X" (list (cons 8 l_name)))
                ; set 'cntr' to number of items in selection set
                cntr (1- (sslength ss))
                amt (itoa cntr); make a string from an integer
                )
    
          (if 
            ; does the sel set have anything in it
            (> cntr 0); test
    
            (while 
              ; as long as 'cntr' is greater than or equal to 0
              ; keep looping
              (>= cntr 0)
    
              ; extract the ename from the sel set
              (setq ssent (ssname ss cntr))
              (entdel ssent); delete that entity
              (setq cntr (1- cntr)); subtract 1 from cntr
              )
    
            )
          )
        )
      (command "_.purge" "LA" l_name "N")
      (princ (strcat "\nErased " amt " items"))
      (princ)
      )
    
    ;;;
    ;;; ===================================================================
    ;;;
    
    (defun fx-rm-layer (l_name / ss sntr amt ssent)
    
      ;;;
      ;;; erase and purges all entites on 'l_name', a string
      ;;; returns the number of entites erased
      ;;;
    
      (setvar 'clayer "0")
    
      (if
        ; make sure the layer exists in the dwg
        (tblsearch "layer" l_name); test
        (progn ; continue
          (setq ss (ssget "X" (list (cons 8 l_name)))
                cntr (1- (sslength ss))
                amt cntr
                )
    
          (if (> cntr 0)
            (while
              (>= cntr 0)
              (setq ssent (ssname ss cntr))
              (entdel ssent)
              (setq cntr (1- cntr))
              )
            )
          )
        )
      (if (> amt 0)
        (command "_.purge" "LA" l_name "N")
        )
      ; return the amount of entites erased
      amt
      )
    
    ;;;
    ;;; ===================================================================
    ;;;
    
    (defun fx-make-layer-list (/ ent l_name entlst)
    
      ;;;
      ;;; generate a list of layer names based on user selection
      ;;; and returns that list
      ;;;
    
      (while
        ; while user is selecting something continue loop
        (setq ent (car (entsel "\nSelect Item on Layer: "))); test
    
        ; extract layer name from selected entity
        (setq l_name (cdr (assoc 8 (entget ent))))
        (prompt l_name); output the layer
    
        (if 
          ; make sure the layer isn't already in the list
          (not (vl-position l_name entlst)); test
    
          ; if not then add it to the list
          (setq entlst (cons l_name entlst))
          )
        )
      )
    
    ;;;
    ;;; ===================================================================
    ;;;
    
    (defun c:del-purge (/ lst)
      (setq cmd (getvar 'cmdecho))
    
      ; turn off the echo!
      (setvar 'cmdecho 0)
    
      (if
        ; make sure we get a list before we continue
        (setq lst (fx-make-layer-list)); test
    
        ; now that we have a list run 'fx-rm-layer' on each of those items
        (mapcar '(lambda (x) (fx-rm-layer x)) lst)
        )
    
      ; reset the variable
      (setvar 'cmdecho cmd)
      (princ)
      )
    My signature goes here

  2. #2
    Administrator CADTutor's Avatar
    Computer Details
    CADTutor's Computer Details
    Operating System:
    Windows 7 Home Premium 64bit
    Motherboard:
    Asus P7P55D-E PRO
    CPU:
    Intel Core i7-860
    RAM:
    4GB PC3-12800 C8 Corsair Dominator
    Graphics:
    NVIDIA Quadro FX 1800 768 MB
    Primary Storage:
    Intel X25-M SSD 160GB
    Secondary Storage:
    Samsung Spinpoint 320GB
    Monitor:
    BenQ FP241W 24" Wide
    Discipline
    Education
    CADTutor's Discipline Details
    Occupation
    Senior Lecturer (Digital Design), Landscape Architect & Web Designer
    Discipline
    Education
    Using
    AutoCAD 2014
    Join Date
    Aug 2002
    Location
    Hampshire, UK
    Posts
    3,606

    Default

    Thanks Mark for the generous contribution. Extremely useful - I'll add that to out AutoLISP archive if you don't mind.

    Tip: Please do not PM or email me with CAD questions - use the forums, you'll get an answer sooner.
    AutoCAD Tutorials | How to add images to your posts | How to register successfully | Forum FAQ

  3. #3
    Full Member
    Using
    Civil 3D 2007
    Join Date
    May 2004
    Location
    Tampa, Florida, USA
    Posts
    41

    Default

    Registered forum members do not see this ad.

    Quote Originally Posted by CADTutor
    Thanks Mark for the generous contribution. Extremely useful - I'll add that to out AutoLISP archive if you don't mind.

    not at all.
    My signature goes here

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