Jump to content

Match Text LISP


Zorg

Recommended Posts

On 12/21/2022 at 3:17 AM, BIGAL said:

I use this one by you Lee. It is used where the text is RL 123.45

 

;;  Author: Lee Mac, Copyright © 2011 - www.lee-mac.com       ;;
;;------------------------------------------------------------;;
;;  Arguments:                                                ;;
;;  s - String to process                                     ;;
;;------------------------------------------------------------;;
;;  Returns:  List of numerical values found in string.       ;;
;;------------------------------------------------------------;;

(defun LM:ParseNumbers ( s )
  (
    (lambda ( l )
      (read
        (strcat "("
          (vl-list->string
            (mapcar
              (function
                (lambda ( a b c )
                  (if
                    (or
                      (< 47 b 58)
                      (and (= 45 b) (< 47 c 58) (not (< 47 a 58)))
                      (and (= 46 b) (< 47 a 58) (< 47 c 58))
                    )
                    b 32
                  )
                )
              )
              (cons nil l) l (append (cdr l) (list nil))
            )
          )
          ")"
        )
      )
    )
    (vl-string->list s)
  )
)
                        
                       
(setq datum (car (LM:ParseNumbers (cdr (assoc 1 (entget (car (entsel "\nPick datum text"))))))))

 

 

How can I utilise this lisp in my situation?

Link to comment
Share on other sites

On 12/20/2022 at 5:09 PM, Lee Mac said:

Have you tried the program I have posted here?

 

 

 

Hi Lee Mac

 

Yes I have tried and its really good, but how can I adjust lisp to show 2 decimal places? example: to show 138.20 and not 138.2 or just 138

 

Edited by Paulsub
Link to comment
Share on other sites

3 hours ago, Paulsub said:

 

Hi Lee Mac

 

Yes I have tried and its really good, but how can I adjust lisp to show 2 decimal places? example: to show 138.20 and not 138.2 or just 138

 

 

