Jump to content

Recommended Posts

Posted

Here's the situation. This new job that I have gets microstation dgn's and we have to convert them to autocad. They wind up coming in with hard coded colors and linetypes. Thats fine as we just need to use these as are, but need to change colors to go with our plotting ctb so it appears corretly.

 

Is there a routine that will allow me to pick, say something that is hard coded colored 150 (thus selecting everything that has a color of 150) and change it to a desired color?

 

I spent all of last night trying to find something but came up empty handed.

  • Replies 24
  • Created
  • Last Reply

Top Posters In This Topic

  • Lee Mac

    6

  • BlackBox

    6

  • Lee Roy

    6

  • econnerly

    6

Popular Days

Top Posters In This Topic

Posted

Use the SETBYLAYER command, then adjust colors and linetypes in the layer manager.

 

Or use Quick Select to filter to that one color.

 

No doubt someone will be along any minute with a lisp routine for you to use.

Posted

Here's something I use:

 

;;; e2a.lsp - Encompass to American color translator

(defun c:e2a (/ colLst lay col)
(vl-load-com)
(setq colLst '(
(1 . 67)
(2 . 66)
(3 . 64)
(4 . 77)
(5 . 78)
(6 . 73)
))

(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)

(setq colLst '(
(64 . 1)
(66 . 2)
(67 . 3)
(68 . 4)
(69 . 5)
(72 . 
(73 . 12)
(74 . 13)
(76 . 20)
(77 . 22)
(78 . 30)
(79 . 41)
))

(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)
)

;;; end e2a.lsp

 

The left number is the color to change from, the right number is the color to change to.

 

I do a double color change. I change the colors first to colors that aren't necessarily used in either .ctb, then change those to the final colors. In the code, you can see that I switch colors 1 and 3 ultimately. If I were to switch 1 to 3, then 3 to 1, my reds never changed but my greens are all red now; not exactly what I wanted. So I change 1 to 67 and 3 to 64; then 64 to 1 and 67 to 3; effectively swapping my reds and greens. I hope that makes sense.

 

I'm sure there's simpler methods, but this took me minutes to make and does the job for me.

Posted
Use the SETBYLAYER command, then adjust colors and linetypes in the layer manager.

 

Or use Quick Select to filter to that one color.

 

No doubt someone will be along any minute with a lisp routine for you to use.

 

Thanks for the quick reply. I have tried that, but unfortuantly some of the entities I bring in that are on the same "level" are colored different and with different linetypes. I need it to appear just as it would if the dgn was plotted. I would create a custom ctb file, but we are also adding our own stuff to these drawings; so that isn't an option.

Posted
Here's something I use:

 

;;; e2a.lsp - Encompass to American color translator

(defun c:e2a (/ colLst lay col)
(vl-load-com)
(setq colLst '(
(1 . 67)
(2 . 66)
(3 . 64)
(4 . 77)
(5 . 78)
(6 . 73)
))

(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)

(setq colLst '(
(64 . 1)
(66 . 2)
(67 . 3)
(68 . 4)
(69 . 5)
(72 . 
(73 . 12)
(74 . 13)
(76 . 20)
(77 . 22)
(78 . 30)
(79 . 41)
))

(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)
)

;;; end e2a.lsp

 

The left number is the color to change from, the right number is the color to change to.

 

I do a double color change. I change the colors first to colors that aren't necessarily used in either .ctb, then change those to the final colors. In the code, you can see that I switch colors 1 and 3 ultimately. If I were to switch 1 to 3, then 3 to 1, my reds never changed but my greens are all red now; not exactly what I wanted. So I change 1 to 67 and 3 to 64; then 64 to 1 and 67 to 3; effectively swapping my reds and greens. I hope that makes sense.

 

I'm sure there's simpler methods, but this took me minutes to make and does the job for me.

 

Very nice Lee Roy!

I can use this on another project we are working on. Unfortunately for this one the colors are not consistent from drawing to drawing. So I would still need the ability to select all entities with the color and change to a user defined color.

Posted
Is there a routine that will allow me to pick, say something that is hard coded colored 150 (thus selecting everything that has a color of 150) and change it to a desired color?

 

QSELECT > Color > 150, then either CHPROP > Color, or use the Color drop-down.

 

Of course, this procedure could also be automated.

Posted
QSELECT > Color > 150, then either CHPROP > Color, or use the Color drop-down.

 

Of course, this procedure could also be automated.

 

Thats exactly what I have been doing Lee! Its just very time consuming when I have to do that command about 60 times a sheet.

Posted
QSELECT > Color > 150, then either CHPROP > Color, or use the Color drop-down.

 

Of course, this procedure could also be automated.

 

I've found that when an object is set to "BYLAYER", QSELECT doesn't select it when I specify the color number. I hate that. Is there a variable I can change?

Posted

Just to update my code above, I simplified it a little for others that may be able to use it.

 

It's still a double change. Change original colors to temporary colors that are not used, then change the temps to final colors. This prevents changing a color back to itself or to another undesired color.

 

;;; c2c.lsp - Color to Color translator
;;;
;;;Expand the lists as needed to change all necessary colors
;;;

