Author Topic: Change colors 6 to 27 and 5 to 25.  (Read 1551 times)

0 Members and 1 Guest are viewing this topic.

frankavoort

  • Mosquito
  • Posts: 3
Change colors 6 to 27 and 5 to 25.
« on: March 27, 2020, 12:20:14 PM »
Hi,

Who can help me with color changes.

My company has many old drawings with blocks.
These drawings contain lines/solids and hatches in color Magenta/index color 6 and Blue/index color 5.

In every old drawing that we gonna use for future new drawings I need to convert these two colors to our new style index color 25 and 27

who can help me with a lisp which automatically changes these colors to the new colors in lines/hatches as blocks

color Magenta/index color 6 > must become index color 27.
color Blue/index color 5 > must become index color 25.

Thanks in advance,

Frank


jtoverka

  • Newt
  • Posts: 127
Re: Change colors 6 to 27 and 5 to 25.
« Reply #1 on: March 27, 2020, 12:45:47 PM »
who can help me with a lisp which automatically changes these colors to the new colors in lines/hatches as blocks

Do you need all objects in the drawing to be converted? Even the graphics inside blocks? Or exclusively to graphics inside blocks? The code below will do everything in the drawing outside of block definitions. If you need it to do block definitions, let me know.

Code: [Select]
((lambda ( / ent elist)
  (setq ent (entnext))
  (while ent
    (setq elist (entget ent '("*")))
    (if (assoc 62 elist)
      (progn
        (cond
          ((= 6 (cdr (assoc 62 eList)))
            (entmod
              (subst
                '(62 . 27)
                (assoc 62 elist)
                elist
              )
            )
          )
          ((= 5 (cdr (assoc 62 eList)))
            (entmod
              (subst
                '(62 . 25)
                (assoc 62 elist)
                elist
              )
            )
          )
        )
      )
    )
    (setq ent (entnext ent))
  )
(princ)
))

frankavoort

  • Mosquito
  • Posts: 3
Re: Change colors 6 to 27 and 5 to 25.
« Reply #2 on: March 30, 2020, 03:08:50 AM »
Thanks, I tested it, works very good.

Is it possible that it includes the block definitions?

Thx in advance,

Frank

jtoverka

  • Newt
  • Posts: 127
Re: Change colors 6 to 27 and 5 to 25.
« Reply #3 on: March 31, 2020, 07:53:41 AM »
Alright, give this a shot

Code: [Select]
((lambda ( / colorChange ent elist nextBlock)
  (defun colorChange (elist / )
    (if (assoc 62 elist)
      (progn
        (cond
          ((= 6 (cdr (assoc 62 eList)))
            (entmod
              (subst
                '(62 . 27)
                (assoc 62 elist)
                elist
              )
            )
          )
          ((= 5 (cdr (assoc 62 eList)))
            (entmod
              (subst
                '(62 . 25)
                (assoc 62 elist)
                elist
              )
            )
          )
        )
      )
    )
  )
  ; Change all color in drawing
  (setq ent (entnext))
  (while ent
    (setq elist (entget ent '("*")))
    (colorChange eList)
    (setq ent (entnext ent))
  )
 
  ; change all colors in block definitions
  (setq nextBlock (tblNext "BLOCK" t))
  (while nextBlock
    (setq ent (cdr (assoc -2 nextBlock)))
    (while ent
      (setq elist (entget ent '("*")))
      (colorChange eList)
      (setq ent (entnext ent))
    )
    (setq nextBlock (tblNext "BLOCK"))
  )
  (command "regenall")
  (princ)
))

frankavoort

  • Mosquito
  • Posts: 3
Re: Change colors 6 to 27 and 5 to 25.
« Reply #4 on: April 03, 2020, 04:09:34 AM »
Thank you very much, it works perfect.