Jump to content

Lisp colour change for all layers and blocks


Recommended Posts

  • 2 months later...
  • Replies 118
  • Created
  • Last Reply

Top Posters In This Topic

  • VVA

    35

  • ichlove

    13

  • flopo

    6

  • Tommy78

    5

Top Posters In This Topic

Popular Posts

Command: ColorX - change color all object of drawing. All layer unlock and thaw ColorXREF change color xref only on a current session. All layer unlock and thaw ColorXL - change color all object o

Posted Images

VVA

colorx is great, I also need to give the xref one a go.

Not sure what the other variants do, I kind of got lost with alll the different requests.

 

Sometimes I need to change the colour of all the objects in a drawing just like colourx already does, but sometimes I need to do the opposite. The drawing may be recieved completly one colour and I need to restore all the layer colours as they are in the layer property manager. Any chance of a modification to enable this restore feature? I can select all and set to bylayer, but it doesn't work with any attributes.

 

Many thanks

Pads

 

edit: ah silly me, of course I can just select 'bylayer' in the select colour pop up.

 

cheers!

Link to post
Share on other sites
Hi everybody,

 

I'ts possible to have the command lisp Colorx ...without he's calling a dialog box?

 

Many thanks!

Replace COLORX command in your lisp file or add as new command

(defun C:COLORX	(/ doc col)
 (vl-load-com)
 (setq doc (vla-get-activedocument (vlax-get-acad-object)))
 (vla-startundomark doc)
 (mip:layer-status-save)
 [color="red"](initget 4)[/color]
 (if ([color="red"]setq col (getint "\nEnter color index: "))[/color]
   (ChangeAllObjectsColor doc col) ;_ col — color number
 ) ;_ end of if
 (mip:layer-status-restore)
 (vla-endundomark doc)
 (princ)
) ;_ end of defun

Link to post
Share on other sites
  • 3 months later...

Hello VVA,

 

Awesome lisp routine! I was wondering how to make the color bylayer change thru the Layer Properties Manager instead of forcing the color? I noticed the lisp forces the color properties to the desired color of choice. Here is an example of the process I am trying to use.

 

First I open the Layer Properties Manager - select all layers - unlock all layers - change all colors to 253

Next I go to modify - change to bylayer - select all - Y- Y and process complete.

 

I have used your ColorX lisp and it works like a champ however it is difficult to manage the colors once they are forced to the color of choice.

 

I am fairly new to writing lisp but do know many of the functions and features of AutoCad. I am now expanding my AutoCad knowledge to VBA, Lisp and automation. Any help would be greatly appreciated.

 

Thank you for your time and efforts.

 

Sincerely,

 

Micahel

Link to post
Share on other sites

I do not quite understand what the problem is?

To change the color to "bylayer" You can call ColorX and select the appropriate button. Beginning with the 2008 version of AutoCAD command is added _setbylayer.

Link to post
Share on other sites
  • 10 months later...
  • 1 year later...
  • 2 weeks later...
What perfect! But can you create each layer for each color and put all objects same color in same layer?

Try it

 

