Author Topic: Change layer of all the blocks in the drawing to the layer of block.  (Read 6617 times)

0 Members and 1 Guest are viewing this topic.

pedroantonio

  • Guest
Hi. I am searching for a lisp,

 to change layer of all the blocks in the drawing to the layer of block.


Tharwat

  • Swamp Rat
  • Posts: 710
  • Hypersensitive
Re: Change layer of all the blocks in the drawing to the layer of block.
« Reply #1 on: December 01, 2013, 01:16:50 PM »
Hi

Does it mean that you want to change the layer of the objects in all blocks to the layer which each block lay on ?

More information is needed .

pedroantonio

  • Guest
Re: Change layer of all the blocks in the drawing to the layer of block.
« Reply #2 on: December 01, 2013, 06:08:00 PM »
For example, I've entered in a drawing 50 blocks. Each block has its own layer. But all the Blocks inserd in layer 0. I need a lisp to
put all blocks  in the drawing to the layer of eatch block .

CAB

  • Global Moderator
  • Seagull
  • Posts: 10401
Re: Change layer of all the blocks in the drawing to the layer of block.
« Reply #3 on: December 01, 2013, 11:44:59 PM »
What defines the layer for each block?
I've reached the age where the happy hour is a nap. (°¿°)
Windows 10 core i7 4790k 4Ghz 32GB GTX 970
Please support this web site.

pedroantonio

  • Guest
Re: Change layer of all the blocks in the drawing to the layer of block.
« Reply #4 on: December 02, 2013, 02:36:43 AM »
Look the example.dwg

Tharwat

  • Swamp Rat
  • Posts: 710
  • Hypersensitive
Re: Change layer of all the blocks in the drawing to the layer of block.
« Reply #5 on: December 02, 2013, 05:45:16 AM »
Although that it is mixed up with vla but it is cool  :-D

