Visual LISP, AutoLISP and General Customization
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Routine to change RGB colors to ACI/Index 255 colors (and the opposite)

11 REPLIES 11
SOLVED
Reply
Message 1 of 12
braudpat
7534 Views, 11 Replies

Routine to change RGB colors to ACI/Index 255 colors (and the opposite)

 

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 ( Supporting Troops ) - Autodesk Expert Elite
If you are happy with my answer please mark "Accept as Solution" and if very happy please give me a Kudos (Felicitations) - Thanks

Patrice BRAUD

EESignature


11 REPLIES 11
Message 2 of 12
Lee_Mac
in reply to: braudpat

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)
Message 3 of 12
braudpat
in reply to: Lee_Mac

 

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 ( Supporting Troops ) - Autodesk Expert Elite
If you are happy with my answer please mark "Accept as Solution" and if very happy please give me a Kudos (Felicitations) - Thanks

Patrice BRAUD

EESignature


Message 4 of 12
3wood
in reply to: braudpat

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)
  )
Message 5 of 12
braudpat
in reply to: 3wood

 

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 ( Supporting Troops ) - Autodesk Expert Elite
If you are happy with my answer please mark "Accept as Solution" and if very happy please give me a Kudos (Felicitations) - Thanks

Patrice BRAUD

EESignature


Message 6 of 12
3wood
in reply to: braudpat


@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)
  )
Message 7 of 12
paulo.belesa
in reply to: 3wood

Newbie question 
How do I run the lisp? 

 

 

Thanks.

Message 8 of 12
komondormrex
in reply to: braudpat

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. 

Message 9 of 12
Sea-Haven
in reply to: komondormrex

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)

Message 10 of 12
komondormrex
in reply to: Sea-Haven

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. 

Message 11 of 12
Sea-Haven
in reply to: komondormrex

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.

 

Message 12 of 12
komondormrex
in reply to: Sea-Haven

i meant not to test, but just load what is already tested by whoever. 

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

Autodesk Design & Make Report

”Boost