Author Topic: Change the block's color  (Read 6589 times)

0 Members and 1 Guest are viewing this topic.

Fabricio28

  • Swamp Rat
  • Posts: 670
Change the block's color
« on: December 27, 2012, 06:01:33 AM »
Hi all,
 I'm having trouble to change the color of some blocks. I have about 30 blocks in my drawing called tree and I have to change some of them to other color.
 I've tried to use Edit_bloc - Gilles Chanteau lisp and didn't work.

Can anyone help me, please??

Regards.

Tharwat

  • Swamp Rat
  • Posts: 710
  • Hypersensitive
Re: Change the block's color
« Reply #1 on: December 27, 2012, 06:34:08 AM »
Hope this helps .

Code - Auto/Visual Lisp: [Select]
  1. (defun c:Test (/ color ss i sn obj lst name)
  2.   ;;;   Tharwat 27. Dec. 2012   ;;;
  3.   (if (and (setq color (acad_colordlg 7 t))
  4.            (setq ss (ssget "_:L")))
  5.     (progn (vla-startundomark acdoc)
  6.            (repeat (setq i (sslength ss))
  7.              (setq obj (vlax-ename->vla-object (setq sn (ssname ss (setq i (1- i))))))
  8.              (if (eq (cdr (assoc 0 (entget sn))) "INSERT")
  9.                (vlax-for block (setq blk (vla-item (vla-get-blocks acdoc) (setq name (vla-get-EffectiveName obj))))
  10.                  (if (and (eq :vlax-false (vla-get-isXref blk))
  11.                           (if (not (member name lst))
  12.                             (setq lst (cons name lst))
  13.                           )
  14.                      )
  15.                    (vlax-for x blk
  16.                      (if (not (eq "AcDbBlockReference" (vla-get-objectname x)))
  17.                        (vla-put-color x color)
  18.                      )
  19.                    )
  20.                  )
  21.                )
  22.                (vla-put-color obj color)
  23.              )
  24.            )
  25.            (vla-regen acdoc acAllViewports)
  26.            (vla-endundomark acdoc)
  27.     )
  28.     (princ)
  29.   )
  30.   (princ "\n Written by Tharwat Al Shoufi ")
  31.   (princ)
  32. )
  33.  

Fabricio28

  • Swamp Rat
  • Posts: 670
Re: Change the block's color
« Reply #2 on: December 27, 2012, 06:49:02 AM »
Hi Tharwat
 Thanks for the quick replay.
 
Your code didn't work, happened the same problem as gile lisp.
Maybe I'm doing something wrong. Can you take a look in my file and test your code, please?

Thanks in advance
File attached

Tharwat

  • Swamp Rat
  • Posts: 710
  • Hypersensitive
Re: Change the block's color
« Reply #3 on: December 27, 2012, 06:54:10 AM »
It is not possible to change a few blocks ' colors and leave the others which have the same name .

Fabricio28

  • Swamp Rat
  • Posts: 670
Re: Change the block's color
« Reply #4 on: December 27, 2012, 07:00:07 AM »
It is not possible to change a few blocks ' colors and leave the others which have the same name .

Thanks Tharwat,
So I'll change the name of the blocks that I wanna change the color.

Thank you very much.
 :-D

Tharwat

  • Swamp Rat
  • Posts: 710
  • Hypersensitive
Re: Change the block's color
« Reply #5 on: December 27, 2012, 07:03:20 AM »
Thanks Tharwat,

You're welcome anytime

Lee Mac

  • Seagull
  • Posts: 12914
  • London, England
Re: Change the block's color
« Reply #6 on: December 27, 2012, 07:03:47 AM »
It is not possible to change a few blocks ' colors and leave the others which have the same name .

Yes it is - set the block definition objects colour to ByBlock then change the colour property of the block reference.

Fabricio28

  • Swamp Rat
  • Posts: 670
Re: Change the block's color
« Reply #7 on: December 27, 2012, 07:10:43 AM »
It is not possible to change a few blocks ' colors and leave the others which have the same name .

Yes it is - set the block definition objects colour to ByBlock then change the colour property of the block reference.

Hi Lee,
Would you mind explain your task better, please?
Because I didn't understand well.

Thanks

Tharwat

  • Swamp Rat
  • Posts: 710
  • Hypersensitive
Re: Change the block's color
« Reply #8 on: December 27, 2012, 07:12:48 AM »
It is not possible to change a few blocks ' colors and leave the others which have the same name .

Yes it is - set the block definition objects colour to ByBlock then change the colour property of the block reference.

OMG , you're right , I have completely forgot about ByBlock option .  :oops:

Lee Mac

  • Seagull
  • Posts: 12914
  • London, England
Re: Change the block's color
« Reply #9 on: December 27, 2012, 07:13:40 AM »
It is not possible to change a few blocks ' colors and leave the others which have the same name .

Yes it is - set the block definition objects colour to ByBlock then change the colour property of the block reference.

Would you mind explain your task better, please?
Because I didn't understand well.

You can open the block in the Block Editor and change the colour of all objects within the block definition to 'ByBlock'.

With the definition colour set to 'ByBlock' you can then change the colour of individual block references in the drawing by changing the colour property of the block reference itself:



Here is a simple program to set the colour of all objects in a block definition to ByBlock:
Code - Auto/Visual Lisp: [Select]
  1. (defun c:setbyblock ( / _byblock e )
  2.  
  3.     (defun _byblock ( n l / a e x )
  4.         (if (and
  5.                 (setq e (tblobjname "BLOCK" n))
  6.                 (not (member n l))
  7.             )
  8.             (while (setq e (entnext e))
  9.                 (if (setq a (assoc 62 (setq x (entget e))))
  10.                     (entmod (subst '(62 . 0) a x))
  11.                     (entmod (append x '((62 . 0))))
  12.                 )
  13.                 (if (= "INSERT" (cdr (assoc 0 x)))
  14.                     (_byblock (cdr (assoc 2 x)) (cons n l))
  15.                 )
  16.             )
  17.         )
  18.         nil
  19.     )
  20.  
  21.     (while
  22.         (progn (setvar 'errno 0) (setq e (car (entsel "\nSelect Block: ")))
  23.             (cond
  24.                 (   (= 7 (getvar 'errno))
  25.                     (princ "\nMissed, try again.")
  26.                 )
  27.                 (   (= 'ename (type e))
  28.                     (if (= "INSERT" (cdr (assoc 0 (entget e))))
  29.                         (_byblock (cdr (assoc 2 (entget e))) nil)
  30.                         (princ "\nObject is not a block.")
  31.                     )
  32.                 )
  33.             )
  34.         )
  35.     )
  36.     (command "_.regen")
  37.     (princ)
  38. )
« Last Edit: December 27, 2012, 07:19:57 AM by Lee Mac »

Fabricio28

  • Swamp Rat
  • Posts: 670
Re: Change the block's color
« Reply #10 on: December 27, 2012, 07:18:34 AM »
Quote
You can open the block in the Block Editor and change the colour of all objects within the block definition to 'ByBlock'.

With the definition colour set to 'ByBlock' you can then change the colour of individual block references in the drawing by changing the colour property of the block reference itself.

Here is a simple program to set the colour of all objects in a block definition to ByBlock:

Thanks Lee!
Works fine.

Thanks Tharwat!

Regards
 :-D