Jump to content

Moving selected blocks to a specific layer


raptor22

Recommended Posts

Hey there,

I am trying to find a method to ease a process which should be done in every drawing, I need to clean up numerous drawings which are real mess. The problems is you could find a block in several layers for instance while block "Door" should only be found in its layer "Door" you could find it in several unrelated layers with wall, stairs and son on and it needs too much time to transfer all of them to their proper layers.

Is there any lisp or method to make it easier? I mean a lisp that you could choose several related blocks (different door blocks) and transfer all of them to a specific layer (door layer).

 

Thx :)

Link to comment
Share on other sites

This could be done using FILTER just select a block and delete the properties like Layer and Insert then it will find all the blocks with this name then just have Properties open and pick correct layer.

Link to comment
Share on other sites

This could be done using FILTER just select a block and delete the properties like Layer and Insert then it will find all the blocks with this name then just have Properties open and pick correct layer.

 

Thank you for you reply, I've already used Filter and it's a handy command the point is through using filter you can almost select all your wanted blocks but when you work on a dirty drawing blocks could be blocked in to each other you need to explode them first and work on them which sometimes end up to another mess by virtue of unexpected problems .... I just wanted to know if anyone has a better way to solve it.. even there is another type of filter by using quick select ....

Link to comment
Share on other sites

Consider this just as an example .

 

NOTES:

* Replace the My-Layer-Name string with your desired Layer name .

* You can add as many as you want in place of Block1,Block2 .... etc as your block names .

* Your Block objects must not be Dynamic otherwise they won't be selected and you would be in need to another filter to handle this .

 

