@Kent1Cooper wrote:
@Kent1Cooper wrote:
.... if ORG is the base color, should it be omitted from the sequence of colors of the stripes?
And the corollary: If GRY is not the base color, should it be added to the list of colors of the stripes? If so, where in the sequence?
I didn't notice on the first of my Replies that the Post I was answering was not from the OP, but @Scottu2's Post got me thinking about how I would want to do something like this, and I had already thought out how to handle some of those issues, so I've finished it up.
The following does take User selection of each one, to allow for the possibilities Scott mentioned. It lets you choose any of the colors for the base, and then any of them except the base color for the stripe color of the first one. It accepts selection of any Text/Mtext in 7 characters with a slash in the middle, so A) you can even re-designate ones that have already been changed from the initial XXX/XXX content, but B) it doesn't take just anything with a slash in it anywhere. As you pick them, the designations imposed cycle through changing the stripe color, omitting the base color from the cycle, so you never get the same color for both.
And it remembers both base and stripe colors, and offers them as defaults on subsequent use, and lets you try again if you pick something inappropriate, whether a wrong entity type entirely or a text object whose content isn't in the right format. [It ends if you just miss, but could be adjusted to let you try again for that, too.]
The use of the (rem) function allows the counter ['n' variable] to just be continually incremented upward, so it doesn't need to be reset to start over when it gets to the end of the list of stripe colors.
It still could use *error* handling, and of course you can change the command name, etc.
(defun C:WCPS ; = Wire Color Pair Sequence
(/ kwordstr promptstr stripelist n)
(setq
kwordstr "BLK BRn Red Org Yel GRN BLU Wht GRY "
promptstr (vl-string-translate " " "/" kwordstr)
); setq
(initget (if *WCPSbase 0 1) kwordstr); no Enter on first use; offer all colors
(setq
*WCPSbase ; global variable
(cond
( (getkword
(strcat
"\nBase wire color [" promptstr "]"
(if *WCPSbase (strcat " <" *WCPSbase ">") ""); offer prior value default if present
": "
); strcat
); getkword
); User-input condition
(*WCPSbase); prior value on Enter [when allowed]
); cond & *WCPSbase
stripelist
(vl-remove ; remove base color from stripe options
(strcase *WCPSbase)
'("BLK" "BRN" "RED" "ORG" "YEL" "GRN" "BLU" "WHT" "GRY")
); vl-remove & stripelist
); setq
(initget (if *WCPSstripe 0 1); no Enter on first use; offer all colors except base
(vl-string-right-trim " " (vl-string-subst "" (strcat *WCPSbase " ") kwordstr))
); initget
(setq
*WCPSstripe ; global variable
(cond
( (getkword
(strcat
"\nStarting stripe color ["
(vl-string-right-trim "/" (vl-string-subst "" (strcat *WCPSbase "/") promptstr))
"]"
(if *WCPSstripe (strcat " <" *WCPSstripe ">") ""); offer prior value default if present
": "
); strcat
); getkword
); User-input condition
(*WCPSstripe); prior value on Enter [when allowed]
); cond & *WCPSstripe
n (1- (vl-position (strcase *WCPSstripe) stripelist))
); setq
(while
(setq txtsel (car (entsel "\nText in ???/??? form for next Base/Stripe content <exit>: ")))
(if
(and
(setq txtdata (entget txtsel))
(wcmatch (cdr (assoc 0 txtdata)) "*TEXT"); Text or Mtext, but:
(wcmatch (cdr (assoc 1 txtdata)) "???/???"); if Mtext, no internal formatting
); and
(entmod ; then
(subst
(cons
1 ; text content
(strcat (strcase *WCPSbase) "/" (nth (rem (setq n (1+ n)) 8) stripelist))
); cons
(assoc 1 txtdata)
txtdata
); subst
); entmod
(prompt "\nNot an appropriate-format Text object."); else
); if
); while
(princ)
); defun -- C:WCPS
(vl-load-com)
(prompt "\nType WCPS to edit Wire Color Pairs in Sequence.")
Kent Cooper, AIA