Author Topic: Help: Search and report missing layers ,etc  (Read 1241 times)

0 Members and 1 Guest are viewing this topic.

PM

  • Guest
Help: Search and report missing layers ,etc
« on: October 15, 2022, 12:02:21 PM »
Hi.I am trying to write a lisp check my drawing layers and open notepad with the results

1) For missing layers (some times i need to have specific layer names in drawing)

2) For example in Layer2 ,layer3  i have only open and close polyline

3) For example in Layer4 ,layer5  i have only open polyline and text

4)  For example in Layer6 ,layer7  i have only open / close polyline and text

5)  For example in Layer8 ,layer9  i have only text

6)  For example in Layer10 ,layer11  i have only close polyline and text

7)  For example in  layer12  i have only close polyline and text. The text in this option must be something like this 061676604003 or 06167/EK/02237 but not 0616b76604003.
     12 charactes only mumbers or 5numbers/EK/5numbers. if the speling of the text is not correct write "One of the text is not correct"

I start the code searching for the layers and write the results in notepad. I don't know if is a faster way to write this and i don't know  how to continue in steps 2,3,4,5,6,7

Code - Auto/Visual Lisp: [Select]
  1. (defun c:test ()
  2.  (setq F (open (setq txt (strcat (getvar "TEMPPREFIX") "layersearch.txt")) "w"))
  3.         (write-line "Is no information for this layers:" F)
  4.   (if (=(tblsearch "layer" "0") nil)
  5.         (write-line "- 0" F)
  6.      );end if
  7.   (if (=(tblsearch "layer" "layer1") nil)
  8.         (write-line "- Layer1" F)
  9.      );end if
  10.   (if (=(tblsearch "layer" "layer2") nil)
  11.         (write-line "- Layer2" F)
  12.      );end if
  13.   (if (=(tblsearch "layer" "layer3") nil)
  14.         (write-line "- Layer3" F)
  15.      );end if
  16.   (if (=(tblsearch "layer" "layer4") nil)
  17.         (write-line "- Layer4" F)
  18.      );end if
  19.   (if (=(tblsearch "layer" "layer5") nil)
  20.         (write-line "- Layer5" F)
  21.      );end if
  22.   (if (=(tblsearch "layer" "layer6") nil)
  23.         (write-line "- Layer6" F)
  24.      );end if
  25.   (if (=(tblsearch "layer" "layer7") nil)
  26.         (write-line "- Layer7" F)
  27.      );end if
  28.   (if (=(tblsearch "layer" "layer8") nil)
  29.         (write-line "- Layer8" F)
  30.      );end if
  31.   (if (=(tblsearch "layer" "layer9") nil)
  32.         (write-line "- Layer9" F)
  33.      );end if
  34.   (if (=(tblsearch "layer" "layer10") nil)
  35.         (write-line "- Layer10" F)
  36.      );end if
  37.   (if (=(tblsearch "layer" "layer11") nil)
  38.         (write-line "- Layer11" F)
  39.      );end if
  40.   (if (=(tblsearch "layer" "layer12") nil)
  41.         (write-line "- Layer12" F)
  42.      );end if
  43.      (close F)
  44.      (startapp "NOTEPAD" txt)
  45. )
  46.  


Any ideas?

Thansk

« Last Edit: October 15, 2022, 01:47:35 PM by PM »

PM

  • Guest
Re: Help: Search and report missing layers ,etc
« Reply #1 on: October 15, 2022, 01:17:25 PM »
If It Is difficult, is not necessary to do all this with one lisp code. We can do it in 7 steps with 7 different lisp

PM

  • Guest
Re: Help: Search and report missing layers ,etc
« Reply #2 on: October 15, 2022, 01:35:21 PM »
i update the code in post1

mhupp

  • Bull Frog
  • Posts: 250
Re: Help: Search and report missing layers ,etc
« Reply #3 on: October 15, 2022, 03:15:25 PM »
List A - Layer names you want in your drawing
List B - Layer names in the drawing
Remove List B from List A
Whats left is the missing layer
Code - Auto/Visual Lisp: [Select]
  1. (defun c:test (/ lst Laylst x)
  2.   (setq lst '( "Layer" "Layer1" "Layer2" "Layer3" "Layer4" "Layer5" "Layer6" "Layer7" "Layer8" "Layer9" "Layer10" "Layer11" "Layer12"))
  3.     (setq laylst (cons (vla-get-name lyr) laylst))
  4.   )
  5.   (setq laylst (vl-sort laylst <))  ;sort to be in alphabetical order
  6.   (foreach x laylst
  7.     (setq lst (vl-remove x lst))
  8.   )
  9.   (if (>= (Length lst) 1)
  10.     (alert (strcat "Missing layers: \n" (lst->str lst "\n")))
  11.     (alert "All Layers Present in Drawing")
  12.   )
  13. )
  14. (defun lst->str ( lst del)
  15.   (if (cdr lst)
  16.     (strcat (car lst) del (lst->str (cdr lst) del))
  17.     (car lst)
  18.   )
  19. )


