Jump to content
Pugazh

Change all hatch to a particular layer using accoreconsole

Recommended Posts

Pugazh

Hello,

 

 Change all hatch (including nested block) to a particular layer using accoreconsole it's possible? please help me!

 

Regards,

Pugazh

Share this post


Link to post
Share on other sites
rlx

try to feed something like this to your console :


(defun c:t1 ( / b l e d )
  (if (not (tblsearch "layer" "rlx"))(command "-layer" "new" "rlx" ""))
  (while (setq b (cdadr (tblnext "block" (not b))))(setq l (cons b l)))
  (foreach b l
    (setq e (tblobjname "block" b))
    (while (setq e (entnext e))
      (if (= (cdr (assoc 0 (setq d (entget e)))) "HATCH")
    (progn (setq d (subst (cons 8 "rlx") (assoc 8 d) d))(entmod d))))
  )
  (command "_.regen")
  (princ)
)

 

  • Thanks 1

Share this post


Link to post
Share on other sites
Pugazh

Hello rlx,

 Thanks for the reply rlx & Nice Code :).

 Yeah it's working fine in nested block hatch. Could please update code for all hatch need change layer (outside of block hatch also).

 

Share this post


Link to post
Share on other sites
rlx


(defun c:t2 ( / b l e d i s)
  (if (not (tblsearch "layer" "rlx"))(command "-layer" "new" "rlx" ""))
  (while (setq b (cdadr (tblnext "block" (not b))))(setq l (cons b l)))
  (foreach b l
    (setq e (tblobjname "block" b))
    (while (setq e (entnext e))
      (if (= (cdr (assoc 0 (setq d (entget e)))) "HATCH")
    (progn (setq d (subst (cons 8 "rlx") (assoc 8 d) d))(entmod d))))
  )
  (if (setq s (ssget "x" '((0 . "HATCH"))))
    (repeat (setq i (sslength s)) (setq d (entget (ssname s (setq i (1- i)))))
      (entmod (setq d (subst (cons 8 "rlx") (assoc 8 d) d)))))
  (command "_.regen")
  (princ)
)

  • Thanks 1

Share this post


Link to post
Share on other sites
Pugazh

Wow!! Working fine!! Great!! 

Thanks for sparing your valuable time rlx...👏 

Share this post


Link to post
Share on other sites
rlx
5 minutes ago, Pugazh said:

Wow!! Working fine!! Great!! 

Thanks for sparing your valuable time rlx...👏 

 

you're welcome 😓

  • Like 1

Share this post


Link to post
Share on other sites
Tharwat

Hi @rlx

A few info if you don't mind of course. :)

cons function can create the layer name "rlx" if its not already existed in the drawing file that included in the pair list as this => (cons 8 "rlx") 

You can shorten the program via removing the progn function and add the entmod right before the subst function like this: (entmod (subst .... etc

  • Like 1

Share this post


Link to post
Share on other sites
rlx
5 hours ago, Tharwat said:

Hi @rlx

A few info if you don't mind of course. :)

cons function can create the layer name "rlx" if its not already existed in the drawing file that included in the pair list as this => (cons 8 "rlx") 

You can shorten the program via removing the progn function and add the entmod right before the subst function like this: (entmod (subst .... etc

Of course I don't mind Tharwat. Didn't know (or just forgot...Altzheimer or something haha) about the cons 8 but good to know.

Funny you mention the entmod. First I had coded it like you said but decided to split it for both clarity and I remembered I had a situation where I had nested too much code and it didn't work any more but not sure if it was vanilla or vla(x) anyways , after splitting it worked again. And else its never really a bad thing to split your code if only for debugging purposes. Now and again some of the mapcar(ish) constructions are a pain to debug because the vlide editor refusus to put a breakpoint where I want it. But if anything, thanx for the advise (hope I don't forget it)

:beer:

Edited by rlx

Share this post


Link to post
Share on other sites
Pugazh
17 hours ago, rlx said:

 


(defun c:t2 ( / b l e d i s)
  (if (not (tblsearch "layer" "rlx"))(command "-layer" "new" "rlx" ""))
  (while (setq b (cdadr (tblnext "block" (not b))))(setq l (cons b l)))
  (foreach b l
    (setq e (tblobjname "block" b))
    (while (setq e (entnext e))
      (if (= (cdr (assoc 0 (setq d (entget e)))) "HATCH")
    (progn (setq d (subst (cons 8 "rlx") (assoc 8 d) d))(entmod d))))
  )
  (if (setq s (ssget "x" '((0 . "HATCH"))))
    (repeat (setq i (sslength s)) (setq d (entget (ssname s (setq i (1- i)))))
      (entmod (setq d (subst (cons 8 "rlx") (assoc 8 d) d)))))
  (command "_.regen")
  (princ)
)

 

 

Hello @rlx

  How to add (cons 62 256) in this code.

 

Share this post


Link to post
Share on other sites
rlx

(defun c:t5 ( / b l e d i s)
  (while (setq b (cdadr (tblnext "block" (not b))))(setq l (cons b l)))
  (foreach b l (setq e (tblobjname "block" b))
    (while (setq e (entnext e))(if (= (cdr (assoc 0 (setq d (entget e)))) "HATCH")(entmod (append (subst (cons 8 "rlx") (assoc 8 d) d) '((62 . 256)))))))
  (if (setq s (ssget "x" '((0 . "HATCH"))))
    (repeat (setq i (sslength s))(entmod (append (subst (cons 8 "rlx") (assoc 8 (setq d (entget (ssname s (setq i (1- i)))))) d) '((62 . 256))))))
  (command "_.regen")
  (princ)
)

  • Thanks 1

Share this post


Link to post
Share on other sites
Pugazh
Just now, rlx said:

 


(defun c:t5 ( / b l e d i s)
  (while (setq b (cdadr (tblnext "block" (not b))))(setq l (cons b l)))
  (foreach b l (setq e (tblobjname "block" b))
    (while (setq e (entnext e))(if (= (cdr (assoc 0 (setq d (entget e)))) "HATCH")(entmod (append (subst (cons 8 "rlx") (assoc 8 d) d) '((62 . 256)))))))
  (if (setq s (ssget "x" '((0 . "HATCH"))))
    (repeat (setq i (sslength s))(entmod (append (subst (cons 8 "rlx") (assoc 8 (setq d (entget (ssname s (setq i (1- i)))))) d) '((62 . 256))))))
  (command "_.regen")
  (princ)
)

Perfect!! Thank you @rlx :) :beer:

 

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×