Jump to content

Recommended Posts

Posted

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

Posted (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 by mhupp
Posted

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!

Posted (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 by mhupp
Posted

Thank you so much!

  • Thanks 1
Posted (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 by mhupp
Posted

Yep, stitching them together was no problem! Thank you!!

Posted
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.

Posted
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"))
    )
  )
)

 

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...