for 2 - 6 use two ssgets one for what your looking for
and one for just things on that layer if (sslength ss2) > (sslength ss1)
something is on that layer you don't want
(setq ss1 (ssget '((0 . "*POLYLINE") (8 . "Layer2"))))
(setq ss2 (ssget '((8 . "Layer2")))) 
with multiple checks  if (sslength ss3) > (+ (sslength ss1) (sslength ss2))
(setq ss1 (ssget '((0 . "*POLYLINE") (8 . "Layer4") (70 . 0)))
(setq ss2 (ssget '((0 . "TEXT") (8 . "Layer4"))))
(setq ss3 (ssget '((8 . "Layer4"))))
« Last Edit: October 15, 2022, 03:57:53 PM by mhupp »

PM

  • Guest
Re: Help: Search and report missing layers ,etc
« Reply #4 on: October 15, 2022, 03:33:24 PM »
Hi mhupp . Thanks for the post. I want analytic results like this in notepad like post1

      Is no information for this layers:
 
        - Layer1"
       - Layer2       
       - Layer3

Your code results is not analytic
    (alert "All Layers Present in Drawing")

I want analytic results because use the dxf of my drawing to upload  it in a platform and if something is missing or is not in the correct layer the dxf file will  not be accepted etc....

PM

  • Guest
Re: Help: Search and report missing layers ,etc
« Reply #5 on: October 15, 2022, 03:43:46 PM »
Sorry again.I test your code and gives me this error

Code: [Select]
; error: bad function: #<SUBR @0000020deef7faa8 <>

mhupp

  • Bull Frog
  • Posts: 250
Re: Help: Search and report missing layers ,etc
« Reply #6 on: October 15, 2022, 03:51:30 PM »
Fixed my code.

if you want to output to a notepad add the following

Code - Auto/Visual Lisp: [Select]
  1. (defun c:test ()
  2.   (setq F (open (setq txt (strcat (getvar "TEMPPREFIX") "layersearch.txt")) "w"))
  3.   (write-line "Information for this layers:" F)
  4.   (if (=(tblsearch "layer" "layer2")  
  5.     (progn  
  6.       (write-line "- Layer2" F)
  7.       (setq ss1 (ssget '((8 . "Layer2"))))  ;Selection set of anything on this layer
  8.       (setq ss2 (ssget '((0 . "*POLYLINE") (8 . "Layer2")))) ;selection set of only polylines on this layer
  9.       (if (> (sslength ss1) (sslength ss2))
  10.         (write-line "***EXTRA EINTIY'S***" F)
  11.         (write-line "- Polylines only" F)
  12.       )
  13.     )
  14.     (write-line "- Layer2 MISSING" F)
  15.   )
  16.   ;...
  17.   (close F)
  18. )


--edit
prodromosm is that you ?
« Last Edit: October 16, 2022, 04:15:08 AM by mhupp »

PM

  • Guest
Re: Help: Search and report missing layers ,etc
« Reply #7 on: October 17, 2022, 03:59:38 AM »
Hi mhupp.I want to add an in the code bellow :

1) When find close polyline in Layer1 wrire

Code: [Select]
            (write-line "- Layer1   (number of close polyline)  close polyline   ΟΚ" F)

2) Then when find open polyline

Code: [Select]
            (write-line "- Layer1   (number of open polyline)  open  polylines   ΟΚ" F)


3) Then when find text

Code: [Select]
            (write-line "- Layer1   (number of text)  text   ΟΚ" F)


Code: [Select]
      (if (tblsearch "layer" "layer1")
            (write-line "- Layer1      ΟΚ" F)
         );end if


Thanks

PM

  • Guest
Re: Help: Search and report missing layers ,etc
« Reply #8 on: October 17, 2022, 01:13:00 PM »
Hi mhupp. Can you help me to fix the code for this 3 layers?

Code - Auto/Visual Lisp: [Select]
  1.     (defun c:test ()
  2.   (setq F (open (setq txt (strcat (getvar "TEMPPREFIX") "layersearch.txt")) "w"))
  3.       (write-line "Information for this layers:" F)
  4.       (if (=(tblsearch "layer" "BOUND_IMPL" "BOUND_UNIMPL" "TOPO_PROP" "PST_KAEK")  
  5.         (progn  
  6.           (write-line "- Layer2" F)
  7.           (setq ss1 (ssget '((8 . "BOUND_IMPL,BOUND_UNIMPL,TOPO_PROP,PST_KAEK"))))  ;Selection set of anything on this layer
  8.           (setq ss2 (ssget '((0 . "*POLYLINE") (8 . "BOUND_IMPL,BOUND_UNIMPL,TOPO_PROP,PST_KAEK")))) ;selection set of only polylines on this layer
  9.           (if (> (sslength ss1) (sslength ss2))
  10.             (write-line "***EXTRA EINTIY'S***" F)
  11.             (write-line "- Polylines only" F)
  12.           )
  13.         )
  14.         (write-line "- Layer2 MISSING" F)
  15.       )
  16.       ;...
  17.       (close F)
  18.          (startapp "NOTEPAD" txt)
  19.          (princ)
  20.     )
  21.  

Thanks