Jump to content

Need Coding Help for Object Color Conversion


Recommended Posts

Posted

Our company is transitioning to 2010 products. During this switch we are also going to change from a very old pen plotter based .ctb to a newer one that takes better advantage of our new laser plotter. I found and modified a autolip that helps me convert all the layer colors from the old settings to the new. Now I need something that change any of the objects in a drawing that are not set to Bylayer using the same conversion numbers. Here is the lisp I have for the layer color conversion.

(defun c:laycol (/ colLst lay col)
 (vl-load-com)
 (setq colLst '(
(1 . 6)
(2 . 40)
(3 . 5)
(4 . 2)
(5 . 170)
(6 . 210)
(8 . 243)
(9 . 1)
(10 . 11)
(11 . 124)
(12 . 235)
(13 . 242)
(14 . 243)
(15 . 244)
(240 . 235)
))

 (vlax-for l (vla-get-layers
       (vla-get-activedocument
         (vlax-get-acad-object)))
   (setq lay (cons l lay)))
 (foreach layer lay
   (if (setq col (assoc (vla-get-color layer) colLst))
     (vla-put-color layer (cdr col))))
 (princ))

I'm just begining to get into this kind of programing so this is over my head. Any help would be greatly appreciated.

Posted
Now I need something that change any of the objects in a drawing that are not set to Bylayer using the same conversion numbers.

Are you saying you just need a way to set the color of objects to "bylayer"?

Posted
Are you saying you just need a way to set the color of objects to "bylayer"?

 

No I want to change the color of the object similiar to the way my current script does. i.e if the color of the object is set to 1 or red, it is converted to color 6 or magenta. Objects set to color 2 changed to color 40, etc. Our company standards have our objects set to bylayer, but we will be having to convert some of our drawings before these standards were implemented, and to take care any "incidentals".

Posted

I know you want help with your lisp, but I think the colorf.lsp found here will do what you want. http://www.cadtutor.net/forum/showthread.php?t=31017

 

It will edit the color of individual entities if not bylayer, and the color of layers if the entity is bylayer. You can create a table to use over many drawings; it also allows you to enter the colors "on the fly". The table should be created as a text file and in the form of From_Color To_Color

.e.g. to change color 1 to color 101 and color 2 to color 202

1 101
2 202

I've used it in a script to make it easier to use over muliple drawings

(load"colorf")
color_fix "colorchange.tbl"

where colorchange.tbl is the name of the text file you created as above

Posted
No I want to change the color of the object similiar to the way my current script does. i.e if the color of the object is set to 1 or red, it is converted to color 6 or magenta. Objects set to color 2 changed to color 40, etc. Our company standards have our objects set to bylayer, but we will be having to convert some of our drawings before these standards were implemented, and to take care any "incidentals".

 

See how it will be works for you

 

(defun C:entcol (/ col colLst ecol en layer layerobj locked obj ss)
   (vl-load-com)
 (setq colLst '(
(1 . 6)
(2 . 40)
(3 . 5)
(4 . 2)
(5 . 170)
(6 . 210)
(8 . 243)
(9 . 1)
(10 . 11)
(11 . 124)
(12 . 235)
(13 . 242)
(14 . 243)
(15 . 244)
(240 . 235)
))
(princ "\n\t\t>>>\tSelect objects to change color\t<<<")
(if (setq ss (ssget))
 (progn
   (while (setq en (ssname ss 0))
     (setq obj (vlax-ename->vla-object en)
    ecol (vla-get-color obj))
     (setq layer (vla-get-layer obj)
      layerobj
       (vla-item
	(vla-get-layers
                 (vla-get-activedocument
                   (vlax-get-acad-object)))
		 layer)
    )
     (if (eq :vlax-true (vla-get-lock layerobj))
(progn
  (vla-put-lock layerobj :vlax-false)
  (setq locked (cons layerobj locked)))
)
     (if ( = ecol 256)
(setq ecol (vla-get-colorindex
	     (vla-get-truecolor
	       layerobj)))
)
     (if (setq col (assoc ecol colLst))
     (vl-catch-all-apply 'vla-put-color (list obj (cdr col)))
)
     (ssdel en ss)
     )
   
   (if locked (foreach layerobj locked
	 (vla-put-lock layerobj :vlax-true))
     )
   )
 )
 (princ)
 )

 

~'J'~

Posted

Thank you lpseifert and fixo both of these work very well. I greatly appreciate the help. When I learn a little more about these I'm definitely going to study, and maybe tweak, both of these routines. Thank you again.

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
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
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...