Jump to content

Too many layers


cduke5

Recommended Posts

I am trying to purge some layers that have gotten in my template over time.

Some layers will not let me delete them. I have used Quick Select to find the objects that are on certain layers and changed their layer but it still won't allow me to delete them. I know some layers such as 0 cannot be deleted but these are layers that have come in with imported drawings. Do I have to explode all of the blocks in my template or erase all the objects in my template to purge layers I don't want. I want about 10 layers but currently have 30-40.

Link to comment
Share on other sites

'laydel' will hard delete a layer even if it has entities on it. Just be very sure the layer you want to delete doesn't have anything you want or need on it. Also, many times blocks will have objects on the layers that you can't delete and it can be time consuming to go through every block to check and fix this, but it is another way to clean up the layers. This is another reason why putting your objects on layer 0 for blocks is a good practice.

Link to comment
Share on other sites

Probably some of yor blocks contain the layers you want to delete.

Try to edit some and see.

You don't nessecary have to explode them. Use refedit or bedit.

If your blocks use those unwanted layers, and you know exactly where, u can use lisp programs to merge these layers in other ones.

 

 

;;function to rename a layer.
;;if old layer exists, and new layer doesn't exist, the old layer is simply renamed.
;;if old layer exists, and new layer is already there, it takes everything on old layer and puts them on new layer.
;;if old layer doesn't exist, it does nothing.
(defun renlay (ol nl / ss i ent )
 (cond ((and (tblsearch "layer" ol) (not (tblsearch "layer" nl))) 
 (command "._rename" "la" ol nl)
)
((and (tblsearch "layer" ol)(tblsearch "layer" nl))
(command "-LAYMRG" "N" ol "" "N" nl "Y")
       )
((not (tblsearch "layer" ol))
 
  (prompt (strcat "\nLayer " ol " not found. "))
       )
 )
 (princ)
)
;;example
(defun c:renlays ()
 (renlay "oldlayer1" "newlayer1")
 (renlay "oldlayer2" "newlayer2")
)

 

 

See this post aswell

http://www.cadtutor.net/forum/showthread.php?55238-Rename-Layers-with-lisp-getting-lselsetp-nil-error

Link to comment
Share on other sites

The laydel worked great!

What is the best way to get rid of unwanted blocks?

The main template I start with was given to me by a friend in a different trade years ago and it contains lots of blocks we never use. I am trying to rid my template of of the clutter of unwanted layers, blocks, text styles, etc..

Any help would be appreciated.

Thanks

Link to comment
Share on other sites

Try opening a new drawing from your template and inserting instances of just the blocks you want to retain. Make sure each layer you want to retain has at least one entity on it, a line or a piece of text or something. Then issue the WBLOCK command and select all entities on screen and save as a DWG. Open this DWG remove all entities from it and save as a DWT. You have a new template with just the layers and blocks you need.

 

... but these are layers that have come in with imported drawings.

 

Why on earth are you importing drawings into your template? Templates are sacred and should not be tampered with.

Link to comment
Share on other sites

The laydel worked great!

What is the best way to get rid of unwanted blocks?

The main template I start with was given to me by a friend in a different trade years ago and it contains lots of blocks we never use. I am trying to rid my template of of the clutter of unwanted layers, blocks, text styles, etc..

Any help would be appreciated.

Thanks

 

You can use 'quickselect' to locate blocks you want to get rid of. Delete the blocks as you go and then purge the drawing so they are no longer in the database. See dialog box below...

 

QUICKSELECT DIALOG BOX.JPG

 

For text styles - make sure all the text you want to keep has the text style applied you want to use then in the styles dialog set current the style you want as your default. Then purge the drawing.

 

TEXT STYLE DIALOG BOX.JPG

 

Be sure to select the purge nested items and the confirm box. I like having a fail safe in case I want to make a decision on an item by item basis.

 

PURGE DIALOG BOX.JPG

Link to comment
Share on other sites

  • 1 year later...

Is there a way to specify any number of layer with certain layer name ending like *-OLD-ABC into a new name *-NEW-XYZ? The routine currently only works if we have complete layer names. Thanks in advance.

 

Probably some of yor blocks contain the layers you want to delete.

Try to edit some and see.

You don't nessecary have to explode them. Use refedit or bedit.

If your blocks use those unwanted layers, and you know exactly where, u can use lisp programs to merge these layers in other ones.

 

 

;;function to rename a layer.
;;if old layer exists, and new layer doesn't exist, the old layer is simply renamed.
;;if old layer exists, and new layer is already there, it takes everything on old layer and puts them on new layer.
;;if old layer doesn't exist, it does nothing.
(defun renlay (ol nl / ss i ent )
(cond ((and (tblsearch "layer" ol) (not (tblsearch "layer" nl))) 
(command "._rename" "la" ol nl)
)
((and (tblsearch "layer" ol)(tblsearch "layer" nl))
(command "-LAYMRG" "N" ol "" "N" nl "Y")
)
((not (tblsearch "layer" ol))

(prompt (strcat "\nLayer " ol " not found. "))
)
)
(princ)
)
;;example
(defun c:renlays ()
(renlay "oldlayer1" "newlayer1")
(renlay "oldlayer2" "newlayer2")
)

 

 

See this post aswell

http://www.cadtutor.net/forum/showthread.php?55238-Rename-Layers-with-lisp-getting-lselsetp-nil-error

Link to comment
Share on other sites

Kam1967, please check if this is what you are looking for:

;routine to Batch Rename Layers Suffix
(defun c:BRLS( / oldCmd suffixOld suffixNew layerItem index )
(setq oldCmd (getvar "CMDECHO"))(setvar "CMDECHO" 0)
(if (and (setq suffixOld (getstring "\nOld suffix: "))
         (setq suffixNew (getstring "\nNew suffix: ")))
 (progn
  (setq layerItem (cdr (assoc 2 (tblnext "LAYER" 1)))
        index 0)

  (while layerItem
   (if (wcmatch (strcase layerItem) (strcase (strcat "*" suffixOld)))
    (progn
     (command "_RENAME" "_LA" layerItem (strcat (substr layerItem 1 (- (strlen layerItem) (strlen suffixOld))) suffixNew))
     (setq index (1+ index))
    )
   )
   (setq layerItem (cdr (assoc 2 (tblnext "LAYER"))))
  )
  (prompt (strcat "\nFixed names of " (itoa index) " layers."))
 )
)
(setvar "CMDECHO" oldCmd)
(princ)
)

Usage:

Command: BRLS

Old suffix: -OLD-ABC

New suffix: -NEW-XYZ

Link to comment
Share on other sites

Even though this tip is unrelated to the O.P.'s need to delete layers, just thought I'd share. Layer Properties Filters are an amazing way to consolidate only necessary layers for practical use if you have an extensive Layer setup.

Link to comment
Share on other sites

Mircea,

 

This one after specifying the layer names it pops up a rename dialogue box. I have a couple of questions for you. Since it does not function properly yet - does it rename to a new layer suffix if there is already one there? Would it merge with existing, if one already exists? And lastly, if I can just type in the name of the suffix to change from/to on the setq lines, would it take an * as in setq suffixOld "*Old suffix"? Thanks!

 

Kam1967, please check if this is what you are looking for:

;routine to Batch Rename Layers Suffix
(defun c:BRLS( / oldCmd suffixOld suffixNew layerItem index )
(setq oldCmd (getvar "CMDECHO"))(setvar "CMDECHO" 0)
(if (and (setq suffixOld (getstring "\nOld suffix: "))
(setq suffixNew (getstring "\nNew suffix: ")))
(progn
(setq layerItem (cdr (assoc 2 (tblnext "LAYER" 1)))
index 0)

(while layerItem
(if (wcmatch (strcase layerItem) (strcase (strcat "*" suffixOld)))
(progn
(command "_RENAME" "_LA" layerItem (strcat (substr layerItem 1 (- (strlen layerItem) (strlen suffixOld))) suffixNew))
(setq index (1+ index))
)
)
(setq layerItem (cdr (assoc 2 (tblnext "LAYER"))))
)
(prompt (strcat "\nFixed names of " (itoa index) " layers."))
)
)
(setvar "CMDECHO" oldCmd)
(princ)
)

Usage:

Link to comment
Share on other sites

I realy don't understand why that dialog box show up. However I have fixed the code to don't use the command for rename. Have added also a protection for existing layers with intended new name - those will be reported.

To use it, you should input only the old, respectively new suffix (that it, no "*"); see the usage example in my previous post.

;;; Routine to Batch Rename Layers Suffix (13-IV-2012)
(defun c:BRLS( / oldCmd suffixOld suffixNew layerItem index assocList )
(setq oldCmd (getvar "CMDECHO"))(setvar "CMDECHO" 0)
(if (and (setq suffixOld (getstring "\nOld suffix: "))
         (setq suffixNew (getstring "\nNew suffix: ")))
 (progn
  (setq layerItem (cdr (assoc 2 (tblnext "LAYER" 1)))
        index 0)

  (while layerItem
   (if (and (wcmatch (strcase layerItem) (strcase (strcat "*" suffixOld)))
            (> (strlen layerItem) (strlen suffixOld)))
    (progn
     (setq nameNew (strcat (substr layerItem 1 (- (strlen layerItem) (strlen suffixOld))) suffixNew))
     (if (not (tblsearch "LAYER" nameNew))
      (progn
       ;(command "_RENAME" "_LA" layerItem nameNew)
       (setq assocList (entget (tblobjname "LAYER" layerItem)))
       (entmod (subst (cons 2 nameNew)
                      (assoc 2 assocList)
                      assocList))
       (setq index (1+ index))
      )
      (prompt (strcat "\nLayer \"" nameNew "\" already exist - cannot rename \"" layerItem "\"."))
     )
    )
   )
   (setq layerItem (cdr (assoc 2 (tblnext "LAYER"))))
  )
  (prompt (strcat "\nFixed names of " (itoa index) " layers."))
 )
)
(textpage)
(setvar "CMDECHO" oldCmd)
(princ)
)

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...