Author Topic: laydel "complex" from a layer list?  (Read 3810 times)

0 Members and 1 Guest are viewing this topic.

butzers09silverado

  • Guest
laydel "complex" from a layer list?
« on: June 15, 2011, 02:42:21 PM »
I need to modify one of the 2 lisps below to allow me to delete layers from an external LIST, list, NOT lisP.  trying to use laydel to strip down a standard .dwt civil 3d template into sub templates without all the layers from the parent template.... cleans up the drawing and eliminates unnecessary layers.  waaaaay over my head. THANKS! 8-)

Code: [Select]
(defun C:DD (/ lay ss)
(setq
lay (cdr (assoc 8 (entget (car
(entsel "Select entity on layer to erase: ")))))
ss (ssget "X" (list (cons 8 lay)))
)
(command "ERASE" ss "")
(princ (strcat "\nAll entities on layer " lay " have been
erased."))
(princ)

or


Code: [Select]
; define function that will be called from the command line

(defun c:ld(/ oldCmdecho)

  ; turn off the command echo
  (setq oldCmdecho (getvar "CMDECHO"))
  (setvar "CMDECHO" 0)

  ; UNDO start
  (command "_.UNDO" "_mark")
 
  ; call main function
  (lay_del)

  ; restore command echo value
  (setvar "CMDECHO" oldCmdecho)
  (princ)
  )

; Main function

(defun lay_del ( / sec el ln msg answer selection)

  ; Prompt user for select utility
  (princ "\nselect an entity tat you want to erase it's LAYER:")
  (setq sec (entsel)
el (entget (car sec)) ; get entity list
ln (cdr (assoc 8 el)) ; LAYER of selected entity
)
  ; Separate the 8 DXF code, which gives LAYER information
  ; from the entity list by using assoc

  ; now prompt user for confirmation

  ; Prepare warning message
  ; By using strcat, we combine our message with 'ln' variable
  ; in which the name of the entity we selected is stored
 
  (setq msg (strcat "All object in " ln " LAYER will be deleted!"
  "\ndo you want to continue? [YES] / [NO] :"))

  (initget "Yes No") ; Set keywords
  (setq answer (getkword msg))

  ; Evaluate the answer, if no go to (exit_prg)
  ; Else go on
  (if (= answer"No") (exit_prg) (princ))

  ; now select the entities to be deleted
  ; We are passing dottd pair (8 . "CHOSEN_LAYER") to
  ; ssget function as filter value

  (setq selection (ssget "X" (list (cons 8 ln))))

  ; now we can erase entitites which are stored as previous
  ; selection set using command function
  (command "_.ERASE" "_p" "")

  ; Exit
  (exit_prg)
 
  )

(defun exit_prg()
  (princ "\nPlease UNDO BACK if you want to undelete")
  (exit)
  (princ)
  )

alanjt

  • Needs a day job
  • Posts: 5352
  • Standby for witty remark...
Re: laydel "complex" from a layer list?
« Reply #1 on: June 15, 2011, 03:29:04 PM »
You could read-line through a text file and use (command "_.-laydel") to purge out each layer. That'd be the easiest way.
Civil 3D 2019 ~ Windohz 7 64bit
Dropbox

butzers09silverado

  • Guest
Re: laydel "complex" from a layer list?
« Reply #2 on: June 15, 2011, 03:32:35 PM »
So there is a way to link a lisp to a text file then... how hard would it be to modify one of those above that i already have to make it work?

alanjt

  • Needs a day job
  • Posts: 5352
  • Standby for witty remark...
Re: laydel "complex" from a layer list?
« Reply #3 on: June 15, 2011, 03:38:15 PM »
Quick freebie...

Code: [Select]
(defun c:NukeLayersFromList (/ file fopen layer lst)
  (if (setq file (getfiled "Select layer list file:" "" "txt" 2))
    (progn (setq fopen (open file "R"))
           (setvar 'CLAYER "0")
           (while (setq layer (read-line fopen))
             (if (and (not (member (strcase layer) '("0" "DEFPOINTS"))) (tblobjname "LAYER" layer))
               (setq lst (cons layer lst))
             )
           )
           (close fopen)
           (if lst
             (progn (command "_.-laydel")
                    (foreach layer lst (command "_name" layer))
                    (command "" "_yes")
             )
           )
    )
  )
  (princ)
)

Remember, LayDel is very useful, but it really does nuke a layer. If something exists in a block or style (you mentioned C3D) and it's on that layer, it will be no more and your style will not have a layer on which to place the defined object (I think it'll use layer 0 in it's stead).

Read a text file in the following format:

Quote
layer1
layer2
layer3
Civil 3D 2019 ~ Windohz 7 64bit
Dropbox

butzers09silverado

  • Guest
Re: laydel "complex" from a layer list?
« Reply #4 on: June 15, 2011, 03:59:47 PM »
Alan you are spot on, we WANT to blow it all out because:

We have a master template with all of our styles, layers, etc in 1 .dwt for civil 3d...  we want to open the template for say a grading drawing, and delete all the layers that are not pertinent to a grading drawing, so this is perfect except that i'm a noob programmer... landscape architect/hack programmer you get the idea.

any help would be good, the concept is to have the external txt file for the lisp to "lookup" so we can always update it without editing the "lisp".

cheers ;-)

mjfarrell

  • Seagull
  • Posts: 14444
  • Every Student their own Lesson
Re: laydel "complex" from a layer list?
« Reply #5 on: June 15, 2011, 04:07:53 PM »
Alan you are spot on, we WANT to blow it all out because:

We have a master template with all of our styles, layers, etc in 1 .dwt for civil 3d...  we want to open the template for say a grading drawing, and delete all the layers that are not pertinent to a grading drawing, so this is perfect except that i'm a noob programmer... landscape architect/hack programmer you get the idea.

any help would be good, the concept is to have the external txt file for the lisp to "lookup" so we can always update it without editing the "lisp".

cheers ;-)
why not simply purge the unused layers from the file?
Be your Best


Michael Farrell
http://primeservicesglobal.com/

butzers09silverado

  • Guest
Re: laydel "complex" from a layer list?
« Reply #6 on: June 15, 2011, 04:16:10 PM »
the layers "appear" unused when the civil 3d styles are actually using the styles.  civil 3d screws up purge.  this lisp is perfect I'll have to figure out what alan posted.  laydel actually works better because it doesn't care if there are blocks or c3d styles or anything using that layer, it just deletes it and you deal with the consequences... we know what those are and that is actually why we want to do this.

thanks for the responses this is great.

butzers09silverado

  • Guest
Re: laydel "complex" from a layer list?
« Reply #7 on: June 16, 2011, 07:26:03 AM »
THIS

IS

GENIUS  ^-^


walabash

  • Guest
Re: laydel "complex" from a layer list?
« Reply #8 on: June 21, 2011, 02:05:20 PM »
Alan, you're the man.  We ended up going with this to eliminate user input  :-D:

Code: [Select]
(defun c:create_z-corridor (/ file fopen layer lst)
  (if (setq file (findfile "S:\\Design\\CAD\\templates\\z-corridor.txt"))
    (progn (setq fopen (open file "R"))
           (setvar 'CLAYER "0")
           (while (setq layer (read-line fopen))
             (if (and (not (member (strcase layer) '("0" "DEFPOINTS"))) (tblobjname "LAYER" layer))
               (setq lst (cons layer lst))
             )
           )
           (close fopen)
           (if lst
             (progn (command "_.-laydel")
                    (foreach layer lst (command "_name" layer))
                    (command "" "_yes")
             )
           )
    )
  )
  (princ)
)

Now I am trying to get it either not to open the Text Window (F2) or to close it when it's done.  I've tried (graphscr), but it's not working.  I'm not really sure where to put it anyways.

alanjt

  • Needs a day job
  • Posts: 5352
  • Standby for witty remark...
Re: laydel "complex" from a layer list?
« Reply #9 on: June 21, 2011, 02:45:57 PM »
It shouldn't be opening the text screen (nothing there to do it), but perhaps whatever version you're in opens it when using the laydel command.

Try this...

Code: [Select]
(defun c:create_z-corridor (/ file fopen layer lst)
  (if (setq file (findfile "S:\\Design\\CAD\\templates\\z-corridor.txt"))
    (progn (setq fopen (open file "R"))
           (setvar 'CLAYER "0")
           (while (setq layer (read-line fopen))
             (if (and (not (member (strcase layer) '("0" "DEFPOINTS"))) (tblobjname "LAYER" layer))
               (setq lst (cons layer lst))
             )
           )
           (close fopen)
           (if lst
             (progn (command "_.-laydel")
                    (foreach layer lst (command "_name" layer))
                    (command "" "_yes")
             )
           )
           (graphscr)
    )
  )
  (princ)
)
Civil 3D 2019 ~ Windohz 7 64bit
Dropbox

butzers09silverado

  • Guest
Re: laydel "complex" from a layer list?
« Reply #10 on: July 06, 2011, 04:47:07 PM »
Wala figured out why we were getting the F2... it was because of block definitions being redefined when it deleted the layer out of the block... we're going to redefine the blocks so that the contents are on layer 0, should fix it.  :mrgreen: