Author Topic: Layer deletion...  (Read 3724 times)

0 Members and 1 Guest are viewing this topic.

Raydancer

  • Guest
Layer deletion...
« on: January 30, 2004, 11:15:49 AM »
I'm writing a lisp that will completely delete the current layer, and it's coming along nicely.  It basically sets the current layer as "vclayer", creates a list of layers in order to get the next and previous layer, if the layer is the last layer in the drawing it goes to the previous layer, otherwise it goes to the next layer, and then it deletes what was the current layer.  I've got everything working, except for the most important part: the deleting.

I've tried:
(c:laydel "t" vclayer "" "yes")
(command "c:laydel" "t" vclayer "" "yes")
(command "laydel" "t" vclayer "" "yes")
(command "(c:laydel)" "t" vclayer "" "yes")
...and none of them work.

Keep in mind that I want the layer completely gone...I don't just want everything off of the layer.

Thanks for any help you can give me...

Don   :)

Matt Stachoni

  • Guest
Layer deletion...
« Reply #1 on: January 30, 2004, 11:51:32 AM »
First off, you cannot purge the current layer, even if it's blank. You must record the layer as a variable, move to another layer (layer 0 is the most logical choice) then delete/purge it.

You also need to decide if your (laydel) routine is implemented as a command or a function. It's eaier to call it with argements if it's a function, e.g. (laydel arg arg arg) than as a command, because the (c:laydel) form cannot be defined with arguments to modify its behaviour.

Thus, you could write the routine as a generic (laydel) function with arguments, then wrap that up into a C:LAYDEL command routine that inputs the correct arguments, like so:

Code: [Select]

;; Generic delete layer function, note lyr argument cannot be current layer.
;; I would also return a Boolean to validate the purging of the layer
(defun layedel (arg lyr ans / LocalArgs)
  ;delete layer code goes here......
  ;; return boolean flag if successful
  (if (tblobjname "layer" lyr) nil T)
)


and write the command routine thusly:
Code: [Select]

(defun c:LayerDel (/ vclayer)
  (setq vclayer (getvar "clayer"))
  (command "._layer" "t" "0" "on" "0" "s" "0" "")
  (if (laydel "t" vclayer "yes")
    (prompt (strcat "\nLayer " vclayer " deleted."))
    (prompt (strcat "\nError: Layer " vclayer " not deleted."))
  )
  (princ)
)

Matt Stachoni

  • Guest
Layer deletion...
« Reply #2 on: January 30, 2004, 11:54:24 AM »
Quote from: Matt Stachoni
 ;; return boolean flag if successful
  (if (tblobjname "layer" lyr) nil T)


Bleah! Write it as this instead:
(not (tblobjname "layer" lyr))

Keith™

  • Villiage Idiot
  • Seagull
  • Posts: 16899
  • Superior Stupidity at its best
Layer deletion...
« Reply #3 on: January 30, 2004, 12:25:07 PM »
This example deletes the a layer you specify, but as Matt pointed out, it is not possible to delete the current layer (without more code).

Code: [Select]
(defun dellay( layer )
  (vl-load-com)
  (vla-delete (vla-item (vla-get-layers (vla-get-activeDocument(vlax-get-acad-object))) layer))
)


You call this function by supplying a layer name as such:

Code: [Select]
(dellay "LAYER1")
Proud provider of opinion and arrogance since November 22, 2003 at 09:35:31 am
CadJockey Militia Field Marshal

Find me on https://parler.com @kblackie

Anonymous

  • Guest
Layer deletion...
« Reply #4 on: January 30, 2004, 01:25:07 PM »
Quote from: Keith
Code: [Select]
(defun dellay( layer )
  (vl-load-com)
  (vla-delete (vla-item (vla-get-layers (vla-get-activeDocument(vlax-get-acad-object))) layer))
)


Don't forget to first test for the existence of the layer before you put the layer name variable in the nested code, because you'll get an ugly automation error if it doesn't.

Of course, you can test the validity of the argument before you call it:

Code: [Select]
(if (not (= (getvar "clayer") MyLayer))
  (if (tblobjname "layer" MyLayer)
    (dellay MyLayer)
  )
)