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

0 Members and 1 Guest 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.