(defun c:mtl  (/ ss e i)
 ;;; Tharwat 02.mar.2015 ;;;
 (if (and (tblsearch "LAYER" "[color=red]My-Layer-Name[/color]") [color=dimgray];;; Only one layer name here [/color]
          (setq ss
                 (ssget "_:L" '((0 . "INSERT") (2 . "[color=blue]Block1,Block2,Block3[/color]")))) [color=dimgray];;; A list of block names separated with a comma [/color]
          )
   (repeat (setq i (sslength ss))
     (setq e (entget (ssname ss (setq i (1- i)))))
     (entmod (subst '(8 . "Layer3") (assoc 8 e) e))
     )
   )
 (princ)
 )

Link to comment
Share on other sites

If you have a nested block ("door1" inside "wall1"), just redefine the original block ("door1") and all blocks ("door1") will be updated, including the nested ones

Link to comment
Share on other sites

If you have a nested block ("door1" inside "wall1"), just redefine the original block ("door1") and all blocks ("door1") will be updated, including the nested ones

 

Thank you.

 

Consider this just as an example .

 

NOTES:

* Replace the My-Layer-Name string with your desired Layer name .

* You can add as many as you want in place of Block1,Block2 .... etc as your block names .

* Your Block objects must not be Dynamic otherwise they won't be selected and you would be in need to another filter to handle this .

 

(defun c:mtl  (/ ss e i)
 ;;; Tharwat 02.mar.2015 ;;;
 (if (and (tblsearch "LAYER" "[color=red]My-Layer-Name[/color]") [color=dimgray];;; Only one layer name here [/color]
          (setq ss
                 (ssget "_:L" '((0 . "INSERT") (2 . "[color=blue]Block1,Block2,Block3[/color]")))) [color=dimgray];;; A list of block names separated with a comma [/color]
          )
   (repeat (setq i (sslength ss))
     (setq e (entget (ssname ss (setq i (1- i)))))
     (entmod (subst '(8 . "Layer3") (assoc 8 e) e))
     )
   )
 (princ)
 )

 

 

Thank you, I tried your code but it simply doesn't work as I write the command -MTL- nothing happens and command line is ready for a new command ... if you could modify it then it would be great. thank you.

 

by the way I can't appreciate your kindness ... :thumbsup:

Link to comment
Share on other sites

Thank you.

 

Thank you, I tried your code but it simply doesn't work as I write the command -MTL- nothing happens and command line is ready for a new command ... if you could modify it then it would be great. thank you.

 

by the way I can't appreciate your kindness ... :thumbsup:

 

You are welcome :)

 

You just changed the command name of the program and did not change the highlighted words that I indicated to .

 

I doubt that you read the notes that I wrote earlier in the same post of the program :facepalm:

Link to comment
Share on other sites

You are welcome :)

 

You just changed the command name of the program and did not change the highlighted words that I indicated to .

 

I doubt that you read the notes that I wrote earlier in the same post of the program :facepalm:

 

 

Hey there ...

 

I am so sorry you are right my bad ... I did exactly what you said and it worked , thx again... but instead of inserting my blocks to the given layer name (06-Door) all of them got inserted into a layer by the name of "Layer3" which didn't exist before.

Link to comment
Share on other sites

Try the following program, change the highlighted section to suit:

 

([color=BLUE]defun[/color] c:blklaymap ( [color=BLUE]/[/color] enx idx lay map sel )
   ([color=BLUE]setq[/color]
       map
      '([highlight]
           ([color=MAROON]"Door"[/color] . [color=MAROON]"Door Layer"[/color])
           ([color=MAROON]"Wall"[/color] . [color=MAROON]"Wall Layer"[/color])[/highlight]
       )
       map ([color=BLUE]mapcar[/color] '([color=BLUE]lambda[/color] ( x ) ([color=BLUE]cons[/color] ([color=BLUE]strcase[/color] ([color=BLUE]car[/color] x)) ([color=BLUE]cdr[/color] x))) map)
   )
   ([color=BLUE]if[/color]
       ([color=BLUE]setq[/color] sel
           ([color=BLUE]ssget[/color] [color=MAROON]"_X"[/color]
               ([color=BLUE]append[/color]
                  '(
                       ( 0 . [color=MAROON]"INSERT"[/color])
                       (-4 . [color=MAROON]"<OR"[/color])
                       ( 2 . [color=MAROON]"`*U*"[/color])
                   )
                   ([color=BLUE]mapcar[/color] '([color=BLUE]lambda[/color] ( x ) ([color=BLUE]cons[/color] 2 ([color=BLUE]car[/color] x))) map)
                  '(
                       (-4 . [color=MAROON]"OR>"[/color])
                   )
               )
           )
       )
       ([color=BLUE]repeat[/color] ([color=BLUE]setq[/color] idx ([color=BLUE]sslength[/color] sel))
           ([color=BLUE]setq[/color] enx ([color=BLUE]entget[/color] ([color=BLUE]ssname[/color] sel ([color=BLUE]setq[/color] idx ([color=BLUE]1-[/color] idx)))))
           ([color=BLUE]if[/color] ([color=BLUE]setq[/color] lay ([color=BLUE]cdr[/color] ([color=BLUE]assoc[/color] ([color=BLUE]strcase[/color] (LM:name->effectivename ([color=BLUE]cdr[/color] ([color=BLUE]assoc[/color] 2 enx)))) map)))
               ([color=BLUE]entmod[/color] ([color=BLUE]subst[/color] ([color=BLUE]cons[/color] 8 lay) ([color=BLUE]assoc[/color] 8 enx) enx))
           )
       )
   )
   ([color=BLUE]princ[/color])
)

[color=GREEN];; Block Name -> Effective Block Name  -  Lee Mac[/color]
[color=GREEN];; blk - [str] Block name[/color]

([color=BLUE]defun[/color] LM:name->effectivename ( blk [color=BLUE]/[/color] rep )
   ([color=BLUE]if[/color]
       ([color=BLUE]and[/color] ([color=BLUE]wcmatch[/color] blk [color=MAROON]"`**"[/color])
           ([color=BLUE]setq[/color] rep
               ([color=BLUE]cdadr[/color]
                   ([color=BLUE]assoc[/color] -3
                       ([color=BLUE]entget[/color]
                           ([color=BLUE]cdr[/color] ([color=BLUE]assoc[/color] 330 ([color=BLUE]entget[/color] ([color=BLUE]tblobjname[/color] [color=MAROON]"block"[/color] blk))))
                          '([color=MAROON]"AcDbBlockRepBTag"[/color])
                       )
                   )
               )
           )
           ([color=BLUE]setq[/color] rep ([color=BLUE]handent[/color] ([color=BLUE]cdr[/color] ([color=BLUE]assoc[/color] 1005 rep))))
       )
       ([color=BLUE]cdr[/color] ([color=BLUE]assoc[/color] 2 ([color=BLUE]entget[/color] rep)))
       blk
   )
)

([color=BLUE]princ[/color])

Link to comment
Share on other sites

Hey there ...

 

I am so sorry you are right my bad ... I did exactly what you said and it worked , thx again... but instead of inserting my blocks to the given layer name (06-Door) all of them got inserted into a layer by the name of "Layer3" which didn't exist before.

 

You are welcome . and happy you got it working .

Link to comment
Share on other sites

Try the following program, change the highlighted section to suit:

 

Thx a million it worked ... exactly what I wanted ... :D

 

You are welcome . and happy you got it working .

Thank you ....

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...