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

0 Members and 1 Guest are viewing this topic.

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