Author Topic: Help with find hatch lisp  (Read 4688 times)

0 Members and 2 Guests are viewing this topic.

PM

  • Guest
Help with find hatch lisp
« on: September 01, 2020, 10:09:54 AM »
Hi i am using this lisp code to find all hatch in model space and paper space and move them in to specific layer.

When i have no hatch in model space and paper space gives me a message "no Hatch " (works fine)

The problem is when i  have hatch only in model space or only in parer space gives me this message and stop dont work

Quote
Enter an option [?/Make/Set/New/Rename/ON/OFF/Color/Ltype/LWeight/TRansparency/MATerial/Plot/Freeze/Thaw/LOck/Unlock/stAte/Description/rEconcile/Xref]: HATCH
Invalid option keyword.
; error: Function cancelled

the code is

Code - Auto/Visual Lisp: [Select]
  1.     (defun c:DLHATCH (/ sel1 CLAYER )
  2. ;Switch from Layout Tab To Model Tab before stating LISP
  3.     (command "_.Tilemode" 1) ; To model space
  4.    (if  (setq sel1 (ssget "X" '((0 . "HATCH")))) ; SELECT ALL HATCH
  5.     (setq OLDLAYER (getvar "CLAYER")) ;GET CURRENT LAYER
  6.     (COMMAND "_layer" "_m" "HATCH" "_c" "171" "" "_lw" "0.18" "" "") ;CREATE NEW LAYER
  7.     (setvar "CLAYER" OLDLAYER) ; SET ACTIVE LAYER TO PREVIOUS
  8.     (command "CHPROP" sel1 "" ; CHANGE HATCH LAYER TO NEW LAYER
  9.     "LAYER" "HATCH"
  10.     "")
  11.    (command "_.Tilemode" 0) ;And back to last current layout
  12.  
  13.     (setq sel1 (ssget "X" '((0 . "HATCH")))) ; SELECT ALL HATCH
  14.     (setq OLDLAYER (getvar "CLAYER")) ;GET CURRENT LAYER
  15.     (COMMAND "_layer" "_m" "HATCH" "_c" "171" "" "_lw" "0.18" "" "") ;CREATE NEW LAYER
  16.     (setvar "CLAYER" OLDLAYER) ; SET ACTIVE LAYER TO PREVIOUS
  17.     (command "CHPROP" sel1 "" ; CHANGE HATCH LAYER TO NEW LAYER
  18.     "LAYER" "HATCH"
  19.     "")
  20. )
  21. (alert "no Hatch")
  22. )
  23. ;(alert "hatch done")
  24.     );END PROGRAM
  25.  
  26.  

Can any one fix it? Thanks

Tharwat

  • Swamp Rat
  • Posts: 710
  • Hypersensitive
Re: Help with find hatch lisp
« Reply #1 on: September 01, 2020, 11:13:22 AM »
Here you go.

Code - Auto/Visual Lisp: [Select]
  1. (defun c:test (/ s i e)
  2.   (or (tblsearch "LAYER" "HATCH")
  3.       (command "_layer" "_m" "HATCH" "_c" "171" "" "_lw" "0.18" "" "")
  4.   )
  5.   (if (setq s (ssget "_X" '((0 . "HATCH"))))
  6.     (repeat (setq i (sslength s))
  7.       (setq i (1- i)
  8.             e (entget (ssname s i))
  9.       )
  10.       (entmod (subst '(8 . "HATCH") (assoc 8 e) e))
  11.     )
  12.   )
  13.   (princ)
  14. )
  15.  

PM

  • Guest
Re: Help with find hatch lisp
« Reply #2 on: September 01, 2020, 04:38:24 PM »
Thank you Tharwat  :smitten:

Tharwat

  • Swamp Rat
  • Posts: 710
  • Hypersensitive
Re: Help with find hatch lisp
« Reply #3 on: September 02, 2020, 02:58:50 AM »
You're welcome anytime.

d2010

  • Bull Frog
  • Posts: 326
Re: Help with find hatch lisp
« Reply #4 on: September 02, 2020, 04:43:31 AM »
You're welcome anytime.

You see here version_pin15.lsp.  :blink:
Your enter PinCard of Bank insideLisp=3584..

Code - Auto/Visual Lisp: [Select]
  1. (defun dfn_ent_layernew(resetlayer picksetListorStr / $rr mpl tip sos $rr ii elf mli)
  2.    (setq;|a11472|;
  3.          tip (type resetlayer)
  4.          resetlayer (if (>  resetlayer "") (js_pin15 27723 (list  resetlayer T)) nil)) (setq;|a11542|;
  5.          $rr (if (>  picksetListorStr "") (js_pin15 57009 (list  "_X" (list (cons 0 picksetListorStr)))) picksetListorStr)) (if (and  $rr (not (js_pin15 19597 (list  "LAYER" resetlayer)))) (js_pin15 20576 (list  resetlayer 255 1 ""))) (if (and  $rr (js_pin15 19597 (list  "LAYER" resetlayer))) (progn  (progn (setq;|a11724|;
  6.          ii (- (js_pin15 16941 (list  $rr)) 1)) (while (>= ii 0) (setq;|a11770|;
  7.          elf (js_pin15 53906 (list  (ssname $rr ii)))
  8.          mli (js_pin15 19481 (list  (subst (cons 8 resetlayer) (assoc 8 elf) elf)))) (setq;|a11890|;
  9.          ii (- ii 1)))) (js_pin15 24576 (list  "okai")))) (princ)
  10. $rr)
  11.  
I compile yourRoutine:-> tothree types of VLisp    :oops:      (_native, _pin15.lsp, _ldc15).You test this programe with (dfn_ent_layernew (setq targeLayer "HATCH") "HATCH")) or Q2[enter]
Code: [Select]
(defun dfn_ent_layernew(resetlayer picksetListorStr / $rr mpl tip sos $rr ii elf mli)
   (setq;|a11476|;
tip (type resetlayer)
resetlayer (if (>  resetlayer "") (strcase resetlayer T) nil)) (setq;|a11546|;
$rr (if (>  picksetListorStr "") (ssget "_X" (list (cons 0 picksetListorStr))) picksetListorStr)) (if (and  $rr (not (tblsearch "LAYER" resetlayer))) (dfn_layer_new resetlayer 255 1 "")) (if (and  $rr (tblsearch "LAYER" resetlayer)) (progn  (progn (setq;|a11728|;
ii (- (sslength $rr) 1)) (while (>= ii 0) (setq;|a11774|;
elf (entget (ssname $rr ii))
mli (entmod (subst (cons 8 resetlayer) (assoc 8 elf) elf))) (setq;|a11894|;
ii (- ii 1)))) (alert "okai"))) (princ)
$rr)
You set "" for  random 0layer at CurrentLayer-Destinationa
Code - Text: [Select]
  1.   (setq CLD (Getstring "\nGive me Clear LayerDestination:"))
  2.  

You see the entities on LayerList bellow
 "0_mtext202008"
 "0_hatch202008*
 "0_line201007"
 "0_point"
Thankl you
« Last Edit: September 02, 2020, 08:17:27 AM by d2010 »

PM

  • Guest
Re: Help with find hatch lisp
« Reply #5 on: September 03, 2020, 10:58:06 AM »
Hi  Tharwat i want to ask somethn else. I have 3 layers include polylines an hatches
Code - Auto/Visual Lisp: [Select]
  1. (command "_layer" "_m" "test1" "_c" "103" "" "")
  2. (command "_layer" "_m" "test2" "_c" "90" "" "")
  3. (command "_layer" "_m" "test3" "_c" "10" "" "")
  4.  

is it possible the hatches in this 3 layer to go in 3 othes layers

Code - Auto/Visual Lisp: [Select]
  1. (command "_layer" "_m" "H1" "_c" "103"  "" "_lw" "0.18" "" "")
  2. (command "_layer" "_m" "H2" "_c" "90"  "" "_lw" "0.18" "" "")
  3. (command "_layer" "_m" "H3" "_c" "10" "" "_lw" "0.18" "" "")
  4.  

and all other hatch go to

Code - Auto/Visual Lisp: [Select]
  1.    (command "_layer" "_m" "HATCH" "_c" "171" "" "_lw" "0.18" "" "")
  2.  



Code - Auto/Visual Lisp: [Select]
  1.     (defun c:Test (/ s i e)
  2.    (command "_layer" "_m" "HATCH" "_c" "171" "" "_lw" "0.18" "" "")
  3.   (if (setq s (ssget "_X" '((0 . "HATCH"))))
  4.     (repeat (setq i (sslength s))
  5.       (setq i (1- i)
  6.             e (entget (ssname s i))
  7.       )
  8.       (entmod (subst '(8 . "HATCH") (assoc 8 e) e))
  9.     )
  10.   )
  11.   (princ)
  12. )
  13.  
  14.  

Thanks

Tharwat

  • Swamp Rat
  • Posts: 710
  • Hypersensitive
Re: Help with find hatch lisp
« Reply #6 on: September 03, 2020, 11:03:50 AM »
Hi PM,

Sorry i did not get your point so can you elaborate your idea a bit more?

PM

  • Guest
Re: Help with find hatch lisp
« Reply #7 on: September 03, 2020, 01:27:24 PM »
I have 3 spesific layers with polyline and hatch :
Code - Auto/Visual Lisp: [Select]
  1. (command "_layer" "_m" "test1" "_c" "103" "" "")
  2. (command "_layer" "_m" "test2" "_c" "90" "" "")
  3. (command "_layer" "_m" "test3" "_c" "10" "" "")
  4.  

I want the hatch from this 3 layers to go to this layers

Code - Auto/Visual Lisp: [Select]
  1.     (command "_layer" "_m" "H1" "_c" "103"  "" "_lw" "0.18" "" "")
  2.     (command "_layer" "_m" "H2" "_c" "90"  "" "_lw" "0.18" "" "")
  3.     (command "_layer" "_m" "H3" "_c" "10" "" "_lw" "0.18" "" "")
  4.      
  5.  

All the other hach in the drawing i want to go to this layer

Code - Auto/Visual Lisp: [Select]
  1. (command "_layer" "_m" "HATCH" "_c" "171" "" "_lw" "0.18" "" "")
  2.  

is this possible ?

thanks

Tharwat

  • Swamp Rat
  • Posts: 710
  • Hypersensitive
Re: Help with find hatch lisp
« Reply #8 on: September 03, 2020, 01:48:55 PM »
Something like this?
Code - Auto/Visual Lisp: [Select]
  1. (defun c:test (/ s i e y)
  2.   (if (setq s (ssget "_X" (list '(0 . "HATCH"))))
  3.     (repeat (setq i (sslength s))
  4.       (setq i (1- i)
  5.             e (entget (ssname s i))
  6.             y (assoc (cdr (assoc 8 e))
  7.                      '(("test1" "H1") ("test2" "H2") ("test3" "H3"))
  8.               )
  9.       )
  10.       (entmod (subst (cons 8
  11.                            (if y
  12.                              (cadr y)
  13.                              "HATCH"
  14.                            )
  15.                      )
  16.                      (assoc 8 e)
  17.                      e
  18.               )
  19.       )
  20.     )
  21.   )
  22.   (princ)
  23. )
  24.  

PM

  • Guest
Re: Help with find hatch lisp
« Reply #9 on: September 03, 2020, 04:47:21 PM »
Yes but i need to create this layers if does not exist

Code - Auto/Visual Lisp: [Select]
  1.     (command "_layer" "_m" "H1" "_c" "103"  "" "_lw" "0.18" "" "")
  2.     (command "_layer" "_m" "H2" "_c" "90"  "" "_lw" "0.18" "" "")
  3.     (command "_layer" "_m" "H3" "_c" "10" "" "_lw" "0.18" "" "")
  4.      
  5.  

Tharwat

  • Swamp Rat
  • Posts: 710
  • Hypersensitive
Re: Help with find hatch lisp
« Reply #10 on: September 03, 2020, 04:52:28 PM »
You can just add them in the program at the top and that's enough although the program would create them if they are not existed but with default values.

PM

  • Guest
Re: Help with find hatch lisp
« Reply #11 on: September 03, 2020, 05:00:51 PM »
Yes but if i will write it like this will create this 3 layes every time .But some times i will not need  3 layers i will need 1 or 2 of them? Is any way to filter and create the layer if it is necessary ?

Code - Auto/Visual Lisp: [Select]
  1.     (defun c:test (/ s i e y)
  2.  (command "_layer" "_m" "H1" "_c" "103"  "" "_lw" "0.18" "" "")
  3.     (command "_layer" "_m" "H2" "_c" "90"  "" "_lw" "0.18" "" "")
  4.     (command "_layer" "_m" "H3" "_c" "10" "" "_lw" "0.18" "" "")
  5.  (command "_layer" "_m" "HATCH" "_c" "171" "" "_lw" "0.18" "" "")
  6.       (if (setq s (ssget "_X" (list '(0 . "HATCH"))))
  7.         (repeat (setq i (sslength s))
  8.           (setq i (1- i)
  9.                 e (entget (ssname s i))
  10.                 y (assoc (cdr (assoc 8 e))
  11.                          '(("test1" "H1") ("test2" "H2") ("test3" "H3"))
  12.                   )
  13.           )
  14.           (entmod (subst (cons 8
  15.                                (if y
  16.                                  (cadr y)
  17.                                  "HATCH"
  18.                                )
  19.                          )
  20.                          (assoc 8 e)
  21.                          e
  22.                   )
  23.           )
  24.         )
  25.       )
  26.       (princ)
  27.     )
  28.      
  29.  
  30.  

Thanks

PM

  • Guest
Re: Help with find hatch lisp
« Reply #12 on: September 03, 2020, 05:11:35 PM »
i find that the code dont work well.Create the layers but all the hach go to layer

my mistake. I write the names of layers wrong. But creates Unnecessary layers like i said in the previous post
« Last Edit: September 03, 2020, 05:17:49 PM by PM »

Tharwat

  • Swamp Rat
  • Posts: 710
  • Hypersensitive
Re: Help with find hatch lisp
« Reply #13 on: September 03, 2020, 05:12:45 PM »
Code - Auto/Visual Lisp: [Select]
  1. (defun c:test (/ s i e y l)
  2.   (if (setq s (ssget "_X" (list '(0 . "HATCH"))))
  3.     (repeat (setq i (sslength s))
  4.       (setq i (1- i)
  5.             e (entget (ssname s i))
  6.             y (assoc (cdr (assoc 8 e))
  7.                      '(("test1" "H1" 103)
  8.                        ("test2" "H2" 90 0.18)
  9.                        ("test3" "H3" 10)
  10.                       )
  11.               )
  12.       )
  13.       (and y
  14.            (or (tblsearch "LAYER" (setq l (cadr y)))
  15.                (Layer_ l (caddr y))
  16.            )
  17.       )
  18.       (entmod (subst (cons 8
  19.                            (if y
  20.                              l
  21.                              "HATCH"
  22.                            )
  23.                      )
  24.                      (assoc 8 e)
  25.                      e
  26.               )
  27.       )
  28.     )
  29.   )
  30.   (princ)
  31. )
  32. (defun Layer_ (lay clr)
  33.   (entmake (list '(0 . "LAYER")
  34.                  '(100 . "AcDbSymbolTableRecord")
  35.                  '(100 . "AcDbLayerTableRecord")
  36.                  (cons 2 lay)
  37.                  (cons 62 clr)
  38.                  '(370 . 18)
  39.                  '(70 . 0)
  40.            )
  41.   )
  42. )

PM

  • Guest
Re: Help with find hatch lisp
« Reply #14 on: September 03, 2020, 05:27:10 PM »
the code works but the HATCH layer is not
Code - Auto/Visual Lisp: [Select]
  1.  (command "_layer" "_m" "HATCH" "_c" "171" "" "_lw" "0.18" "" "")
  2.  

Tharwat

  • Swamp Rat
  • Posts: 710
  • Hypersensitive
Re: Help with find hatch lisp
« Reply #15 on: September 03, 2020, 05:30:44 PM »
the code works but the HATCH layer is not
Code - Auto/Visual Lisp: [Select]
  1.  (command "_layer" "_m" "HATCH" "_c" "171" "" "_lw" "0.18" "" "")
  2.  
Yes, because the codes for this layer name was added into the first posted codes but anyway here you go.
Code - Auto/Visual Lisp: [Select]
  1. (defun c:test (/ s i e y l)
  2.   (or (tblsearch "LAYER" "HATCH")
  3.       (Layer_ "HATCH" 171)
  4.   )
  5.   (if (setq s (ssget "_X" (list '(0 . "HATCH"))))
  6.     (repeat (setq i (sslength s))
  7.       (setq i (1- i)
  8.             e (entget (ssname s i))
  9.             y (assoc (cdr (assoc 8 e))
  10.                      '(("test1" "H1" 103)
  11.                        ("test2" "H2" 90 0.18)
  12.                        ("test3" "H3" 10)
  13.                       )
  14.               )
  15.       )
  16.       (and y
  17.            (or (tblsearch "LAYER" (setq l (cadr y)))
  18.                (Layer_ l (caddr y))
  19.            )
  20.       )
  21.       (entmod (subst (cons 8
  22.                            (if y
  23.                              l
  24.                              "HATCH"
  25.                            )
  26.                      )
  27.                      (assoc 8 e)
  28.                      e
  29.               )
  30.       )
  31.     )
  32.   )
  33.   (princ)
  34. )
  35. (defun Layer_ (lay clr)
  36.   (entmake (list '(0 . "LAYER")
  37.                  '(100 . "AcDbSymbolTableRecord")
  38.                  '(100 . "AcDbLayerTableRecord")
  39.                  (cons 2 lay)
  40.                  (cons 62 clr)
  41.                  '(370 . 18)
  42.                  '(70 . 0)
  43.            )
  44.   )
  45. )
  46.  

PM

  • Guest
Re: Help with find hatch lisp
« Reply #16 on: September 03, 2020, 06:01:03 PM »
Ok now work.

Thanks Tharwat
« Last Edit: September 03, 2020, 06:25:46 PM by PM »

PM

  • Guest
Re: Help with find hatch lisp
« Reply #17 on: September 04, 2020, 01:59:55 AM »
Ηι Tharwat. I want to ask something else about layers thats way i didnt  change post.

I am using a simple command  for purge ,audit and overkill. The problem is i have sone spesific layers with close polylines the most of the times are overlap and i want  them. If i use the overkill command i loose parts of them

If i wright the code like bellow  the  code search to find the same time in the drawing all this layers TEST1,TEST2,TEST3,TEST4,TEST5,TEST6.

I want not to find all of them just one of them (TEST1 or TEST2 or TEST3 or TEST4 or TEST5 or TEST6), because in the drawing i will have one or two or thee of them etc.

The question is how to filter if find one or more of this 6 layers then

 (COMMAND "-PURGE" "A" "*" "N"  "_AUDIT" "Y" "" "")

unless

(COMMAND "-PURGE" "A" "*" "N"  "_AUDIT" "Y" "-overkill" "all" "" "")


Code - Auto/Visual Lisp: [Select]
  1. (defun c:test ()
  2.  
  3. (if (not (tblsearch "LAYER" "TEST1" "TEST2" "TEST3" "TEST4" "TEST5" "TEST6"))
  4. (COMMAND "-PURGE" "A" "*" "N"  "_AUDIT" "Y" "-overkill" "all" "" ""))
  5. (or
  6.  (COMMAND "-PURGE" "A" "*" "N"  "_AUDIT" "Y" "" "")
  7. )
  8. )
  9.  
  10.  


Dlanor

  • Bull Frog
  • Posts: 263
Re: Help with find hatch lisp
« Reply #18 on: September 04, 2020, 07:03:46 AM »
IIRC you can't select anything on locked layers in the overkill command, therefore if you lock the layers you don't want altering overkill shouldn't touch them.

PM

  • Guest
Re: Help with find hatch lisp
« Reply #19 on: September 04, 2020, 07:12:54 AM »
hi Dianor .I want to learn how i can do this

Code - Auto/Visual Lisp: [Select]
  1. want not to find all of them just one of them (TEST1 or TEST2 or TEST3 or TEST4 or TEST5 or TEST6)
  2.  

it will be usefull .


Quote
IIRC you can't select anything on locked layers in the overkill command, therefore if you lock the layers you don't want altering overkill shouldn't touch them.


What is IIRC, there is no IIRC command in Autocad 2020 ???

Thanks

PM

  • Guest
Re: Help with find hatch lisp
« Reply #20 on: September 04, 2020, 07:35:47 AM »
Code - Auto/Visual Lisp: [Select]
  1. (if (not (tblsearch "LAYER" "test1" "test2"))
  2.  

I try again this and now work . But if i do this not working.

Code - Auto/Visual Lisp: [Select]
  1. (if (not (tblsearch "LAYER" "test1" "test2" "test3"))
  2.  

I dont know. Please help

Thanks
« Last Edit: September 04, 2020, 07:39:44 AM by PM »

Tharwat

  • Swamp Rat
  • Posts: 710
  • Hypersensitive
Re: Help with find hatch lisp
« Reply #21 on: September 04, 2020, 08:08:01 AM »
You can't check if many layer names are existed in a drawing at the same time with tblsearch function so you can check only once per one,  but if you want to check for a list of layer names then you can use any of the iteration functions like, foreach, mapcar .. etc.

eg:
Code - Auto/Visual Lisp: [Select]
  1. (foreach lay '("test1"  "test2"  "test3")
  2.   (if (tblsearch "LAYER" lay) ;; variable 'lay' represents the layer name in the above list. eg: "test1" then next, next ...
  3.      ;; do your stuff here if layer found ....
  4.    )
  5. )

Just go back to any of my posted codes in this thread for more info.

Dlanor

  • Bull Frog
  • Posts: 263
Re: Help with find hatch lisp
« Reply #22 on: September 04, 2020, 08:30:29 AM »
What is IIRC, there is no IIRC command in Autocad 2020 ???
Thanks

It's not a command. It is an abbreviated form of the phrase "If I Recall Correctly" Like "LOL" = Lots Of Laughs

PM

  • Guest
Re: Help with find hatch lisp
« Reply #23 on: September 04, 2020, 09:42:18 AM »
Hi Tharwat ,can you show me an example ?

JohnK

  • Administrator
  • Seagull
  • Posts: 10648
Re: Help with find hatch lisp
« Reply #24 on: September 04, 2020, 09:55:13 AM »
Jumping in the middle of the conversation...

You can always do something like the following:
Code - Auto/Visual Lisp: [Select]
  1. (defun Layer-p (l)
  2.   ;; return boole for layer existence
  3.    (and (tblsearch "LAYER" l)) )
  4.  
  5. (mapcar '(lambda ( x ) (Layer-p x)) '("test1"  "test2"  "test3"))
TheSwamp.org (serving the CAD community since 2003)
Member location map - Add yourself

Donate to TheSwamp.org

PM

  • Guest
Re: Help with find hatch lisp
« Reply #25 on: September 04, 2020, 10:11:05 AM »
I try this but

Quote
; error: bad argument type: stringp nil


Code - Auto/Visual Lisp: [Select]
  1. (defun c:test ()
  2. (if (not (tblsearch "LAYER" l))
  3. (mapcar '(lambda ( x ) (Layer-p x)) '("test1"  "test2"  "test3"))
  4. (COMMAND "-PURGE" "A" "*" "N"  "_AUDIT" "Y" "-overkill" "all" "" "")
  5. )
  6. (or
  7. (COMMAND "-PURGE" "A" "*" "N"  "_AUDIT" "Y" "" "")
  8.     )
  9.  (princ)
  10.    )    
  11.  

JohnK

  • Administrator
  • Seagull
  • Posts: 10648
Re: Help with find hatch lisp
« Reply #26 on: September 04, 2020, 10:15:44 AM »
You get that error because there is very little correct about the code you have. I will read the thread and see if I can help.

I try this but

Quote
; error: bad argument type: stringp nil


Code - Auto/Visual Lisp: [Select]
  1. (defun c:test ()
  2. (if (not (tblsearch "LAYER" l))
  3. (mapcar '(lambda ( x ) (Layer-p x)) '("test1"  "test2"  "test3"))
  4. (COMMAND "-PURGE" "A" "*" "N"  "_AUDIT" "Y" "-overkill" "all" "" "")
  5. )
  6. (or
  7. (COMMAND "-PURGE" "A" "*" "N"  "_AUDIT" "Y" "" "")
  8.     )
  9.  (princ)
  10.    )    
  11.  
TheSwamp.org (serving the CAD community since 2003)
Member location map - Add yourself

Donate to TheSwamp.org

PM

  • Guest
Re: Help with find hatch lisp
« Reply #27 on: September 04, 2020, 10:31:42 AM »
 :idea: :idea: :idea: :idea: :idea: :idea: :idea: :idea:

JohnK

  • Administrator
  • Seagull
  • Posts: 10648
Re: Help with find hatch lisp
« Reply #28 on: September 04, 2020, 10:50:13 AM »
So if I understand you would like to run either one operation if one of those layers is found in the drawing and another operation if not. Correct?

You can run the layer check, build a list of the results, and check those results for for a true value. If one of the test come back true then you can run an operation otherwise run another.

Building a list of results and checking that list--vs iterating and checking as you go--is more efficient in times that you find yourself crunching a lot of data (like points, blocks, etc) so it is a good habit to get into.

Code - Auto/Visual Lisp: [Select]
  1. (defun Layer-p (l)
  2.   ;; return boole for layer existence
  3.    (and (tblsearch "LAYER" l)) )
  4.  
  5. (if (member 't
  6.         (mapcar
  7.                 '(lambda ( x ) (Layer-p x))
  8.                 '("test1"  "test2"  "test3")))
  9.  (COMMAND "-PURGE" "A" "*" "N"  "_AUDIT" "Y" "" "")
  10.  (COMMAND "-PURGE" "A" "*" "N"  "_AUDIT" "Y" "-overkill" "all" "" "")
  11. )

And you can restructure the code if this is a bit more readable for you.
Code - Auto/Visual Lisp: [Select]
  1. (defun Layer-p (l)
  2.   ;; return boole for layer existence
  3.    (and (tblsearch "LAYER" l)) )
  4.  
  5. (setq results (mapcar
  6.                 '(lambda ( x ) (Layer-p x))
  7.                 '("test1"  "test2"  "test3"))
  8.  
  9. (if (member 't results)
  10.  (COMMAND "-PURGE" "A" "*" "N"  "_AUDIT" "Y" "" "")
  11.  (COMMAND "-PURGE" "A" "*" "N"  "_AUDIT" "Y" "-overkill" "all" "" "")
  12. )

And you would build a function of all of that like this:
Code - Auto/Visual Lisp: [Select]
  1. (defun c:test ( / Layer-p results )
  2.         (defun Layer-p (l)
  3.          ;; return boole for layer existence
  4.          (and (tblsearch "LAYER" l)) )
  5.  
  6.    (setq results (mapcar
  7.                   '(lambda ( x ) (Layer-p x))
  8.                   '("test1"  "test2"  "test3")))
  9.  
  10.    (if (member 't results)
  11.     (COMMAND "-PURGE" "A" "*" "N"  "_AUDIT" "Y" "" "")
  12.     (COMMAND "-PURGE" "A" "*" "N"  "_AUDIT" "Y" "-overkill" "all" "" "")
  13.    )
  14. )
  15.  
« Last Edit: September 04, 2020, 10:53:53 AM by John Kaul (Se7en) »
TheSwamp.org (serving the CAD community since 2003)
Member location map - Add yourself

Donate to TheSwamp.org

PM

  • Guest
Re: Help with find hatch lisp
« Reply #29 on: September 04, 2020, 11:43:57 AM »
thank you John Kaul (Se7en). i think i understand  the  code .I add some comments ,if i am wrong correct me

Code - Auto/Visual Lisp: [Select]
  1. (defun c:test ( / Layer-p results )
  2.         (defun Layer-p (l)
  3.          ;; return boole for layer existence
  4.          (and (tblsearch "LAYER" l)) )
  5.  
  6.    (setq results (mapcar
  7.                   '(lambda ( x ) (Layer-p x))
  8.                   '("test1"  "test2"  "test3"))) ; here search for existing layers
  9.  
  10.    (if (member 't results)
  11.     (COMMAND "-PURGE" "A" "*" "N"  "_AUDIT" "Y" "" "") ; if find  one or some  of them execute this command
  12.     (COMMAND "-PURGE" "A" "*" "N"  "_AUDIT" "Y" "-overkill" "all" "" "") ; unless execute this command
  13.    )
  14. )
  15.  
  16.  

JohnK

  • Administrator
  • Seagull
  • Posts: 10648
Re: Help with find hatch lisp
« Reply #30 on: September 04, 2020, 11:49:57 AM »
You are correct.

No problem. Glad I could help.
TheSwamp.org (serving the CAD community since 2003)
Member location map - Add yourself

Donate to TheSwamp.org