Author Topic: fIND AND RENAME LAYERS  (Read 2386 times)

0 Members and 1 Guest are viewing this topic.

pedroantonio

  • Guest
fIND AND RENAME LAYERS
« on: July 15, 2018, 04:12:35 AM »
Ηι. I have a problem and i need help.I youse a lot of layers in my drawings. I need a lisp to search my layers in the drawing and rename some of them.I need to add in the code all the layers i use and  another list with the new names . I find acode but is not working. Can any one help ?

Code - Auto/Visual Lisp: [Select]
  1. ;;function to rename a layer.
  2. ;;if old layer exists, and new layer doesn't exist, the old layer is simply renamed.
  3. ;;if old layer exists, and new layer is already there, it takes everything on old layer and puts them on new layer.
  4. ;;if old layer doesn't exist, it does nothing.
  5. (defun renlay (ol nl / ss i ent )
  6.   (cond ((and (tblsearch "layer" ol) (not (tblsearch "layer" nl)))
  7.          (command "._rename" "la" ol nl)
  8.         )
  9.         ((and (tblsearch "layer" ol)(tblsearch "layer" nl))
  10.           (setq ss (ssget "x" (list (cons 8 ol))))
  11.           (setq i -1)
  12.            (repeat (sslength ss)
  13.               (setq ent (entget (ssname ss (setq i (1+ i))))
  14.                     ent (subst (cons 8 nl) (cons 8 (cdr (assoc 8 ent))) ent)
  15.               )    
  16.               (entmod ent)
  17.            )
  18.         )
  19.         ((not (tblsearch "layer" ol))
  20.           (prompt (strcat "\nLayer " ol " not found. "))
  21.         )
  22.   )
  23.   (princ)
  24. )
  25.  
  26. ;;example
  27. (defun c:test ()
  28.   (renlay "0" "A-Flor-Strs")
  29.   (renlay "_fence" "A-Flor-Tptn")
  30.   (renlay "ARWOOD" "A-Flor-Wdwk")
  31.   (renlay "ARFURNITURE" "A-Furn")
  32.   (renlay "ARWINDOW" "A-Glaz")
  33. )
  34.  

Crank

  • Water Moccasin
  • Posts: 1503
Re: fIND AND RENAME LAYERS
« Reply #1 on: July 15, 2018, 06:50:39 AM »
Can't you use the LAYTRANS command to create a file and then use (acet-laytrans) in your lisp?
Vault Professional 2023     +     AEC Collection

kdub_nz

  • Mesozoic keyThumper
  • SuperMod
  • Water Moccasin
  • Posts: 2138
  • class keyThumper<T>:ILazy<T>
Re: fIND AND RENAME LAYERS
« Reply #2 on: July 15, 2018, 10:11:21 AM »
Since you haven't explained the "but is not working" part ...
Wild assed guess :
Layer 0 can not be deleted ... what happens if you comment out the first statement in the test function.

asides :
The routine would be more efficient if you assigned the values from the tblsearch methods to variables prior to the conditional, and replace the in-line calls with the variable.

Adding an error function would be a little more professional.
Called Kerry in my other life
Retired; but they dragged me back in !

I live at UTC + 13.00

---
some people complain about loading the dishwasher.
Sometimes the question is more important than the answer.

pedroantonio

  • Guest
Re: fIND AND RENAME LAYERS
« Reply #3 on: July 15, 2018, 11:51:49 AM »
Thanks for the reply. For the 0 layer i already find it .I am not good in lisp. if anyone can do some changes to improve the code ?

Thanks

Crank

  • Water Moccasin
  • Posts: 1503
Re: fIND AND RENAME LAYERS
« Reply #4 on: July 16, 2018, 01:09:12 PM »
Quote
if old layer exists, and new layer is already there, it takes everything on old layer and puts them on new layer.
Basicly this means that you want to merge layers. If layers are used in blocks or xdata then this is a lot more complicated than renaming a layer.
Also: You can't merge layer '0' or layer 'Defpoints'.

The attached lisp is a modified version of a lisp from the expresstools. I don't use it any more, because it's very slow and new objects are not supported.

The suggestion from my previous post is fast and only needs one line of code. Just make sure that the .dws (or rename the .dws to .dwg) that you've created with the LAYTRANS command is in your search path.
Code: [Select]
(or (member "laytrans.arx" (arx)) (arxload "laytrans"))
(acet-laytrans "YourFile.dws" 7)
« Last Edit: July 16, 2018, 01:19:41 PM by Crank »
Vault Professional 2023     +     AEC Collection