PDA

View Full Version : Help with this color change LISP routine


jeff.richards
2008-11-25, 05:27 PM
AutoLISP Gurus,

I managed to write this routine to change the color of a given group of layers. The problem is that when I try to use it on drawings that don't contain all layers listed, it doesn't work. I attempted to write an IF function that would check for the layer first, if it exists, then execute the command, if not, do nothing or print "no such layer" and move on, but it isn't working.

Any thougts are appreciated.

Hrothgar
2008-11-25, 06:59 PM
Try this

(defun LYCLR (LAYER COLOR / OBJNAME LAYLST)
(if (tblsearch "LAYER" LAYER)
(progn
(setq LAYLST (assoc 62 (tblsearch "LAYER" LAYER)))
(setq OBJNAME (tblobjname "LAYER" LAYER))
(entmod (subst (cons 62 COLOR) LAYLST (entget OBJNAME)))
)
(print "no such layer")
) ;_ end of if
) ;_ end of defun

jeff.richards
2008-11-25, 08:34 PM
Hrothgar,

Thanks so much, that worked!

So if I understand what was happening, when using IF by itself it expects only one expression where I was giving it three, and by nesting the PROGN function inside, LISP interpretted all expressions as one?

Thanks Again,

Hrothgar
2008-11-26, 12:37 AM
Yes that's right.

Also, someone else can probably say for sure, but I think overall it would run faster if you stored layer names and colors in a dotted pair list ie. (("layer1 . 2) ("layer2" . 4)), and then processed the list in one routine instead of multiple calls to Lyclr. But I'm only talking fractions of a second most likely, so it may not be worth the trouble at this point.

jeff.richards
2008-11-26, 03:54 PM
Many thanks. I will try using dotted pairs as I develop the routine.

Peace,