Change these lines:

                                       (if (and (= 'int (type x)) (= 'int (type *inc*)))
                                           (itoa (+ x *inc*))
                                           (if (member (type x) '(int real))
                                               (rtos (+ x *inc*) 2)
                                               x
                                           )
                                       )

 

To:

                                       (if (member (type x) '(int real))
                                           (rtos (+ x *inc*) 2 2)
                                           x
                                       )

 

Link to comment
Share on other sites

1 hour ago, Lee Mac said:

 

Change these lines:

                                       (if (and (= 'int (type x)) (= 'int (type *inc*)))
                                           (itoa (+ x *inc*))
                                           (if (member (type x) '(int real))
                                               (rtos (+ x *inc*) 2)
                                               x
                                           )
                                       )

 

To:

                                       (if (member (type x) '(int real))
                                           (rtos (+ x *inc*) 2 2)
                                           x
                                       )

 

For some reason I am getting error in cad

 

error: extra right paren on input.

 

 

                               (function

                                   (lambda ( x )

                                           (if (member (type x) '(int real))

                                               (rtos (+ x *inc*) 2 2)

                                               x

                                           )

                                       )

                                   )

             

Link to comment
Share on other sites

On 1/13/2023 at 3:47 PM, Lee Mac said:

That error implies that you have one too many closing parentheses.

;; Text Increment  -  Lee Mac
;; Increments numerical data found in a selection of Text or MText
;; objects by a value specified by the user.

(defun c:txtinc ( / e i l s x )
   (if (null *inc*)
       (setq *inc* 1.0)
   )
   (if (setq i (getreal (strcat "\nSpecify Increment <" (rtos *inc* 2) ">: ")))
       (setq *inc* i)
   )
   (if (equal 0.0 (rem *inc* 1) 1e-8)
       (setq *inc* (fix *inc*))
   )
   (if (setq s (ssget "_:L" '((0 . "TEXT,MTEXT") (1 . "*#*"))))
       (repeat (setq i (sslength s))
           (setq e (entget (ssname s (setq i (1- i))))
                 x (assoc 1 e)
           )
           (entmod
               (subst
                   (cons 1
                       (apply 'strcat
                           (mapcar
                               (function
                                   (lambda ( x )
                                           (if (member (type x) '(int real))
                                           (rtos (+ x *inc*) 2 2)
                                           x
                                       )
                               (LM:splitstring (cdr x))
                           )
                       )
                   )
                   x e
               )
           )
       )
   )
   (princ)
)            

;; Split String  -  Lee Mac
;; Splits a string into a list of text and numbers

(defun LM:splitstring ( s )
   (
       (lambda ( l )
           (read
               (strcat "("
                   (vl-list->string
                       (apply 'append
                           (mapcar
                               (function
                                   (lambda ( a b c )
                                       (cond
                                           (   (= 92 b)
                                               (list 32 34 92 b 34 32)
                                           )
                                           (   (or (< 47 b 58)
                                                   (and (= 45 b) (< 47 c 58) (not (< 47 a 58)))
                                                   (and (= 46 b) (< 47 a 58) (< 47 c 58))
                                               )
                                               (list b)
                                           )
                                           (   (list 32 34 b 34 32))
                                       )
                                   )
                               )
                               (cons nil l) l (append (cdr l) (list nil))
                           )
                       )
                   )
                   ")"
               )
           )
       )
       (vl-string->list s)
   )
)

(princ)

 

Hi Lee, now i am getting error: malformed list on input.

 

 

Lee, I would need to decrease cover level number by invert. For example: CL136.80  and IL1.20 I would like to get result 135.60 . Is there a way to change lines to decrease number instead of increase?

 

Thank you for your effort helping.

Edited by Paulsub
Link to comment
Share on other sites

13 hours ago, Paulsub said:
;; Text Increment  -  Lee Mac
;; Increments numerical data found in a selection of Text or MText
;; objects by a value specified by the user.

(defun c:txtinc ( / e i l s x )
   (if (null *inc*)
       (setq *inc* 1.0)
   )
   (if (setq i (getreal (strcat "\nSpecify Increment <" (rtos *inc* 2) ">: ")))
       (setq *inc* i)
   )
   (if (equal 0.0 (rem *inc* 1) 1e-8)
       (setq *inc* (fix *inc*))
   )
   (if (setq s (ssget "_:L" '((0 . "TEXT,MTEXT") (1 . "*#*"))))
       (repeat (setq i (sslength s))
           (setq e (entget (ssname s (setq i (1- i))))
                 x (assoc 1 e)
           )
           (entmod
               (subst
                   (cons 1
                       (apply 'strcat
                           (mapcar
                               (function
                                   (lambda ( x )
                                           (if (member (type x) '(int real))
                                           (rtos (+ x *inc*) 2 2)
                                           x
                                       )
                               (LM:splitstring (cdr x))
                           )
                       )
                   )
                   x e
               )
           )
       )
   )
   (princ)
)            

;; Split String  -  Lee Mac
;; Splits a string into a list of text and numbers

(defun LM:splitstring ( s )
   (
       (lambda ( l )
           (read
               (strcat "("
                   (vl-list->string
                       (apply 'append
                           (mapcar
                               (function
                                   (lambda ( a b c )
                                       (cond
                                           (   (= 92 b)
                                               (list 32 34 92 b 34 32)
                                           )
                                           (   (or (< 47 b 58)
                                                   (and (= 45 b) (< 47 c 58) (not (< 47 a 58)))
                                                   (and (= 46 b) (< 47 a 58) (< 47 c 58))
                                               )
                                               (list b)
                                           )
                                           (   (list 32 34 b 34 32))
                                       )
                                   )
                               )
                               (cons nil l) l (append (cdr l) (list nil))
                           )
                       )
                   )
                   ")"
               )
           )
       )
       (vl-string->list s)
   )
)

(princ)

 

Hi Lee, now i am getting error: malformed list on input.

 

You were missing two closing parentheses - try this:

;; Text Increment  -  Lee Mac
;; Increments numerical data found in a selection of Text or MText
;; objects by a value specified by the user.

(defun c:txtinc ( / e i l s x )
   (if (null *inc*)
       (setq *inc* 1.0)
   )
   (if (setq i (getreal (strcat "\nSpecify Increment <" (rtos *inc* 2) ">: ")))
       (setq *inc* i)
   )
   (if (equal 0.0 (rem *inc* 1) 1e-8)
       (setq *inc* (fix *inc*))
   )
   (if (setq s (ssget "_:L" '((0 . "TEXT,MTEXT") (1 . "*#*"))))
       (repeat (setq i (sslength s))
           (setq e (entget (ssname s (setq i (1- i))))
                 x (assoc 1 e)
           )
           (entmod
               (subst
                   (cons 1
                       (apply 'strcat
                           (mapcar
                               (function
                                   (lambda ( x )
                                       (if (member (type x) '(int real))
                                           (rtos (+ x *inc*) 2 2)
                                           x
                                       )
                                   )
                               )
                               (LM:splitstring (cdr x))
                           )
                       )
                   )
                   x e
               )
           )
       )
   )
   (princ)
)            

;; Split String  -  Lee Mac
;; Splits a string into a list of text and numbers

(defun LM:splitstring ( s )
   (
       (lambda ( l )
           (read
               (strcat "("
                   (vl-list->string
                       (apply 'append
                           (mapcar
                               (function
                                   (lambda ( a b c )
                                       (cond
                                           (   (= 92 b)
                                               (list 32 34 92 b 34 32)
                                           )
                                           (   (or (< 47 b 58)
                                                   (and (= 45 b) (< 47 c 58) (not (< 47 a 58)))
                                                   (and (= 46 b) (< 47 a 58) (< 47 c 58))
                                               )
                                               (list b)
                                           )
                                           (   (list 32 34 b 34 32))
                                       )
                                   )
                               )
                               (cons nil l) l (append (cdr l) (list nil))
                           )
                       )
                   )
                   ")"
               )
           )
       )
       (vl-string->list s)
   )
)

(princ)

 

13 hours ago, Paulsub said:

Lee, I would need to decrease cover level number by invert. For example: CL136.80  and IL1.20 I would like to get result 135.60 . Is there a way to change lines to decrease number instead of increase?

 

Specify a negative increment.

Link to comment
Share on other sites

10 hours ago, Lee Mac said:

 

You were missing two closing parentheses - try this:

;; Text Increment  -  Lee Mac
;; Increments numerical data found in a selection of Text or MText
;; objects by a value specified by the user.

(defun c:txtinc ( / e i l s x )
   (if (null *inc*)
       (setq *inc* 1.0)
   )
   (if (setq i (getreal (strcat "\nSpecify Increment <" (rtos *inc* 2) ">: ")))
       (setq *inc* i)
   )
   (if (equal 0.0 (rem *inc* 1) 1e-8)
       (setq *inc* (fix *inc*))
   )
   (if (setq s (ssget "_:L" '((0 . "TEXT,MTEXT") (1 . "*#*"))))
       (repeat (setq i (sslength s))
           (setq e (entget (ssname s (setq i (1- i))))
                 x (assoc 1 e)
           )
           (entmod
               (subst
                   (cons 1
                       (apply 'strcat
                           (mapcar
                               (function
                                   (lambda ( x )
                                       (if (member (type x) '(int real))
                                           (rtos (+ x *inc*) 2 2)
                                           x
                                       )
                                   )
                               )
                               (LM:splitstring (cdr x))
                           )
                       )
                   )
                   x e
               )
           )
       )
   )
   (princ)
)            

;; Split String  -  Lee Mac
;; Splits a string into a list of text and numbers

(defun LM:splitstring ( s )
   (
       (lambda ( l )
           (read
               (strcat "("
                   (vl-list->string
                       (apply 'append
                           (mapcar
                               (function
                                   (lambda ( a b c )
                                       (cond
                                           (   (= 92 b)
                                               (list 32 34 92 b 34 32)
                                           )
                                           (   (or (< 47 b 58)
                                                   (and (= 45 b) (< 47 c 58) (not (< 47 a 58)))
                                                   (and (= 46 b) (< 47 a 58) (< 47 c 58))
                                               )
                                               (list b)
                                           )
                                           (   (list 32 34 b 34 32))
                                       )
                                   )
                               )
                               (cons nil l) l (append (cdr l) (list nil))
                           )
                       )
                   )
                   ")"
               )
           )
       )
       (vl-string->list s)
   )
)

(princ)

 

 

Specify a negative increment.

Lee, thank you for coming back to me and trying to help.

 

I am not getting error now, but still nothing changed and I am getting just one decimal palace ( zero not showing)

 

Also I have tried to specify a negative increment as you suggested. But i am getting negative sign next to number, is there a way for lisp to exclude and don't show it within text? 

 

image attached for review.

 

Thank you

 

still not correct.JPG

Link to comment
Share on other sites

On 1/17/2023 at 10:19 PM, Lee Mac said:

Set DIMZIN = 0 to retain trailing zeros.

 

Where the negative is concerned, surely to obtain 135.6 from 1.2 you would need to specify an increment of +134.4?

Thank you Lee Mac,  DIMZIN=0 fixed issue with trailing zeros.

Edited by Paulsub
Link to comment
Share on other sites

  • 2 months later...
On 5/11/2009 at 7:17 PM, Lee Mac said:

Three options for you :)

 

*Just thought I'd write my own versions...* :P

 

Let me know which one you like best :)

 

 

[b][color=RED]([/color][/b][b][color=BLUE]defun[/color][/b] c:mt  [b][color=RED]([/color][/b][b][color=BLUE]/[/color][/b] cEnt mEnt[b][color=RED])[/color][/b]
 [b][color=RED]([/color][/b][b][color=BLUE]if[/color][/b] [b][color=RED]([/color][/b][b][color=BLUE]and[/color][/b] [b][color=RED]([/color][/b][b][color=BLUE]setq[/color][/b] cEnt [b][color=RED]([/color][/b][b][color=BLUE]car[/color][/b] [b][color=RED]([/color][/b][b][color=BLUE]nentsel[/color][/b] [b][color=#ff00ff]"\nSelect Source Text: "[/color][/b][b][color=RED])[/color][/b][b][color=RED])[/color][/b][b][color=RED])[/color][/b]
          [b][color=RED]([/color][/b][b][color=BLUE]member[/color][/b] [b][color=RED]([/color][/b][b][color=BLUE]cdr[/color][/b] [b][color=RED]([/color][/b][b][color=BLUE]assoc[/color][/b] [b][color=#009900]0[/color][/b] [b][color=RED]([/color][/b][b][color=BLUE]entget[/color][/b] cEnt[b][color=RED])[/color][/b][b][color=RED])[/color][/b][b][color=RED])[/color][/b]
                  [b][color=DARKRED]'[/color][/b][b][color=RED]([/color][/b][b][color=#ff00ff]"TEXT"[/color][/b] [b][color=#ff00ff]"MTEXT"[/color][/b] [b][color=#ff00ff]"ATTRIB"[/color][/b][b][color=RED])[/color][/b][b][color=RED])[/color][/b][b][color=RED])[/color][/b]
   [b][color=RED]([/color][/b][b][color=BLUE]progn[/color][/b]
     [b][color=RED]([/color][/b][b][color=BLUE]redraw[/color][/b] cEnt [b][color=#009900]3[/color][/b][b][color=RED])[/color][/b]
     [b][color=RED]([/color][/b][b][color=BLUE]while[/color][/b] [b][color=RED]([/color][/b][b][color=BLUE]and[/color][/b] [b][color=RED]([/color][/b][b][color=BLUE]setq[/color][/b] mEnt [b][color=RED]([/color][/b][b][color=BLUE]car[/color][/b] [b][color=RED]([/color][/b][b][color=BLUE]nentsel[/color][/b] [b][color=#ff00ff]"\nSelect Destination Text: "[/color][/b][b][color=RED])[/color][/b][b][color=RED])[/color][/b][b][color=RED])[/color][/b]
                 [b][color=RED]([/color][/b][b][color=BLUE]member[/color][/b] [b][color=RED]([/color][/b][b][color=BLUE]cdr[/color][/b] [b][color=RED]([/color][/b][b][color=BLUE]assoc[/color][/b] [b][color=#009900]0[/color][/b] [b][color=RED]([/color][/b][b][color=BLUE]entget[/color][/b] mEnt[b][color=RED])[/color][/b][b][color=RED])[/color][/b][b][color=RED])[/color][/b]
                         [b][color=DARKRED]'[/color][/b][b][color=RED]([/color][/b][b][color=#ff00ff]"TEXT"[/color][/b] [b][color=#ff00ff]"MTEXT"[/color][/b] [b][color=#ff00ff]"ATTRIB"[/color][/b][b][color=RED])[/color][/b][b][color=RED])[/color][/b][b][color=RED])[/color][/b]
       [b][color=RED]([/color][/b][b][color=BLUE]entmod[/color][/b] [b][color=RED]([/color][/b][b][color=BLUE]subst[/color][/b] [b][color=RED]([/color][/b][b][color=BLUE]assoc[/color][/b] [b][color=#009900]1[/color][/b] [b][color=RED]([/color][/b][b][color=BLUE]entget[/color][/b] cEnt[b][color=RED])[/color][/b][b][color=RED])[/color][/b]
                      [b][color=RED]([/color][/b][b][color=BLUE]assoc[/color][/b] [b][color=#009900]1[/color][/b] [b][color=RED]([/color][/b][b][color=BLUE]entget[/color][/b] mEnt[b][color=RED])[/color][/b][b][color=RED])[/color][/b]
                      [b][color=RED]([/color][/b][b][color=BLUE]entget[/color][/b] mEnt[b][color=RED])[/color][/b][b][color=RED])[/color][/b][b][color=RED])[/color][/b][b][color=RED])[/color][/b]
     [b][color=RED]([/color][/b][b][color=BLUE]redraw[/color][/b] cEnt [b][color=#009900]4[/color][/b][b][color=RED])[/color][/b][b][color=RED])[/color][/b]
   [b][color=RED]([/color][/b][b][color=BLUE]princ[/color][/b] [b][color=#ff00ff]"\n<!> Incorrect Selection <!>"[/color][/b][b][color=RED])[/color][/b][b][color=RED])[/color][/b]
 [b][color=RED]([/color][/b][b][color=BLUE]princ[/color][/b][b][color=RED])[/color][/b][b][color=RED])[/color][/b]



[b][color=RED]([/color][/b][b][color=BLUE]defun[/color][/b] c:mt2  [b][color=RED]([/color][/b][b][color=BLUE]/[/color][/b] cEnt mEnt sLst[b][color=RED])[/color][/b]
 [b][color=RED]([/color][/b][b][color=BLUE]if[/color][/b] [b][color=RED]([/color][/b][b][color=BLUE]and[/color][/b] [b][color=RED]([/color][/b][b][color=BLUE]setq[/color][/b] cEnt [b][color=RED]([/color][/b][b][color=BLUE]car[/color][/b] [b][color=RED]([/color][/b][b][color=BLUE]nentsel[/color][/b] [b][color=#ff00ff]"\nSelect Source Text: "[/color][/b][b][color=RED])[/color][/b][b][color=RED])[/color][/b][b][color=RED])[/color][/b]
          [b][color=RED]([/color][/b][b][color=BLUE]member[/color][/b] [b][color=RED]([/color][/b][b][color=BLUE]cdr[/color][/b] [b][color=RED]([/color][/b][b][color=BLUE]assoc[/color][/b] [b][color=#009900]0[/color][/b] [b][color=RED]([/color][/b][b][color=BLUE]entget[/color][/b] cEnt[b][color=RED])[/color][/b][b][color=RED])[/color][/b][b][color=RED])[/color][/b]
                  [b][color=DARKRED]'[/color][/b][b][color=RED]([/color][/b][b][color=#ff00ff]"TEXT"[/color][/b] [b][color=#ff00ff]"MTEXT"[/color][/b] [b][color=#ff00ff]"ATTRIB"[/color][/b][b][color=RED])[/color][/b][b][color=RED])[/color][/b][b][color=RED])[/color][/b]
   [b][color=RED]([/color][/b][b][color=BLUE]progn[/color][/b]
     [b][color=RED]([/color][/b][b][color=BLUE]redraw[/color][/b] cEnt [b][color=#009900]3[/color][/b][b][color=RED])[/color][/b]
     [b][color=RED]([/color][/b][b][color=BLUE]if[/color][/b] [b][color=RED]([/color][/b][b][color=BLUE]setq[/color][/b] ss [b][color=RED]([/color][/b][b][color=BLUE]ssget[/color][/b] [b][color=#ff00ff]"_X"[/color][/b] [b][color=DARKRED]'[/color][/b][b][color=RED]([/color][/b][b][color=RED]([/color][/b][b][color=#009900]-4[/color][/b] . [b][color=#ff00ff]"<NOT"[/color][/b][b][color=RED])[/color][/b] [b][color=RED]([/color][/b][b][color=#009900]0[/color][/b] . [b][color=#ff00ff]"TEXT,MTEXT,INSERT"[/color][/b][b][color=RED])[/color][/b] [b][color=RED]([/color][/b][b][color=#009900]-4[/color][/b] . [b][color=#ff00ff]"NOT>"[/color][/b][b][color=RED])[/color][/b][b][color=RED])[/color][/b][b][color=RED])[/color][/b][b][color=RED])[/color][/b]
       [b][color=RED]([/color][/b][b][color=BLUE]mapcar[/color][/b] [b][color=DARKRED]'[/color][/b][b][color=RED]([/color][/b][b][color=BLUE]lambda[/color][/b] [b][color=RED]([/color][/b]x[b][color=RED])[/color][/b] [b][color=RED]([/color][/b][b][color=BLUE]redraw[/color][/b] x [b][color=#009900]2[/color][/b][b][color=RED])[/color][/b][b][color=RED])[/color][/b] [b][color=RED]([/color][/b][b][color=BLUE]setq[/color][/b] sLst [b][color=RED]([/color][/b][b][color=BLUE]mapcar[/color][/b] [b][color=DARKRED]'[/color][/b][b][color=BLUE]cadr[/color][/b] [b][color=RED]([/color][/b][b][color=BLUE]ssnamex[/color][/b] ss[b][color=RED])[/color][/b][b][color=RED])[/color][/b][b][color=RED])[/color][/b][b][color=RED])[/color][/b][b][color=RED])[/color][/b]
     [b][color=RED]([/color][/b][b][color=BLUE]while[/color][/b] [b][color=RED]([/color][/b][b][color=BLUE]and[/color][/b] [b][color=RED]([/color][/b][b][color=BLUE]setq[/color][/b] mEnt [b][color=RED]([/color][/b][b][color=BLUE]car[/color][/b] [b][color=RED]([/color][/b][b][color=BLUE]nentsel[/color][/b] [b][color=#ff00ff]"\nSelect Destination Text: "[/color][/b][b][color=RED])[/color][/b][b][color=RED])[/color][/b][b][color=RED])[/color][/b]
                 [b][color=RED]([/color][/b][b][color=BLUE]member[/color][/b] [b][color=RED]([/color][/b][b][color=BLUE]cdr[/color][/b] [b][color=RED]([/color][/b][b][color=BLUE]assoc[/color][/b] [b][color=#009900]0[/color][/b] [b][color=RED]([/color][/b][b][color=BLUE]entget[/color][/b] mEnt[b][color=RED])[/color][/b][b][color=RED])[/color][/b][b][color=RED])[/color][/b]
                         [b][color=DARKRED]'[/color][/b][b][color=RED]([/color][/b][b][color=#ff00ff]"TEXT"[/color][/b] [b][color=#ff00ff]"MTEXT"[/color][/b] [b][color=#ff00ff]"ATTRIB"[/color][/b][b][color=RED])[/color][/b][b][color=RED])[/color][/b][b][color=RED])[/color][/b]
       [b][color=RED]([/color][/b][b][color=BLUE]entmod[/color][/b] [b][color=RED]([/color][/b][b][color=BLUE]subst[/color][/b] [b][color=RED]([/color][/b][b][color=BLUE]assoc[/color][/b] [b][color=#009900]1[/color][/b] [b][color=RED]([/color][/b][b][color=BLUE]entget[/color][/b] cEnt[b][color=RED])[/color][/b][b][color=RED])[/color][/b]
                      [b][color=RED]([/color][/b][b][color=BLUE]assoc[/color][/b] [b][color=#009900]1[/color][/b] [b][color=RED]([/color][/b][b][color=BLUE]entget[/color][/b] mEnt[b][color=RED])[/color][/b][b][color=RED])[/color][/b]
                      [b][color=RED]([/color][/b][b][color=BLUE]entget[/color][/b] mEnt[b][color=RED])[/color][/b][b][color=RED])[/color][/b][b][color=RED])[/color][/b][b][color=RED])[/color][/b][b][color=RED])[/color][/b]
   [b][color=RED]([/color][/b][b][color=BLUE]princ[/color][/b] [b][color=#ff00ff]"\n<!> Incorrect Selection <!>"[/color][/b][b][color=RED])[/color][/b][b][color=RED])[/color][/b]
 [b][color=RED]([/color][/b][b][color=BLUE]command[/color][/b] [b][color=#ff00ff]"_regenall"[/color][/b][b][color=RED])[/color][/b]
 [b][color=RED]([/color][/b][b][color=BLUE]princ[/color][/b][b][color=RED])[/color][/b][b][color=RED])[/color][/b]



[b][color=RED]([/color][/b][b][color=BLUE]defun[/color][/b] c:mt3  [b][color=RED]([/color][/b][b][color=BLUE]/[/color][/b] cEnt ss[b][color=RED])[/color][/b]
 [b][color=RED]([/color][/b][b][color=BLUE]vl-load-com[/color][/b][b][color=RED])[/color][/b]
 [b][color=RED]([/color][/b][b][color=BLUE]if[/color][/b] [b][color=RED]([/color][/b][b][color=BLUE]and[/color][/b] [b][color=RED]([/color][/b][b][color=BLUE]setq[/color][/b] cEnt [b][color=RED]([/color][/b][b][color=BLUE]car[/color][/b] [b][color=RED]([/color][/b][b][color=BLUE]nentsel[/color][/b] [b][color=#ff00ff]"\nSelect Source Text: "[/color][/b][b][color=RED])[/color][/b][b][color=RED])[/color][/b][b][color=RED])[/color][/b]
          [b][color=RED]([/color][/b][b][color=BLUE]member[/color][/b] [b][color=RED]([/color][/b][b][color=BLUE]cdr[/color][/b] [b][color=RED]([/color][/b][b][color=BLUE]assoc[/color][/b] [b][color=#009900]0[/color][/b] [b][color=RED]([/color][/b][b][color=BLUE]entget[/color][/b] cEnt[b][color=RED])[/color][/b][b][color=RED])[/color][/b][b][color=RED])[/color][/b]
                  [b][color=DARKRED]'[/color][/b][b][color=RED]([/color][/b][b][color=#ff00ff]"TEXT"[/color][/b] [b][color=#ff00ff]"MTEXT"[/color][/b] [b][color=#ff00ff]"ATTRIB"[/color][/b][b][color=RED])[/color][/b][b][color=RED])[/color][/b][b][color=RED])[/color][/b]
   [b][color=RED]([/color][/b][b][color=BLUE]progn[/color][/b]
     [b][color=RED]([/color][/b][b][color=BLUE]redraw[/color][/b] cEnt [b][color=#009900]3[/color][/b][b][color=RED])[/color][/b]
     [b][color=RED]([/color][/b][b][color=BLUE]if[/color][/b] [b][color=RED]([/color][/b][b][color=BLUE]setq[/color][/b] ss [b][color=RED]([/color][/b][b][color=BLUE]ssget[/color][/b] [b][color=DARKRED]'[/color][/b][b][color=RED]([/color][/b][b][color=RED]([/color][/b][b][color=#009900]0[/color][/b] . [b][color=#ff00ff]"TEXT,MTEXT"[/color][/b][b][color=RED])[/color][/b][b][color=RED])[/color][/b][b][color=RED])[/color][/b][b][color=RED])[/color][/b]
       [b][color=RED]([/color][/b][b][color=BLUE]foreach[/color][/b] x  [b][color=RED]([/color][/b][b][color=BLUE]vl-remove-if[/color][/b] [b][color=DARKRED]'[/color][/b][b][color=BLUE]listp[/color][/b]
                     [b][color=RED]([/color][/b][b][color=BLUE]mapcar[/color][/b] [b][color=DARKRED]'[/color][/b][b][color=BLUE]cadr[/color][/b] [b][color=RED]([/color][/b][b][color=BLUE]ssnamex[/color][/b] ss[b][color=RED])[/color][/b][b][color=RED])[/color][/b][b][color=RED])[/color][/b]
         [b][color=RED]([/color][/b][b][color=BLUE]entmod[/color][/b] [b][color=RED]([/color][/b][b][color=BLUE]subst[/color][/b] [b][color=RED]([/color][/b][b][color=BLUE]assoc[/color][/b] [b][color=#009900]1[/color][/b] [b][color=RED]([/color][/b][b][color=BLUE]entget[/color][/b] cEnt[b][color=RED])[/color][/b][b][color=RED])[/color][/b]
                        [b][color=RED]([/color][/b][b][color=BLUE]assoc[/color][/b] [b][color=#009900]1[/color][/b] [b][color=RED]([/color][/b][b][color=BLUE]entget[/color][/b] x[b][color=RED])[/color][/b][b][color=RED])[/color][/b]
                        [b][color=RED]([/color][/b][b][color=BLUE]entget[/color][/b] x[b][color=RED])[/color][/b][b][color=RED])[/color][/b][b][color=RED])[/color][/b][b][color=RED])[/color][/b][b][color=RED])[/color][/b][b][color=RED])[/color][/b]
   [b][color=RED]([/color][/b][b][color=BLUE]princ[/color][/b] [b][color=#ff00ff]"\n<!> Incorrect Selection <!>"[/color][/b][b][color=RED])[/color][/b][b][color=RED])[/color][/b]
 [b][color=RED]([/color][/b][b][color=BLUE]command[/color][/b] [b][color=#ff00ff]"_regenall"[/color][/b][b][color=RED])[/color][/b]
 [b][color=RED]([/color][/b][b][color=BLUE]princ[/color][/b][b][color=RED])[/color][/b][b][color=RED])[/color][/b]
 

 

Thank you for this Mr. Lee!

How about if I also wanted not only to match the text but also match the match prop of the source text (specifically the color of the source text)? Could you please show me the way :(

Edited by AeJay
Link to comment
Share on other sites

53 minutes ago, BIGAL said:

If you look into the ssget filters (62 . 4) add  62 is dxf, 4 is color  so add (cons 62 4) or (cons 62 laycol)

HI, which of the 3 examples provided by Lee would you be referring to do this to?

Link to comment
Share on other sites

The example I posted applies to most code where Ssget is used and you can have multiple filters applied.

Examples

Object 

Object + Layer 

Object +  Layer + Color 

Object + Layer + Color + Linetype

Link to comment
Share on other sites

On 3/24/2023 at 8:03 AM, BIGAL said:

The example I posted applies to most code where Ssget is used and you can have multiple filters applied.

Examples

Object 

Object + Layer 

Object +  Layer + Color 

Object + Layer + Color + Linetype

Could you please teach me how to do it for this code?

 

(defun c:mt3  (/ cEnt ss)
 (vl-load-com)
 (if (and (setq cEnt (car (nentsel "\nSelect Source Text: ")))
          (member (cdr (assoc 0 (entget cEnt)))
                  '("TEXT" "MTEXT" "ATTRIB")))
   (progn
     (redraw cEnt 3)
     (if (setq ss (ssget '((0 . "TEXT,MTEXT"))))
       (foreach x  (vl-remove-if 'listp
                     (mapcar 'cadr (ssnamex ss)))
         (entmod (subst (assoc 1 (entget cEnt))
                        (assoc 1 (entget x))
                        (entget x))))))
   (princ "\n<!> Incorrect Selection <!>"))
 (command "_regenall")
 (princ))

 

Link to comment
Share on other sites

You can not mix a text mtext with an INSERT which is the holder for attributes so you could use ("TEXT","MTEXT","INSERT") then go through the selection looking for certain criteria like is it a block and has name xxxx then get its attributes.

Edited by BIGAL
Link to comment
Share on other sites

2 hours ago, BIGAL said:

It would be better if you post a dwg with before and after.

Below is a video of what I mean. It can convert some other texts, but I have no idea why it doesn't work for the one in white text.

Code I used:
 

(defun c:newmt (/ cEnt ss textColor)
  (vl-load-com)
  (if (and (setq cEnt (car (nentsel "\nSelect Source Text: ")))
           (member (cdr (assoc 0 (entget cEnt)))
                   '("TEXT" "MTEXT" "ATTRIB")))
    (progn
      (setq textColor (cdr (assoc 62 (entget cEnt))))
      (redraw cEnt 3)
      (if (setq ss (ssget '((0 . "TEXT,MTEXT"))))
        (foreach x  (vl-remove-if 'listp
                      (mapcar 'cadr (ssnamex ss)))
          (entmod (subst (assoc 1 (entget cEnt))
                         (assoc 1 (entget x))
                         (entmod (subst (cons 62 textColor) (assoc 62 (entget x)) (entget x)))))))
    )
  (command "_regenall")
  (princ))

 

 

 

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...