Code - Auto/Visual Lisp: [Select]
  1. (defun c:Test (/ *error* l1 l2 s lst i e x en)
  2.   ;; Tharwat 02.12.2013 ;;
  3.   (or doc
  4.   )
  5.   (defun *error* (u)
  6.     (if lst
  7.       (mapcar '(lambda (u) (vla-put-lock u :vlax-true)) lst)
  8.     )
  9.     (princ "\*Cancel*")
  10.   )
  11.   (setq l1 "Point_dot"
  12.         l2 "Station_dot"
  13.   )
  14.   (if (and (if (tblsearch "LAYER" l1)
  15.              t
  16.              (progn
  17.                (alert (strcat "Layer < " l1 " > is not found !!"))
  18.                nil
  19.              )
  20.            )
  21.            (if (tblsearch "LAYER" l2)
  22.              t
  23.              (progn
  24.                (alert (strcat "Layer < " l2 " > is not found !!"))
  25.                nil
  26.              )
  27.            )
  28.            (setq s (ssget "_X"
  29.                           '((0 . "INSERT") (66 . 1) (2 . "station,point"))
  30.                    )
  31.            )
  32.       )
  33.     (progn
  34.       (vlax-for layer (vla-get-layers doc)
  35.         (if (eq :vlax-true (vla-get-lock layer))
  36.           (vla-put-lock (car (setq lst (cons layer lst))) :vlax-false)
  37.         )
  38.       )
  39.       (vla-StartUndoMark doc)
  40.       (repeat (setq i (sslength s))
  41.         (setq e (entget (setq x (ssname s (setq i (1- i))))))
  42.         (entmod (subst (cons 8
  43.                              (if (eq (cdr (assoc 2 e)) "point")
  44.                                l1
  45.                                l2
  46.                              )
  47.                        )
  48.                        (assoc 8 e)
  49.                        e
  50.                 )
  51.         )
  52.       )
  53.       (vla-EndUndoMark doc)
  54.       (if lst
  55.         (mapcar '(lambda (u) (vla-put-lock u :vlax-true)) lst)
  56.       )
  57.       (vla-regen doc AcAllViewports)
  58.     )
  59.   )
  60.   (princ)
  61. )
  62.  
« Last Edit: December 02, 2013, 02:14:52 PM by Tharwat »

pedroantonio

  • Guest
Re: Change layer of all the blocks in the drawing to the layer of block.
« Reply #6 on: December 02, 2013, 10:34:32 AM »
thank you Mr Tharwat for the code but i think that you don't understand exactly my questien.

i want not to change all the attribiuts layers, but to move all blocks to there current layer.For example when i pick the point block not to be in 0 layer but in point_dot layer, when i pick Station block not to be in 0 layer but in Station _dot layer.

Tharwat

  • Swamp Rat
  • Posts: 710
  • Hypersensitive
Re: Change layer of all the blocks in the drawing to the layer of block.
« Reply #7 on: December 02, 2013, 12:30:27 PM »
Hi

So finally , does it mean that you want to put the point in the attributed block to layer Point_dot and the attributed texts to Station_dot ?

pedroantonio

  • Guest
Re: Change layer of all the blocks in the drawing to the layer of block.
« Reply #8 on: December 02, 2013, 12:35:46 PM »
yes

Tharwat

  • Swamp Rat
  • Posts: 710
  • Hypersensitive
Re: Change layer of all the blocks in the drawing to the layer of block.
« Reply #9 on: December 02, 2013, 12:54:32 PM »
I updated the previous code , so can you try it and let me know ?

pedroantonio

  • Guest
Re: Change layer of all the blocks in the drawing to the layer of block.
« Reply #10 on: December 02, 2013, 01:03:30 PM »
No. look example 2.dwg .I need the inside layer to work. my english is bad.Please try to understand


Tharwat

  • Swamp Rat
  • Posts: 710
  • Hypersensitive
Re: Change layer of all the blocks in the drawing to the layer of block.
« Reply #11 on: December 02, 2013, 02:15:54 PM »
Codes Updated again  8-)

pedroantonio

  • Guest
Re: Change layer of all the blocks in the drawing to the layer of block.
« Reply #12 on: December 02, 2013, 04:40:20 PM »
Thank you Tharwat .This  is exactly what I am looking for

pedroantonio

  • Guest
Re: Change layer of all the blocks in the drawing to the layer of block.
« Reply #13 on: December 02, 2013, 05:08:29 PM »
i try to add more block in this lisp,and i change the nome of the blocks and i have some error, But i canot understand why?

Code: [Select]
(defun c:Test (/ *error* l1 l2 l3 l4 l5 l6 l7 s lst i e x en)
  ;; Tharwat 02.12.2013 ;;
  (or doc
      (setq doc (vla-get-activedocument (vlax-get-acad-object)))
  )
  (defun *error* (u)
    (if lst
      (mapcar '(lambda (u) (vla-put-lock u :vlax-true)) lst)
    )
    (princ "\*Cancel*")
  )
  (setq l1 "point"
l2 "station"
l3 "trigonom"
l4 "REPERS"
l5 "koryfes"
l6 "kokaek"
l7 "korot"
  )
  (if
    (and
      (if (tblsearch "LAYER" l1)
t
(progn
  (alert (strcat "Layer < " l1 " > is not found !!"))
  nil
)
      )
      (if (tblsearch "LAYER" l2)
t
(progn
  (alert (strcat "Layer < " l2 " > is not found !!"))
  nil
)
(if (tblsearch "LAYER" l3)
  t
  (progn
    (alert (strcat "Layer < " l3 " > is not found !!"))
    nil
  )
  (if (tblsearch "LAYER" l4)
    t
    (progn
      (alert (strcat "Layer < " l4 " > is not found !!"))
      nil
    )
    (if (tblsearch "LAYER" l5)
      t
      (progn
(alert (strcat "Layer < " l5 " > is not found !!"))
nil
      )
      (if (tblsearch "LAYER" l6)
t
(progn
  (alert (strcat "Layer < " l6 " > is not found !!"))
  nil
)
(if (tblsearch "LAYER" l7)
  t
  (progn
    (alert (strcat "Layer < " l7 " > is not found !!"))
    nil
  )
)
(setq s
       (ssget
"_X"
'((0 . "INSERT")
   (66 . 1)
   (2
    .
    "station,point,trigonom,repers,koryfes,kokaek,korot"
   )
  )
       )
)
      )
      (progn
(vlax-for layer (vla-get-layers doc)
  (if (eq :vlax-true (vla-get-lock layer))
    (vla-put-lock
      (car (setq lst (cons layer lst)))
      :vlax-false
    )
  )
)
(vla-StartUndoMark doc)
(repeat (setq i (sslength s))
  (setq e (entget (setq x (ssname s (setq i (1- i))))))
  (entmod
    (subst (cons 8
(if (eq (cdr (assoc 2 e)) "point")
   l1
   l2
   l3
   l4
   l5
   l6
   l7
)
   )
   (assoc 8 e)
   e
    )
  )
)
(vla-EndUndoMark doc)
(if lst
  (mapcar '(lambda (u) (vla-put-lock u :vlax-true)) lst)
)
(vla-regen doc AcAllViewports)
      )
    )
    (princ)
  )
  (vl-load-com)
)
      )
    )
  )
)

Tharwat

  • Swamp Rat
  • Posts: 710
  • Hypersensitive
Re: Change layer of all the blocks in the drawing to the layer of block.
« Reply #14 on: December 03, 2013, 12:58:39 AM »
Try this .

Code - Auto/Visual Lisp: [Select]
  1. (defun c:Test (/ *error* l lst lk s i e en ln)
  2.   ;; Tharwat 03.12.2013 ;;
  3.   (defun *error* (u)
  4.     (if lk
  5.       (mapcar '(lambda (u) (vla-put-lock u :vlax-true)) lk)
  6.     )
  7.     (princ "\*Cancel*")
  8.   )
  9.   (setq lst (mapcar 'strcase (list "point" "station" "trigonom" "REPERS" "koryfes" "kokaek" "korot")))
  10.   (mapcar '(lambda (u) (setq l (cons (strcat u ",") l))) lst)
  11.   (if (setq s (ssget "_X" (list '(0 . "INSERT") '(66 . 1) (cons 2 (apply 'strcat l)))))
  12.     (progn (vlax-for layer (vla-get-layers doc)
  13.              (if (eq :vlax-true (vla-get-lock layer))
  14.                (vla-put-lock (car (setq lk (cons layer lk))) :vlax-false)
  15.              )
  16.            )
  17.            (vla-StartUndoMark doc)
  18.            (repeat (setq i (sslength s))
  19.              (setq e (entget (ssname s (setq i (1- i)))))
  20.              (if (tblsearch "LAYER" (setq ln (strcase (cdr (assoc 2 e)))))
  21.                (entmod (subst (cons 8 (nth (vl-position ln lst) lst)) (assoc 8 e) e))
  22.              )
  23.            )
  24.            (vla-EndUndoMark doc)
  25.            (if lk
  26.              (mapcar '(lambda (u) (vla-put-lock u :vlax-true)) lk)
  27.            )
  28.            (vla-regen doc AcAllViewports)
  29.     )
  30.   )
  31.   (princ)
  32. )
  33.