My Photo

May 2009

Sun Mon Tue Wed Thu Fri Sat
          1 2
3 4 5 6 7 8 9
10 11 12 13 14 15 16
17 18 19 20 21 22 23
24 25 26 27 28 29 30
31            

BLOGMap


« Super Previous Plot | Main | 7 Days and counting till AU »

November 18, 2005

Convert block to Layer 0

Do you get sooo frustrated when you see you're users EXPLODING your nice Dynamic blocks? Yes, there is the option that allows you to specify which blocks can be exploded. But face it, sometimes you have to. There is options where a block needs to be a totally different layer, or color or linetype. I run into this all the time. But I may have a solution for this.

If you use the attached code called MAKE0, it prompts you to select a block,  dynamic or not. It will next take that block and create a block with the same block name but with the extension -0. Then change all the objects in the block from its current layers and settings to layer 0. It will erase the old block and insert the new block in the same location. Once placed, the block will get the same settings in the currently set layer for the drawing. Allowing you to change the appearance of you blocks without having to explode them.

Here you select the block.
Make01

Next your block will get the current layers properties applied to it.

Make02

Now your block is still a block and will change as you change its layer settings.

Make03

Here the block changes as you change its current layer.

Make04

Now for the code!!

Note: Dynamic blocks wont be set back to their dynamic block states. It will act just like a reset. You will also notice a quick flash when the code enters the dynamic block editor. This is needed to retain the dynamic block properties.

(defun c:make0 (/     oldblk oldblkname  oldblkX
  oldblkY     oldblkZ oldblkrot   newblkname
        )
  (setvar "osmode" 0)
  (setvar "blockeditlock" 0)
  (setq oldblk (entsel "\nSelect Block for Zero Makeover: "))
  (setq oldblkname (vla-get-EffectiveName (vlax-ename->vla-object (car oldblk))))
  (setq oldblkins (cdr (assoc 10 (entget (car oldblk)))))
  (setq oldblkX (cdr (assoc 41 (entget (car oldblk)))))
  (setq oldblkY (cdr (assoc 42 (entget (car oldblk)))))
  (setq oldblkZ (cdr (assoc 43 (entget (car oldblk)))))
  (setq oldblkrot (cdr (assoc 50 (entget (car oldblk)))))
  (setq newblkname (strcat "0-" oldblkname))
  (if (= (tblsearch "block" newblkname) nil)
    (setq testflag 0)
    (setq testflag 1)
  )
  (if (= testflag 0)
    (progn
       (COMMAND "-BEDIT" oldblkname)
  (command "bsaveas" (strcase (strcat "0-" oldblkname)))
  (command "change" "all" "" "p" "la" "0" "")
  (command "bsave")
  (command "bclose")
  (command "erase" oldblk "")
  ))
  (command "erase" oldblk "")
  (command "insert"
    newblkname
    oldblkins
    oldblkX
    oldblkY
    (/ (* 180 oldblkrot) pi)
  )
  (gc)
  (princ)
)

TrackBack

TrackBack URL for this entry:
http://www.typepad.com/services/trackback/6a00d8345ae08669e200d83461384f53ef

Listed below are links to weblogs that reference Convert block to Layer 0:

Comments

Mark, does this alter the insertion point at all? I have one called BL0 that I found a while back, and for some reason when the UCS isnt World, it alters the position the block was in.

hey...intersting...copy paste;)

Is there a way to join the objects together after you explode them? that way when you click on it, it is joined as one object?

Verify your Comment

Previewing your Comment

This is only a preview. Your comment has not yet been posted.

Working...
Your comment could not be posted. Error type:
Your comment has been saved. Comments are moderated and will not appear until approved by the author. Post another comment

The letters and numbers you entered did not match the image. Please try again.

As a final step before posting your comment, enter the letters and numbers you see in the image below. This prevents automated programs from posting comments.

Having trouble reading this image? View an alternate.

Working...

Post a comment

Comments are moderated, and will not appear until the author has approved them.