I can't delete layers with objects
Hello, Can anyone help me? I can't delete layers and their entities automatically. Thank you.
;
Rutina para renombra y borrar capas de Catastro
;
(defun c:mcapas ()
(setq capas-renombre '(
("Construccion" . "CATASTRO Construccion")
("Parcela" . "CATASTRO Parcela")
("RefCatastral" . "CATASTRO RefCatastral")
)
)
(setq capas-eliminar '("Busqueda" "Subparcela" "txtConstru" "txtSubpa"))
(vl-load-com)
(setq doc (vla-get-activedocument (vlax-get-acad-object)))
(vla-startundomark doc)
; Renombrar capas
(vlax-for layer (vla-get-layers doc)
(setq capa-nombre (vla-get-name layer))
(foreach par capas-renombre
(if (equal capa-nombre (car par))
(progn
(setq new-name (cdr par))
(if (not (equal new-name ""))
(vla-put-name layer new-name)
)
)
)
)
)
; Eliminar objetos de capas a eliminar
(vlax-for layer (vla-get-layers doc)
(setq capa-nombre (vla-get-name layer))
(if (member capa-nombre capas-eliminar)
(vla-erase layer)
)
)
; Eliminar capas
(vlax-for layer (vla-get-layers doc)
(setq capa-nombre (vla-get-name layer))
(if (member capa-nombre capas-eliminar)
(vla-delete layer)
)
)
(vla-endundomark doc)
(vla-regen doc acAllViewports)
)
(princ)
0
Comments
-
Hi Luis,
you should delete all items on the layer first.
You can find inspiration here:
https://jtbworld.com/autocad-layers-erase-lsp0 -
Do you know about the Express Tools LAYDEL command? From the description, it sounds like it does what you want.0
-
Thank you all. I will try0
-
; Rutina para renombrar y borrar capas de Catastro
(defun c:mcapas ()
(setq capas-renombre '(
("Construccion" . "CATASTRO Construccion")
("Parcela" . "CATASTRO Parcela")
("RefCatastral" . "CATASTRO RefCatastral")
)
)
(setq capas-eliminar '("Busqueda" "Subparcela" "txtConstru" "txtSubpa"))
(vl-load-com)
(setq doc (vla-get-activedocument (vlax-get-acad-object)))
(vla-startundomark doc)
; Renombrar capas
(vlax-for layer (vla-get-layers doc)
(setq capa-nombre (vla-get-name layer))
(foreach par capas-renombre
(if (equal capa-nombre (car par))
(progn
(setq new-name (cdr par))
(if (not (equal new-name ""))
(vla-put-name layer new-name)
)
)
)
)
)
; Eliminar objetos y capas
(foreach lay capas-eliminar
(if (tblsearch "layer" lay)
(command "_.-laydel" lay "")
)
)
(vla-endundomark doc)
(vla-regen doc acAllViewports)
)
(princ)
_______________________________________________________________________________________________________________________
: MCAPAS
Incapaz de reconocer el comando "-LAYDEL".
Incapaz de reconocer el comando "-LAYDEL".
Incapaz de reconocer el comando "-LAYDEL".
Incapaz de reconocer el comando "-LAYDEL".nil0 -
I think Express Tools don't work in Lisp code. But someone on this forum said that Express Tools are included in Bricscad beginning with v2023; so maybe in the newest version it is possible to use LAYDEL in Lisp code.Anthony Apostolaros said:... Express Tools LAYDEL command ...
But Express Tools can be used in macros. I found an old forum thread from 2015 in which I wrote that I was able to use LAYDEL in a macro to delete all objects on the 3 layers named. I wrote that it deleted objects in blocks, without deleting the rest of the block, and also deleted the layers themselves. I also wrote that it worked on layers that were off or frozen, but not on layers that were locked. Most of the Express Tools no longer work on my system, so I can't verify it, but this is the macro code I posted in 2015:^c^claydel;t;layer1;t;layer2;t;layer3;;y;graphscr;
Have you tried(vla-delete layer)
?0 -
(vla-delete layer)?
Yes:
;
Rutina para renombra y borrar capas de Catastro
;
(defun c:mcapas ()
(setq capas-renombre '(
("Construccion" . "CATASTRO Construccion")
("Parcela" . "CATASTRO Parcela")
("RefCatastral" . "CATASTRO RefCatastral")
)
)
(setq capas-eliminar '("Busqueda" "Subparcela" "txtConstru" "txtSubpa"))
(vl-load-com)
(setq doc (vla-get-activedocument (vlax-get-acad-object)))
(vla-startundomark doc)
; Renombrar capas
(vlax-for layer (vla-get-layers doc)
(setq capa-nombre (vla-get-name layer))
(foreach par capas-renombre
(if (equal capa-nombre (car par))
(progn
(setq new-name (cdr par))
(if (not (equal new-name ""))
(vla-put-name layer new-name)
)
)
)
)
)
; Eliminar objetos de capas a eliminar
(vlax-for layer (vla-get-layers doc)
(setq capa-nombre (vla-get-name layer))
(if (member capa-nombre capas-eliminar)
(vla-erase layer)
)
)
; Eliminar capas
(vlax-for layer (vla-get-layers doc)
(setq capa-nombre (vla-get-name layer))
(if (member capa-nombre capas-eliminar)
(vla-delete layer)
)
)
(vla-endundomark doc)
(vla-regen doc acAllViewports)
)
(princ)
_______________________________________________________________________________________________________
Error:
; error : Automation Error 80200139; [IAcadLayer] Error accessing [DELETE] method. ErrIndex=0;
Object is referenced by other object(s)
0 -
Laydel is available in different versions of Express tools I have V20. Can download for that version. Google Bricscad Express tools.0