Author Topic: Use stripmtext while isolating overwritten mtext color  (Read 622 times)

0 Members and 1 Guest are viewing this topic.

jlogan02

  • Bull Frog
  • Posts: 300
Use stripmtext while isolating overwritten mtext color
« on: September 30, 2022, 05:43:07 PM »
The attached image represents a progression of new projects within one drawing. Each new project is always red. Each project after that is assigned a color. Each revision block you see from left to right is how the revision would appear in a separate drawing version of the same drawing, new project.

So there is a green revision (drawing start). Brand new drawing, the project doesn't get a color, it stays bylayer.
Rev#1 is red
New project starts, Rev#1 becomes color 56, Rev#2 becomes red.
New Project starts, Rev#2 becomes color 107, Rev#3 becomes red.
New Project starts, Rev#3 becomes 136, Rev#4 becomes red.

Most times you might see two colors, but can have as many as 5 projects running within the same drawing at one time. Think of them as chronological revisions.

Using color routines I hunt for RED mtext entities and change them to the next revision color.

Sadly, some of our users insist on overwriting Mtext color. Hence the code below. You might note that I'm exacerbating the mtext color overwrite issue buy using this piece of code as C1 becomed C136, not 1 and 136 per the properties color palette.


Code - Auto/Visual Lisp: [Select]
  1.  (if (setq sel (ssget "_X" '((0 . "mtext"))));;MTEXT
  2.    (repeat (setq int (sslength sel))
  3.      (setq obj (vlax-ename->vla-object (ssname sel (setq int (1- int)))))
  4.       (progn (setq txt (vla-get-textstring obj))
  5.            (while (vl-string-search "\\C1;" txt) (setq txt (vl-string-subst "\\C136;" "\\C1;" txt)))
  6.            (vla-put-textstring obj txt)
  7.       )
  8.     )
  9.   )

I need to find a way to either strip the overwritten Mtext of just one of the colors while leaving the other colors alone during the change from RED (above code) to that new revision color, or better still strip out the overwritten C1 color and then change it to the next color. The overwritten color issue always starts with RED.

For now I'm just adding this to the end of each "return to bylayer" routines.

Code - Auto/Visual Lisp: [Select]
  1. (Alert "Some MText may have not be returned to it's bylayer color. Select them now")
  2.   (StripMtext (ssget) "c") ;;select all red text not changed by routine.
J. Logan
ACAD 2018

I am one with the Force and the Force is with me.
AutoCAD Map 2018 Windows 10

BIGAL

  • Swamp Rat
  • Posts: 1098
  • 40 + years of using Autocad
Re: Use stripmtext while isolating overwritten mtext color
« Reply #1 on: September 30, 2022, 08:19:41 PM »
Just a thought maybe check backwards start with does highest color exist and change. Then can make lower color go up.
A man who never made a mistake never made anything

jlogan02

  • Bull Frog
  • Posts: 300
Re: Use stripmtext while isolating overwritten mtext color
« Reply #2 on: October 03, 2022, 03:30:51 PM »
That's is exactly were I'm stuck. I can't seem or don't know how to check for the overwritten value.

(vl-string-search "\\C1;") ???
J. Logan
ACAD 2018

I am one with the Force and the Force is with me.
AutoCAD Map 2018 Windows 10

jlogan02

  • Bull Frog
  • Posts: 300
Re: Use stripmtext while isolating overwritten mtext color
« Reply #3 on: October 04, 2022, 07:17:42 PM »
This gets the selection set for mtext entities that are red... but I get this error.
Error: bad argument type: (or stringp symbolp): <Selection set: 70>

It's the
Code - Auto/Visual Lisp: [Select]
  1. vl-string-search str "*\\C1;*"
as C1 is not a string ??

Code - Auto/Visual Lisp: [Select]
  1. (defun c:foo ( / str obj txt)
  2.  (if (setq str (ssget "_x" '((0 . "mtext"))))
  3.   (repeat (setq int (sslength str))
  4.      (setq obj (vlax-ename->vla-object (ssname str (setq int (1- int)))))
  5.       (progn (setq txt (vla-get-textstring obj))
  6.         (while (vl-string-search "\\C1;" txt)
  7.          (stripmtext obj '("C"))
  8.         (command "chprop" obj "" "C" "56" "")
  9.         )  
  10.       )
  11.   )
  12.  )
  13. )

Once this runs and I get the error, I can drop the last two lines into the command line and they do what is expected. I can't seem to get any farther.
J. Logan
ACAD 2018

I am one with the Force and the Force is with me.
AutoCAD Map 2018 Windows 10

BIGAL

  • Swamp Rat
  • Posts: 1098
  • 40 + years of using Autocad
Re: Use stripmtext while isolating overwritten mtext color
« Reply #4 on: October 04, 2022, 08:10:22 PM »
You need to look at the mtext string closer your not removing enough control code.

: (vla-get-textstring obj)
"ABCD\\C1;EFG"

remove color from mtext manually
: (vla-get-textstring obj )
"ABCDEFG"
A man who never made a mistake never made anything

jlogan02

  • Bull Frog
  • Posts: 300
Re: Use stripmtext while isolating overwritten mtext color
« Reply #5 on: October 05, 2022, 12:32:09 PM »
Code - Auto/Visual Lisp: [Select]
  1. (defun c:foo ( / str obj txt)
  2.  (if (setq str (ssget "_x" '((0 . "mtext"))))
  3.   (repeat (setq int (sslength str))
  4.      (setq obj (vlax-ename->vla-object (ssname str (setq int (1- int)))))
  5.       (progn (setq txt (vla-get-textstring obj))
  6.         (while (vl-string-search "*\\C1;*" txt) ;;;added wildcard both side of color code
  7.          (stripmtext obj '("C"))
  8.         (command "chprop" obj "" "C" "56" "")
  9.         )  
  10.       )
  11.   )
  12.  )
  13. )

added wildcard both side of color code
Returns nil

At this point that feels like a win, even though it's not.
J. Logan
ACAD 2018

I am one with the Force and the Force is with me.
AutoCAD Map 2018 Windows 10

jlogan02

  • Bull Frog
  • Posts: 300
Re: Use stripmtext while isolating overwritten mtext color
« Reply #6 on: October 19, 2022, 05:23:05 PM »
While laying here in an emergency room I thought I'd see if I could go off memory, no ACAD, and no code.

I believe I left off with an attempt to changing
Code - Auto/Visual Lisp: [Select]

to

Code - Auto/Visual Lisp: [Select]
  1. (while (wcmatch txt *\\C1;*")...)

There was 1 piece of red mtext in the drawing and another piece of text on color 136. Both with the letters asdadf.
From memory I got a...

bad arguement type lselsetp {\\c1;asadf}

I looked at the lselsetp error definition. Am I changing ssname or sslength maybe ?

I'm pretty sure none of that is right while going purely from memory.

Anyway, I'm just killing time waiting for test results. How long does it take to spin a vile of blood round and round?



J. Logan
ACAD 2018

I am one with the Force and the Force is with me.
AutoCAD Map 2018 Windows 10