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

0 Members and 2 Guests are viewing this topic.

pedroantonio

  • Guest
Re: Change layer of all the blocks in the drawing to the layer of block.
« Reply #15 on: December 03, 2013, 02:51:01 AM »
Thank you Thawat. Can i ask you a question ?

this is the names of the layer ok?

Code - Auto/Visual Lisp: [Select]
  1. "point" "station" "trigonom" "REPERS" "koryfes" "kokaek" "korot"

why when i change them with other names the lisp didn't work?

Tharwat

  • Swamp Rat
  • Posts: 710
  • Hypersensitive
Re: Change layer of all the blocks in the drawing to the layer of block.
« Reply #16 on: December 03, 2013, 02:58:54 AM »
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]
(if (eq (cdr (assoc 2 e)) "point")
   l1
   l2
   l3
   l4
   l5
   l6
   l7

With the of IF function you have to include the progn function to have more than one return value or so , but in our example as shown above we need only one Layer name to take place of the one that the Block lays on , so in the above example would work only for two statements and that's why I have replaced that way with another when you have asked me for modify the code for many block names and Layers as well .  :wink:

Hope this clear enough to you .

pedroantonio

  • Guest
Re: Change layer of all the blocks in the drawing to the layer of block.
« Reply #17 on: December 03, 2013, 03:26:54 AM »
yes but when i change the layer name point with the name north or title or tree anything and i do the same change in the lisp the block stays in layer 0 ?

pedroantonio

  • Guest
Re: Change layer of all the blocks in the drawing to the layer of block.
« Reply #18 on: December 03, 2013, 03:32:02 AM »
i want to add all my blocks in this lisp.so i want to help me in this code to work for any block with simple changes.

Tharwat

  • Swamp Rat
  • Posts: 710
  • Hypersensitive
Re: Change layer of all the blocks in the drawing to the layer of block.
« Reply #19 on: December 03, 2013, 03:32:58 AM »
yes but when i change the layer name point with the name north or title or tree anything and i do the same change in the lisp the block stays in layer 0 ?
It is not a matter of copying and pasting codes to work on another process with a little modification according to what it might be right , actually it is a matter of understanding every line of code and it is like a chain it has to be connected all together to give the correct aim that we are after .

Tharwat

  • Swamp Rat
  • Posts: 710
  • Hypersensitive
Re: Change layer of all the blocks in the drawing to the layer of block.
« Reply #20 on: December 03, 2013, 03:36:41 AM »
i want to add all my blocks in this lisp.so i want to help me in this code to work for any block with simple changes.

Then you can add them to my last code that I posted in recently as shown at the top of the routine . ( but do not guarantee the success since that I don't know what you're cooking in the background with the codes)  ^-^

pedroantonio

  • Guest
Re: Change layer of all the blocks in the drawing to the layer of block.
« Reply #21 on: December 03, 2013, 03:53:59 AM »
Here is all my blocks i want to add in this code...

i dont want for you to make all this , but show me an easy way and i try to finish it..

pedroantonio

  • Guest
Re: Change layer of all the blocks in the drawing to the layer of block.
« Reply #22 on: December 04, 2013, 03:39:54 AM »
I add the layer names from blocks.dwg but only for the layer REPERS the lisp work ??   :embarrassed:

Code: [Select]
(defun c:Test (/ *error* l lst lk s i e en ln)
  ;; Tharwat 03.12.2013 ;;
  (or doc (setq doc (vla-get-activedocument (vlax-get-acad-object))))
  (defun *error* (u)
    (if lk
      (mapcar '(lambda (u) (vla-put-lock u :vlax-true)) lk)
    )
    (princ "\*Cancel*")
  )
  (setq lst (mapcar 'strcase (list "krounos" "REPERS" "ROCKS" "TREE1" "TREE2" "TREE3" "TREE4" "TREE5" "TΑΧΥΜΕΤΡΙΚΑ" "VELOS" "ΒΑΝΑ" "ΒΕΛΟΣ" "ΒΟΡΡΑΣ" "ΒΡΥΣΗ" "ΔΕΗ" "ΚΑΜΕΡΑ" "ΚΛΙΜΑΚΑ" "ΚΟΡΥΦΗ ΟΤ" "Ο.Τ" "ΟΔΕΥΣΗ" "ΟΤΕ" "ΠΙΝΑΚΙΔΑ - ΤΑΜΠΕΛΑ" "ΣΗΜΑ _ΣΤΡΟΓ" "ΣΗΜΑ _ΤΡΙΓ" "ΣΗΜΑ_ΕΞΑΓ" "ΣΗΜΑ_ΤΕΤΡ" "ΣΗΜΕΙΟ_ΚΑΕΚ" "ΣΤΑΘΜΕΣ" "ΣΤΑΣΗ" "ΣΤΑΥΡΟΣ" "ΤΗΛ. ΘΑΛΑΜΟΣ" "ΤΡΙΓΩΝΟΜΕΤΡΙΚΑ" "ΦΑΝΑΡΑΡΑΚΙ  ΔΙΠΛΟ" "ΦΑΝΑΡΑΡΑΚΙ  ΜΟΝΟ" "ΦΑΝΑΡΑΡΑΚΙ  ΤΡΙΠΛΟ" "ΦΑΝΑΡΙ ΚΥΚΛΟΦΟΡΙΑΣ")))
  (mapcar '(lambda (u) (setq l (cons (strcat u ",") l))) lst)
  (if (setq s (ssget "_X" (list '(0 . "INSERT") '(66 . 1) (cons 2 (apply 'strcat l)))))
    (progn (vlax-for layer (vla-get-layers doc)
             (if (eq :vlax-true (vla-get-lock layer))
               (vla-put-lock (car (setq lk (cons layer lk))) :vlax-false)
             )
           )
           (vla-StartUndoMark doc)
           (repeat (setq i (sslength s))
             (setq e (entget (ssname s (setq i (1- i)))))
             (if (tblsearch "LAYER" (setq ln (strcase (cdr (assoc 2 e)))))
               (entmod (subst (cons 8 (nth (vl-position ln lst) lst)) (assoc 8 e) e))
             )
           )
           (vla-EndUndoMark doc)
           (if lk
             (mapcar '(lambda (u) (vla-put-lock u :vlax-true)) lk)
           )
           (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 #23 on: December 04, 2013, 05:49:19 AM »
Hi

Actually I could not use any code on the drawing because some of the layers' names are not in English which would prompt them as question marks and this is considered entirely wrong .
If you can change the name of your layers to pure English , I may could modify the code to help you with it .

pedroantonio

  • Guest
Re: Change layer of all the blocks in the drawing to the layer of block.
« Reply #24 on: December 04, 2013, 10:59:52 AM »
here i translate them

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 "krounos" "REPERS" "ROCKS" "TREE1" "TREE2" "TREE3" "TREE4" "TREE5" "measure points" "id num" "arrow2" "arrow" "ΒΟΡΡΑΣ" "faucet" "deh" "camera" "scale" "point2" "ot num" "traverse" "ote" "road light1" "road light2" "road light3" "sign4" "road section" "point kaek" "level" "station" "cross" "phone" "trigon" "sign1" "sign2" "sign13" "traffic light")))
  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. )

look and block2.dwg

Tharwat

  • Swamp Rat
  • Posts: 710
  • Hypersensitive
Re: Change layer of all the blocks in the drawing to the layer of block.
« Reply #25 on: December 04, 2013, 11:19:56 AM »
You have only 8 blocks that their names are included in your modified layer name list and one of the layer name is wrong which is including numbers and symbols and many more .

Recheck the block names with the layer list .

pedroantonio

  • Guest
Re: Change layer of all the blocks in the drawing to the layer of block.
« Reply #26 on: December 04, 2013, 11:56:40 AM »
if i understand ,the block name and the layer name must be the same. (This is impossible i can't do that.) Is any other way?

Tharwat

  • Swamp Rat
  • Posts: 710
  • Hypersensitive
Re: Change layer of all the blocks in the drawing to the layer of block.
« Reply #27 on: December 04, 2013, 12:01:09 PM »
Only 8 blocks and layer names are matched .

pedroantonio

  • Guest
Re: Change layer of all the blocks in the drawing to the layer of block.
« Reply #28 on: December 04, 2013, 12:30:12 PM »
the block name and the layer name can't be the same .....