sequencing color code text string

sequencing color code text string

Migumby
Advocate Advocate
2,231 Views
17 Replies
Message 1 of 18

sequencing color code text string

Migumby
Advocate
Advocate

hello,

I looking for a lsp routine that will change existing text strings to color code names.

for example:

The grey code list would be gry/blk, gry/brn, gry/red, gry/org, gry/yell, gry/grn, gry/blu, gry/wht.

I would like to select the text strings named "XXX/XXX" and they would change to the color label and sequence to the next in order.

Does anyone know of anything like this?

I’m using AutoCad 2016 with Windows 10

thanks

0 Likes
Accepted solutions (1)
2,232 Views
17 Replies
Replies (17)
Message 2 of 18

john.uhden
Mentor
Mentor

I am looking at your "XXX/XXX" as a fraction with the numerator being grey and the denomiator changing from black to brown, etc., which may be way off base.  Could you please post an image of what you want?  Are the text strings Mtext, or could they be?  That would permit color formatting of characters within the string.  Otherwise you would have to break the strings yet keep them proximitous.

John F. Uhden

0 Likes
Message 3 of 18

Migumby
Advocate
Advocate

Yea I think you have the right idea.

the text isn't mtext, but it isn't that important.

the slash symbol indicates that it's stripped wire.

I basically have to rename the text in sequence for every color.

I inserted an example.

If the slash is a problem than maybe we can use a dash instead.

thanks

0 Likes
Message 4 of 18

john.uhden
Mentor
Mentor

Ah, so when you say colors you mean textual color descriptors as separate pieces of text, in pairs under each "UNIV" whatever that is.

You'll have to enlighten me a little better on the renaming part.  Is all the text already in the drawing and you want to change say GRY-1 to GRY/BLK or something like that?  Maybe a before and after image would be helpful.

 

I know only enough about electricity to turn a light switch on and off, oh, and not to stick a paperclip in an outlet with just your fingers, oh, and not to bring the clock radio into the bath tub.

John F. Uhden

0 Likes
Message 5 of 18

Migumby
Advocate
Advocate

Yes, I think you do understand.

I'm not looking for actual colors, but color names.

I attached another example.

 

0 Likes
Message 6 of 18

Migumby
Advocate
Advocate

Sorry,

I forgot to attach my example.

0 Likes
Message 7 of 18

john.uhden
Mentor
Mentor

Thank you for the before and after.

Yes, that would be some work, but it is entirely possible.

To help guide the effort, please provide some additional information...

1.  Are the XXX/XXX texts on a unique layer?  (that may not make any difference)

2.  Does the color range always increase from left to right?

3.  Is there more than one group of terminals (whatever) in the drawing?

4.  If yes to 3, is it okay if you select one group per running of the function?

John F. Uhden

0 Likes
Message 8 of 18

DannyNL
Advisor
Advisor
Accepted solution

Something like this?

 

This will select only text with a '/' in it and sort them from left to right (based on X-coord). After sorting text is color coded according to your sequence. If more texts are selected than there are colors in the sequence, it will restart at the beginning of the sequence.

 

(defun c:ColorText (/ CT_Selection CT_Entity CT_List CT_ColorList CT_Count)
   (if
      (setq CT_Selection (ssget '((0 . "TEXT")(1 . "*/*"))))
      (progn
         (foreach CT_Entity (vl-remove-if '(lambda (CT_Item) (listp (cadr CT_Item))) (ssnamex CT_Selection))
            (setq CT_List (append CT_List (list (list (car (cdr (assoc 10 (entget (cadr CT_Entity))))) (vlax-ename->vla-object (cadr CT_Entity))))))
         )
         (setq CT_List (vl-sort CT_List '(lambda (CT_Item1 CT_Item2) (< (car CT_Item1) (car CT_Item2)))))
         (setq CT_ColorList '("BLK" "BRN" "RED" "ORG" "YEL" "GRN" "BLU" "WHT"))
         (setq CT_Count 0)
         (vla-StartUndoMark (vla-get-ActiveDocument (vlax-get-acad-object)))
         (foreach CT_Text CT_List
            (vla-put-TextString (cadr CT_Text) (strcat "GRY/" (nth CT_Count CT_ColorList)))
            (setq CT_Count (1+ CT_Count))
            (if
               (= CT_Count (length CT_ColorList))
               (setq CT_Count 0)
            )
         )
         (vla-EndUndoMark (vla-get-ActiveDocument (vlax-get-acad-object)))
      )
   )
   (princ)
)
Message 9 of 18

Scottu2
Advocate
Advocate

Nice one DannyNL.

 

I was not fast enough to post some last minute suggestions before someone posted their code.

My concept was semi-auto by selecting the base color, then starting stripe color.

Its a bit slower to select items in sequence but it provides more flexibility, if the input module

was position vertically or had 16 points or different base colors other than gry and org.

 

Select the base wire color:

Enter the starting color <1>-blk 2-brn 3-red 4-org 5-yell 6-grn 7-blu 8-wht:

Select text (gry/blk):

Select text (gry/brn):

Select text (gry/red):

Select text (gry/org):

Select text (gry/yell):

Select text (gry/grn):

 

Select the base wire color:

Enter the starting color <1>-blk 2-brn 3-red 4-org 5-yell 6-grn 7-blu 8-wht:

Select text (org/blk):

Select text (org/brn):

 

Just a suggestion  🙂

 

0 Likes
Message 10 of 18

Kent1Cooper
Consultant
Consultant

@Scottu2 wrote:

.... 

Select the base wire color:

Enter the starting color <1>-blk 2-brn 3-red 4-org 5-yell 6-grn 7-blu 8-wht:

Select text (gry/blk):

....


As a former electronic instrumentation technician in the Air Force, I fondly remember wires coded with colored striping, and similar color coding of resistors, capacitors, etc.  But I don't remember [and it may have changed since then] -- how many base wire colors are there?  Only GRY and ORG, or others, too?  And if ORG is the base color, should it be omitted from the sequence of colors of the stripes?

Kent Cooper, AIA
0 Likes
Message 11 of 18

john.uhden
Mentor
Mentor

Perfect!  You saved me some work.

John F. Uhden

Message 12 of 18

Kent1Cooper
Consultant
Consultant

@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?

Kent Cooper, AIA
0 Likes
Message 13 of 18

Migumby
Advocate
Advocate

That's it!

Its perfect!

Thank you all for your efforts.

0 Likes
Message 14 of 18

DannyNL
Advisor
Advisor

You're welcome and glad it works as needed Smiley Happy

0 Likes
Message 15 of 18

Migumby
Advocate
Advocate

Danny,

You Rock!

You saved me a lot of monotonous work.

thanks again

0 Likes
Message 16 of 18

Kent1Cooper
Consultant
Consultant

@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
0 Likes
Message 17 of 18

Migumby
Advocate
Advocate
Thank you very much Kent.
0 Likes
Message 18 of 18

Scottu2
Advocate
Advocate

Kent1Cooper,

I like your routine with the extra features and acronym, WCPS.

BTW: Thank you for your service to keep the equipment in working order, its greatly appreciated.

 

0 Likes