(defun c:e2a (/ colLst)
(vl-load-com)

(defun convert (colLst / lay col)
(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)
)

;;;
;;;list of original colors to change from, to temporary colors
;;;(<from> . <to>)
;;;
(setq colLst '(
(1 . 67)
(2 . 66)
(3 . 64)
(4 . 77)
(5 . 78)
))
(convert colLst) ;Run convert function

;;;
;;;list of temporary colors to change from, to final colors 
;;;(<from> . <to>)
;;;
(setq colLst '(
(64 . 1)
(78 . 2)
(67 . 3)
(66 . 4)
(77 . 5)
))
(convert colLst) ;Run convert function
)

;;; end c2c.lsp

Posted
I've found that when an object is set to "BYLAYER", QSELECT doesn't select it when I specify the color number. I hate that. Is there a variable I can change?

 

Not to my knowledge, since the QSELECT command is selecting objects based on object properties, not layer properties.

Posted

I've found that when an object is set to "BYLAYER", QSELECT doesn't select it when I specify the color number. I hate that.

 

By definition if an object is set to "BYLAYER," QSELECT will not select it when you specify any color other than "BYLAYER." Instead you might consider QSELECT by block name. SELECTSIMILAR (or a custom adaptation of) may also be a work around.

 

Is there a variable I can change?

 

Not that I am aware of.

Posted
Thats exactly what I have been doing Lee! Its just very time consuming when I have to do that command about 60 times a sheet.

 

Here is a very simple program that will 'map' one set of colours to another:

 

(defun c:c2c ( / col doc map )
   
   ;; Color Map
   ;; Alter this list to suit your requirements

   (setq map
      '(
           ;; <Old Color>  <New Color>
           (     150          152    )
           (     140          147    )
           (     213          190    )
       )
   )

   (setq doc (vla-get-activedocument (vlax-get-acad-object)))
   (vlax-for blk (vla-get-blocks doc)
       (if (eq :vlax-false (vla-get-isxref blk))
           (vlax-for obj blk
               (if (setq col (cadr (assoc (vla-get-color obj) map)))
                   (vl-catch-all-apply 'vla-put-color (list obj col))
               )
           )
       )
   )
   (vla-regen doc acallviewports)
   (princ)
)
(vl-load-com) (princ)

The program will alter the colours for all objects for which the colour property is not set to ByLayer, and the colour is found in the colour map.

 

The program will include all objects in all layouts and will also include objects nested in blocks to any level.

 

The program will exclude objects found in XRefs, or objects on locked layers.

Posted

Lee, what happens when you want to change 1 to 3 and 3 to 1?

 

Such as:

   (setq map
      '(
           ;; <Old Color>  <New Color>
           (     1          3    )
           (     3          1    )
           (     5          4    )
       )
   )

 

Would this change all red to green, then all green to red, thus leaving red alone in the end?

Posted
Lee, what happens when you want to change 1 to 3 and 3 to 1?

 

Would this change all red to green, then all green to red, thus leaving red alone in the end?

 

No, since the block collection is iterated only once; the result would be as you would inuitively expect: what was red becomes green, and what was green becomes red.

Posted

(Assoc ... trumps (Foreach x ...

 

:thumbsup:

Posted
(Assoc ... trumps (Foreach x ...

 

:thumbsup:

 

Ahhhhhh....there it is!

 

Thank you both!

Posted
(Assoc ... trumps (Foreach x ...

 

:thumbsup:

 

I wish I had the programming skills as you guys. I have no clue what that means.

Posted (edited)
Ahhhhhh....there it is!

 

Thank you both!

 

Lee did all of the (hard?) work. :thumbsup:

 

I wish I had the programming skills as you guys. I have no clue what that means.

 

Basically, by Lee correctly using the Assoc function to query the Object's color against the Map list variable (which consists of a list of lists, i.e., (list (list OldColor1 NewColor1) (list OldColor2 NewColor2)) ), the Map list variable settings define what is replaced and what is not.

 

If, when querying the Map list variable, there is no matching item returned, then no change is enacted upon that object.

 

 

Were Lee to use the Foreach function with the Map list variable upon the selection set, this would not only be significantly less efficient as the code would iterate through the selection set for each item in the Map list variable, but also any Object that were to have already been changed to a new color (that corresponds to an old color further down the Map list) would _again_ be changed.

 

... Does this make (more?) sense to you now? :unsure:

Edited by BlackBox
Correction; Grouped pairs = Lists (thanks Lee!)
Posted
Lee did all of the (hard?) work. :thumbsup:

... Does this make (more?) sense to you now? :unsure:

 

It makes "more" sense! :)

Posted
It makes "more" sense! :)

 

Early on, when I was first learning LISP (which was _not_ that long ago), it felt like I was always reading others' explanations of what the code was doing here or there, and almost none of it made much sense to me... at that time.

 

The more I learned, though, the more I was able to reflect back, and even re-read old posts, and albeit slowly (in my case) it all started to fall into place.

 

** Edit - I am still learning... Through the kindness of others, and through trial and error, of course.

 

I'm sure that the same will hold true for you, as you advance your coding ability. :beer:

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...