@ВeekeeCZ wrote:
Both codes have a limit of 255 colors, then it fails. ....
I didn't imagine that the OP would want to subdivide a single line into that many segments of different colors, and if not, since mine starts over at 1 for each line [for that very reason], it wouldn't run into that problem as @dbhunia's would. But if so, then yes, it could pretty easily be made to cycle back to the beginning. @Anonymous, tell us more about how you want it to operate. Should mine continue with subsequent color numbers for further lines, rather than start over for each?
Another thing it could be made to do is to remember the specified number of segments and offer it as a default the next time you use it. Would that be of any use, or would you be using different numbers every time?
Just to illustrate a way of cycling back to the beginning of a sequence, here's a version that cycles through only 6 colors because of the use of the word "rainbow" in the Subject. Change some color numbers if you prefer the look of others to the ones I chose.
(defun C:LSMC ; = Line, Subdivided, Multi-Colored in 6 "rainbow" colors
(/ clist n p1 p2 a s c)
(setq
clist '(1 30 2 3 150 6); "rainbow" colors +/-
n (getint "\nNumber of differently-colored segments: ")
); setq
(while (setq p1 (getpoint "\nStart of line or <exit>: "))
(setq
p2 (getpoint p1 "\nEnd of line: ")
a (angle p1 p2)
s (/ (distance p1 p2) n)
c -1
); setq
(repeat n
(command
"_line" "_none" p1 "_none" (polar p1 a s) ""
"_.chprop" "_last" "" "_color" (nth (setq c (rem (1+ c) 6)) clist) ""
); command
(setq p1 (getvar 'lastpoint))
); repeat
); while
(princ)
); defun
Kent Cooper, AIA