Hello Friends
I am looking for a routine to change
- on ALL objects of the current drawing (entire DWG)
OR
- on ONLY on a classic AutoCAD selection
*** Routine: TO255COLORS
Brownse all entities and all blocks and sub-blocks and sub-entities (of the selection OR of ALL current drawing)
and force the RGB color [or Pantone or RAL] (if used) to the "nearest" ACI/Index 255 color
*** Routine: TORGBCOLORS
Exactly the opposite : entities (and sub-entities) with classic ACI/Index 255 colors will be updated with the nearest RGB color !
The good functions are here :
---- Colour Conversion Functions ---- from Lee_Mac
http://www.lee-mac.com/colourconversion.html#rgbaci
I have tried to find the right routines with Google but no success !
Thanks in advance for your help, Regards, Patrice
Patrice BRAUD
Solved! Go to Solution.
Solved by 3wood. Go to Solution.
Solved by 3wood. Go to Solution.
Solved by Lee_Mac. Go to Solution.
For the first program, try the following:
(defun c:toACI ( / i l s ) (if (setq s (ssget "_:L")) (repeat (setq i (sslength s)) (toACI (entget (ssname s (setq i (1- i))))) ) ) (command "_.regen") (princ) ) (defun toACI ( x / e n ) (entmod (vl-remove-if '(lambda ( x ) (member (car x) '(420 430))) x)) (if (and (= "INSERT" (cdr (assoc 0 x))) (not (member (setq n (cdr (assoc 2 x))) l)) (setq e (tblobjname "block" n)) (setq l (cons n l)) ) (while (setq e (entnext e)) (toACI (entget e))) ) ) (princ)
Hello Lee
1) THANKS
2) The routine acts on Entities with forced colors = OK
3) But if the default Color Layer is : RGB, Pantone, Ral, etc and if the entities are "ByLayer/ByBlock", I have an "other" problem !
So is it possible to get an other routine ("LayerToACI") that will change (if necessary) ONLY the default Color (RGB, Pantone, Ral, etc) Layer TO ACI/Index 255 color scheme ?
French Humour : Mr LEE, you are a Lisp/VLisp legend !!!
Regards, Patrice
Patrice BRAUD
To change TrueColor layer colors to Index layer colors, please try the lisp routine below:
(defun C:LAYERCOLORTOINDEX (/ acad doc color2 n1 color1 method1 colorindex) ;;; By 3wood 24/03/2016, Change truecolor layer colors to index colors (setq acad (vlax-get-acad-object) doc (vla-get-activedocument acad) color2 (vla-GetInterfaceObject acad "AutoCAD.AcCmColor.19") ) (vla-startundomark doc) (vlax-for n1 (vla-get-layers doc) (setq color1 (vla-get-truecolor n1) method1 (vla-get-colormethod color1) colorindex (vla-get-colorindex color1) ) (if (/= method1 195) (progn (vla-put-colorindex color2 colorindex) (vla-put-truecolor n1 color2) ) ) ) (vla-endundomark doc) (princ) )
Hello Mr 3wood
1) Sorry for the delay
2) Thanks your routine is OK but I change ONE line :
color2 (vla-GetInterfaceObject acad "AutoCAD.AcCmColor.19") is for 2014/2013
to
color2 (vla-GetInterfaceObject acad "AutoCAD.AcCmColor.20") is for 2015/2016
3) Please is it possible to get a NEW version that will detect automatically the version
and will run ??
Thanks again for your help, Regards, Patrice
Patrice BRAUD
@braudpat wrote:
3) Please is it possible to get a NEW version that will detect automatically the version
and will run ??
Good suggestion!
Here it is:
(defun C:LAYERCOLORTOINDEX (/ acad doc color2 n1 color1 method1 colorindex) ;;; By 3wood 31/03/2016, Change truecolor layer colors to index colors (setq acad (vlax-get-acad-object) doc (vla-get-activedocument acad) color2 (vla-GetInterfaceObject acad (strcat "AutoCAD.AcCmColor." (substr (vlax-product-key) 28 2))) ) (vla-startundomark doc) (vlax-for n1 (vla-get-layers doc) (setq color1 (vla-get-truecolor n1) method1 (vla-get-colormethod color1) colorindex (vla-get-colorindex color1) ) (if (/= method1 195) (progn (vla-put-colorindex color2 colorindex) (vla-put-truecolor n1 color2) ) ) ) (vla-endundomark doc) (princ) )
most quicker way is to copy afore mentioned or other lisp code from '(defun (...' to closing bracket to the clipboard and paste it from clipboard to autocad command line. press <enter> if needed. it shows there command loaded c:.... voile. use that command as if it were native autocad command. that's it.
I use copy and paste all the time but one problem is if the code has blank lines these will be interpreted as like a command so lisp will stop working, easier is save file, then use Explorer and just drag lisp onto the dwg. If you want it to run straight away just add the C: defun as last line.
eg (defun c:drawline add this as last line (c:drawline)
agree. in such situation i copy/paste a code into vlisp editor and do load it from there. for repititious loading a code it needs to be saved as *. lsp program.
Notepad ++ has a load lisp function which is great for testing as you write. An ActiveX add on. Runs current text.
Lets go back to the post.