TheSwamp
Code Red => AutoLISP (Vanilla / Visual) => Topic started by: frankavoort 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
-
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.
((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)
))
-
Thanks, I tested it, works very good.
Is it possible that it includes the block definitions?
Thx in advance,
Frank
-
Alright, give this a shot
((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)
))
-
Thank you very much, it works perfect.