TheSwamp

Code Red => AutoLISP (Vanilla / Visual) => Topic started by: jlogan02 on July 08, 2022, 12:51:44 PM

Title: StripMtext modified example not working
Post by: jlogan02 on July 08, 2022, 12:51:44 PM
According to the description in the lisp file...

This doesn't seem to be working. What am I missing?

The text is found and a selection set is created.
Code - Auto/Visual Lisp: [Select]
  1.   (if (setq ss (ssget "x" '((0 . "mtext") (62 . 1)))) (StripMtext ss '("C")))

At the command line..
Code - Auto/Visual Lisp: [Select]
  1. Command: (setq ss (ssget "x" '((0 . "mtext") (62 . 1))))
  2. <Selection set: 12a>
  3. Command: (StripMtext ss '("C"))
  4. 1


Tried this variation
Selection set made
but returns a selection set again once command issued.

Code - Auto/Visual Lisp: [Select]
  1.   (if (setq ss (ssget "x" '((0 . "mtext") (62 . 1))))
  2.     (Command "SMT" ss "C)

At the command line...
Command: (setq ss (ssget "x" '((0 . "mtext") (62 . 1))))
<Selection set: 15d>
Command: (Command "-SMT" ss "C" "")
-SMT Unknown command "-SMT".  Press F1 for help.
Command: <Selection set: 349>

All works fine with SMT outside of lisp and at the command line with
Command: SMT ...dialog box
Title: Re: StripMtext modified example not working
Post by: jlogan02 on July 08, 2022, 01:36:54 PM
Need to read a bit further down the description.

(StripMtext (ssget "x") "c")

works.

Edit: now to isolate for just color red.
Title: Re: StripMtext modified example not working
Post by: jlogan02 on July 08, 2022, 03:54:38 PM
Ok...not having any luck here.

We use color (red) as a revision identifier.
We use color (15) as a future identifier.

I've been using this...

Code - Auto/Visual Lisp: [Select]
  1.   (if (setq sel (ssget "_X" '((0 . "mtext") (62 . 1))));;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 "\\C256;" "\\C1;" txt)))
  6.            (vla-put-textstring obj txt)
  7.       )
  8.     )
  9.   )


because some of our users have a tendency to use the Mtext dialog to set the color. I don't like this approach because it leaves the {Ccolor # and doesn't actually strip it away, it just changes the color to \\C256. So future uses of other routines are rendered obsolete, or I'd have to write more routines to cover all the possibilities.

StripMtext is the answer, but I'm not able to isolate just one color using logic..

Code - Auto/Visual Lisp: [Select]
  1. (StripMtext (ssget "x" '((-4 . "<>")(62 . 15))) "c")
but that only selects color properties and not Mtext dialog hard coded color. Am I relegated to asking the user to select the offending Mtext entities? I prefer the hunt and kill method without users selecting things.
Title: Re: StripMtext modified example not working
Post by: jlogan02 on July 08, 2022, 06:40:24 PM
Ok...I just added this to the end of the routine.

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

Not optimal, but at least with the alert, some training, and the user hopefully using their eyes they'll get it done.

I can live with this.