(defun C:C2L (/ tmp txt count TrueColor layFilter lay)
;;;http://forum.dwg.ru/showthread.php?p=1069183
;;;http://www.cadtutor.net/forum/showthread.php?533-Lisp-colour-change-for-all-layers-and-blocks/page10
;;; Color To Layer
;;; layFilter - Layer List
;;;If the colors are not in the list of layers, the layer will be called Color_Number.
;;;For example, for 123 colors -> Layer name "Color _123"
;;;color R = 12 G = 32 B = 65  -> Layer name "Color _12_32_65"
 (setq layFilter
        (list
          '((143 134 112) "MyLay1") ;_entity with color R = 143 G = 134 B = 112 is transferred to the layer "MyLay1"
          '((110 87 168) "MyLay2")  ;_entity with color R = 110 G = 87 B = 168 is transferred to the layer "MyLay2"
          '((1) "Red")  ;_entity with color ACI = 1 is transferred to the layer "Red"
          '((2) "Yellow") ;_entity with color ACI = 2 is transferred to the layer "Yellow"
          '((3) "Green")  ;_entity with color ACI = 3 is transferred to the layer "Green"
) ;_ end of list
 ) ;_ end of setq
 (vl-load-com)
 (vlax-for Blk (vla-get-blocks
                 (vla-get-activedocument (vlax-get-acad-object))
               ) ;_ end of vla-get-Blocks
   (if (eq (vla-get-isxref Blk) :vlax-false)
     (progn
       (setq count 0
             txt   (strcat "Changed " (vla-get-name Blk))
       ) ;_ end of setq
       (grtext -1 txt)
       (vlax-for Obj Blk
         (setq count (1+ count))
         (if (zerop (rem count 10))
           (grtext -1 (strcat txt " : " (itoa count)))
         ) ;_ end of if
         (if (and (vlax-write-enabled-p Obj)
                  (vlax-property-available-p Obj 'Color)
             ) ;_ end of and
           (setq tmp
                  (if
                    (= (vla-get-colormethod
                         (setq TrueColor (vla-get-truecolor Obj))
                       ) ;_ end of vla-get-ColorMethod
                       accolormethodbyrgb
                    ) ;_ end of =
                     (list (vla-get-red TrueColor)
                           (vla-get-green TrueColor)
                           (vla-get-blue TrueColor)
                     ) ;_ end of list
                     (cond ((eq (vla-get-color obj) acbyblock)
                            nil
                           )
                           ((eq (vla-get-color obj) acbylayer)
                            nil
                           )
                           (t (list (vla-get-color obj)))
                     ) ;_ end of cond
                  ) ;_ end of if
           ) ;_ end of setq
           (setq tmp nil)
         ) ;_ end of if
         (or (setq lay (cadr (assoc tmp layFilter)))
             (setq
               lay (strcat
                     "Color"
                     (apply
                       'strcat
                       (mapcar '(lambda (x) (strcat "_" (itoa x))) tmp)
                     ) ;_ end of apply
                   ) ;_ end of strcat
             ) ;_ end of setq
         ) ;_ end of or
         (if (and tmp (listp tmp) (vlax-write-enabled-p Obj))
           (entmod
             (subst
               (cons
                 8
                 lay
               ) ;_ end of cons
               (assoc 8 (entget (vlax-vla-object->ename obj)))
               (entget (vlax-vla-object->ename obj))
             ) ;_ end of subst
           ) ;_ end of entmod
         ) ;_ end of if
       ) ;_ end of vlax-for
     ) ;_ end of progn
   ) ;_ end of if
 ) ;_ end of vlax-for
 (vl-cmdf "_regenall")
 (princ)
) ;_ end of defun

Link to post
Share on other sites

found

(cond ((eq (vla-get-color obj) acbyblock)
                            nil
                           )
                           ((eq (vla-get-color obj) acbylayer)
                            nil
                           )

and change

(cond ((eq (vla-get-color obj) acbyblock)
                            (list 888) ;_byblock
                           )
                           ((eq (vla-get-color obj) acbylayer)
                            (list 999) ;_Bylayer
                           )

Link to post
Share on other sites
  • 2 weeks later...
brianmcguire

I am sure you hear this all the time. this is awesome. I am new to Codingand lisp but this is perfect. I am trying to figure out how to do this as ascript on multiple drawings. The only thing stopping me in the ACI colordialogue box pop up. Is there a way to tell it to input "8" thenenter so it will run as a script. You may have covered this already. Eitherway, you are a coding genus so thank you very much.

Link to post
Share on other sites

brianmcguire see post #84 or use your function

(defun mycolorXfunc	( col / doc)
;col — color number
 (vl-load-com)
 (setq doc (vla-get-activedocument (vlax-get-acad-object)))
 (vla-startundomark doc)
 (mip:layer-status-save)
   (ChangeAllObjectsColor doc col) ;_ col — color number
 (mip:layer-status-restore)
 (vla-endundomark doc)
 (princ)
) ;_ end of defun

Use

(mycolorXfunc  

Link to post
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
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...