Jump to content

Recommended Posts

Posted

thanks~

 

When deleting layers from layer manager, I have to delete all objects on it first(I use CAD 2006)...so, I'm a lazy guy:P

 

Haha, you love your Dialog Boxes :)

 

I could create one for it, but, tbh, isn't this the same as just going into the layer manager and deleting the layer from there?

  • Replies 24
  • Created
  • Last Reply

Top Posters In This Topic

  • Lee Mac

    12

  • TheRedGuy

    6

  • Hunter

    5

  • CADgirl

    1

Top Posters In This Topic

Posted

Try this:

 

(defun DeleteLayer  (Name / ss)
   (if    (setq ss (ssget "X" (list (cons 8 lay))))
     (mapcar 'entdel (mapcar 'cadr (ssnamex ss))))
   (if    (vl-catch-all-error-p
     (vl-catch-all-apply 'vla-Delete
       (list (vlax-ename->vla-object (tblobjname "LAYER" Name)))))
     (princ "\nError Deleting Layer")))

(defun c:Ldel (/ dcTag lst uClk)
 (vl-load-com)
 (setq dcTag (load_dialog "laydel.dcl"))
 (if (not (new_dialog "laydel" dcTag))
   (progn (alert "The Dialog Box could not be loaded.") (exit)))
 (start_list "lays" 3)
 (mapcar 'add_list
     (setq lst (vl-remove-if '(lambda (x) (or (eq x "0") (eq x (getvar "CLAYER")))) (laylist)))) (end_list)
 (action_tile "accept" "(setq lay (nth (atoi (get_tile \"lays\")) lst) uClk T) (done_dialog)")
 (action_tile "cancel" "(setq uClk nil) (done_dialog)")
 (start_dialog)
 (unload_dialog dcTag)
 (if uClk (DeleteLayer lay))
 (princ))

(defun laylist (/ oLst)
   (vlax-for l (vla-get-Layers
           (vla-get-ActiveDocument
           (vlax-get-acad-object)))
   (setq oLst (cons (vla-get-Name l) oLst)))
   (reverse oLst))

laydel.zip

Posted

Thanks Lee~

It works perfectly~

How nice u are!

Posted
For a programming exercise in LISP, note that a layer can be deleted with a simple one-liner:

 

(vl-catch-all-apply 'vla-Delete (list (vlax-ename->vla-object (tblobjname "LAYER" "layername"))))

 

:P

 

And it can with VBA, as well:

 

ThisDrawing.Layers.Item("layername").Delete

 

It's less code, and runs faster. But the original version is much more robust. As for accounting for layer zero (or the current later), I just would not place them in the listbox to begin with. I'd leave the layer deleting code in the layer deleting sub, and account for data filtering to the sub, from the user Interface.

 

BTW. Nice code, Hunter:roll:

Posted

As for accounting for layer zero (or the current later), I just would not place them in the listbox to begin with. I'd leave the layer deleting code in the layer deleting sub, and account for data filtering to the sub, from the user Interface.

 

I remove the layer "0" and the current layer from the layer list before populating the popup_list in the dialog box. Removing the need for the extra "if" statement at the start of the layer deletion code. :thumbsup:

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