JoeMama22 Posted May 7, 2021 Posted May 7, 2021 Hello, I am trying to delete specific layers, so far I have this code. The DLE.lsp is attempting to delete specific layers using the LAYDEL command. Afterwards dimensions will be exported using LISP code I found on this very forum. (see dimexp.lsp). I am trying to write the code so it combines both, this way I can shift through dimension data and put in on an excel sheet. I have to do 5000 dwg's dimensions and input their parameters on a excel sheet to create a standard size database. This is my first time writing LISP code and any help would be apprecaited. Thank you! DLE.lsp dimexp.lsp Quote
mhupp Posted May 7, 2021 Posted May 7, 2021 (edited) (defun c:DLE () (LayerDelete '( "48" "53" "54" "55" "NICKTRN" "FLATUTIL" "CNOT")) (princ) ) ;;------------------------------------------------------------------------------------------------------------;; ;; Delete Layers in List (defun LayerDelete (#DelLayers / #Layers) (vl-load-com) (setq #Layers (vla-get-layers (vla-get-activedocument (vlax-get-acad-object)))) (mapcar '(lambda (lay) (if (tblsearch "Layer" lay) (progn (vla-delete (vla-item (vla-get-layers (vla-get-activeDocument(vlax-get-acad-object))) lay)) (prompt (strcat "\nLayer " lay " Deleted")) ) (prompt (strcat "\nLayer " lay " Doesn't Exist")) ) ) #DelLayers ) ) Edited May 7, 2021 by mhupp Quote
JoeMama22 Posted May 7, 2021 Author Posted May 7, 2021 That script did work in prompting the LAYDEL command, however I still have to manually input the layers into the command line. I appreciate your help but sadly I'm still where I started! Thank you anyways! Quote
mhupp Posted May 7, 2021 Posted May 7, 2021 (edited) 1 hour ago, JoeMama22 said: That script did work in prompting the LAYDEL command, however I still have to manually input the layers into the command line. I appreciate your help but sadly I'm still where I started! Thank you anyways! Updated my code to visual lisp should work now. I use BricsCAD so probably that's why i didn't work. saw that your lisp had "LA" and BriscsCAD use "T" to list layers Edited May 7, 2021 by mhupp Quote
mhupp Posted May 7, 2021 Posted May 7, 2021 (edited) If the other lisp is doing everything you want. its easy to add them together now. (defun C:DimExp (/ s tx fn dlim i d dl m file) (setq s (ssget "_X" (list '(0 . "DIMENSION"))) tx nil fn (strcat (getvar "dwgprefix") "DimExp.csv") dlim "," ; set to ";" for CSY/DEU... ) (repeat (setq i (sslength s)) (setq d (ssname s (setq i (1- i))) dl (entget d) m (cdr (assoc 42 dl)) ) (if (not (member m tx)) (setq tx (cons m tx))) ) (setq s nil) (if tx (progn (setq file (open fn "a")) ; append (write-line "" file) (princ (strcat (getvar "dwgname") dlim) file) (foreach x tx (princ x file) (princ dlim file) ) (if file (close file)) (princ (strcat "\n" (itoa (length tx)) " dimensions written to " fn)) ) ) (LayerDelete '( "48" "53" "54" "55" "NICKTRN" "FLATUTIL" "CNOT")) (princ) ) ;;------------------------------------------------------------------------------------------------------------;; ;; Delete Layers in List (defun LayerDelete (#DelLayers / #Layers) (vl-load-com) (setq #Layers (vla-get-layers (vla-get-activedocument (vlax-get-acad-object)))) (mapcar '(lambda (lay) (if (tblsearch "Layer" lay) (progn (vla-delete (vla-item (vla-get-layers (vla-get-activeDocument(vlax-get-acad-object))) lay)) (prompt (strcat "\nLayer " lay " Deleted")) ) (prompt (strcat "\nLayer " lay " Doesn't Exist")) ) ) #DelLayers ) ) -EDIT- missed at ) Edited May 7, 2021 by mhupp Quote
JoeMama22 Posted May 7, 2021 Author Posted May 7, 2021 Yep, stitching them together was no problem! Thank you!! Quote
Jonathan Handojo Posted May 10, 2021 Posted May 10, 2021 On 5/8/2021 at 3:43 AM, mhupp said: If the other lisp is doing everything you want. its easy to add them together now. (defun C:DimExp (/ s tx fn dlim i d dl m file) (setq s (ssget "_X" (list '(0 . "DIMENSION"))) tx nil fn (strcat (getvar "dwgprefix") "DimExp.csv") dlim "," ; set to ";" for CSY/DEU... ) (repeat (setq i (sslength s)) (setq d (ssname s (setq i (1- i))) dl (entget d) m (cdr (assoc 42 dl)) ) (if (not (member m tx)) (setq tx (cons m tx))) ) (setq s nil) (if tx (progn (setq file (open fn "a")) ; append (write-line "" file) (princ (strcat (getvar "dwgname") dlim) file) (foreach x tx (princ x file) (princ dlim file) ) (if file (close file)) (princ (strcat "\n" (itoa (length tx)) " dimensions written to " fn)) ) ) (LayerDelete '( "48" "53" "54" "55" "NICKTRN" "FLATUTIL" "CNOT")) (princ) ) ;;------------------------------------------------------------------------------------------------------------;; ;; Delete Layers in List (defun LayerDelete (#DelLayers / #Layers) (vl-load-com) (setq #Layers (vla-get-layers (vla-get-activedocument (vlax-get-acad-object)))) (mapcar '(lambda (lay) (if (tblsearch "Layer" lay) (progn (vla-delete (vla-item (vla-get-layers (vla-get-activeDocument(vlax-get-acad-object))) lay)) (prompt (strcat "\nLayer " lay " Deleted")) ) (prompt (strcat "\nLayer " lay " Doesn't Exist")) ) ) #DelLayers ) ) -EDIT- missed at ) The vla-get-layers in the mapcar can be replaced with #Layers. Isn't that the purpose of setting that variable? Having AutoCAD to re-evaluate the expression in the mapcar function makes it a bit inefficient. Quote
mhupp Posted May 10, 2021 Posted May 10, 2021 18 hours ago, Jonathan Handojo said: to re-evaluate the expression in the mapcar function makes it a bit inefficient. I edited a lisp for renaming layers with two lists and did see that when posting. What it came down to is time and I can make out what visual lisp is doing but cant really program it that well. ;;------------------------------------------------------------------------------------------------------------;; ;; Delete Layers with list ;(LayerDelete '( "layer1" "layer2" "layer3" ....)) (defun LayerDelete (#DelLayers / lay) (vl-load-com) (foreach lay #DelLayers (if (tblsearch "Layer" lay) (progn (vla-delete (vla-item (vla-get-layers (vla-get-activeDocument (vlax-get-acad-object))) lay)) (prompt (strcat "\nLayer " lay " Deleted")) ) (prompt (strcat "\nLayer " lay " Doesn't Exist")) ) ) ) Quote
Recommended Posts
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.