Jump to content

Match Text LISP


Zorg

Recommended Posts

I've got a LISP for matching text and attributes but it doesn't work for MTEXT. Can anyone rectify it for me? :oops: It's in another language too, so i supose this doesn't help :lol:

 

(defun UNDO-BEGIN ()
(command "UNDO" "BEGIN")
)
(defun UNDO-EIND ()
(command "UNDO" "END")
)
(defun ERRHAND (MSG)
(if  (/= MSG "Function cancelled")
(progn
      (princ (strcat "\nFunction terminated" ))
 (setvar "SNAPMODE" OUDE-SNAP)
 (redraw)
 (setq *ERROR* OUDE-ERR)
 (UNDO-EIND)
 (princ)
)
)
)
(defun ERR-BEGIN ()
(setvar "CMDECHO" 0)
(setq  OUDE-ERR *ERROR*
*ERROR* ERRHAND
)
)
(defun ERR-EIND ()
(setq *ERROR* OUDE-ERR)
(princ)
)
(defun C:MT ( / 
             BRON_ENT ; bron-entiteit
             BRON_TEKST  ; tekst van de bron-entiteit
             BRON_SEL             ; selectiegegevens van bron-entiteit
             BRONPUNT ; beginpunt van aanduidingslijn
             DOEL_ENT ; doel-entiteit
             DOELPUNT   ; selectiepunt van doel-entiteit
             LIJNTELLER ; teller die de zichtbaarheid van de aanduidingslijn regelt
             LIJNVLAG              ; regelt het einde van de aanduidingslijn
             MATCHVLAG          ; regelt het herhelen van doel-entiteit
             SURSORPUNT        ; eindpunt van aanduidingslijn
OUDE-SNAP ; snap-instelling
OUDE-ERR ; error-instelling
)
(ERR-BEGIN)
(UNDO-BEGIN)
(setq OUDE-SNAP (getvar "SNAPMODE"))
(setvar "SNAPMODE" 0) 
(setq BRON_SEL (nentsel "\nSelect source text or attribute.")
BRONPUNT (car (cdr BRON_SEL))
BRON_ENT (car BRON_SEL)
LIJNTELLER 0 
        MATCHVLAG T
) 
(if  (AND (/= (cdr (assoc 0 (entget BRON_ENT))) "ATTRIB")
     (/= (cdr (assoc 0 (entget BRON_ENT))) "TEXT"))
    (princ  "  Entity must be a text or attribute !")
(progn
        (setq  BRON_TEKST (cdr (assoc 1 (entget BRON_ENT))))
        (while  MATCHVLAG 
           (setq  CURSORPUNT nil
                 LIJNVLAG T
  )
           (princ  "\n Select text or attribute to change. ")
         (while  LIJNVLAG
               (setq  CURSORPUNT (grread T 5 2))    
               (if  (= 11 (car CURSORPUNT))
                  (progn
                      (setq MATCHVLAG nil)
                      (redraw)
                  )
                  (setq MATCHVLAG T)
               )
               (setq  DOELPUNT (car (cdr CURSORPUNT)))
               (grdraw BRONPUNT DOELPUNT 7)                           ;7=wit
               (if  (= (/ LIJNTELLER 3.0)(/ LIJNTELLER 3))
    (redraw)
   )
               (setq  LIJNTELLER (+ LIJNTELLER 1))
               (if  (= LIJNTELLER 1000)
    (setq LIJNVLAG nil)
   )
               (if  (= 3 (car CURSORPUNT))
                  (progn 
                      (setq LIJNVLAG nil)
                      (redraw)
                  )                      
               )
           )
           (if  (= nil (setq DOEL_ENT (car (nentselp DOELPUNT))))
               (princ  "  Nothing selected, retry !")
               (progn
                  (if  (AND (/= (cdr (assoc 0 (entget DOEL_ENT))) "ATTRIB")
                                (/= (cdr (assoc 0 (entget DOEL_ENT))) "TEXT")
     )
                      (princ "  No text or attribute selected, retry !")
                   (progn (setq DOEL_ENT (entget DOEL_ENT))
                          (entmod (subst (cons 1 BRON_TEKST)(assoc 1 DOEL_ENT) DOEL_ENT ))
                          (entupd (cdr (assoc -1 DOEL_ENT)))
                     )
                  )
               )
           )
        )
    )
)
(setvar "SNAPMODE" OUDE-SNAP)
(UNDO-EIND) 
(ERR-EIND) 
) ; defun C:MATCHTXT

 

Z

Link to comment
Share on other sites

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]

  • Thanks 1
Link to comment
Share on other sites

  • 7 years later...

Thanks Mr. Lee for the Lisp

You are a Bruce Lee in Programming ;) fast and quickee......

 

 

 

"The more you give, The more you earn" (my grandpa's saying's)

 

You are one of them

GOD BLESS YOU

Link to comment
Share on other sites

  • 2 years later...
On 5/11/2009 at 9: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]
 

 

Hi Lee ... I was hoping to give this a go - but why do all the lsp options you post look like gibberish? I am i missing something ... doing something wrong?

cheers

Link to comment
Share on other sites

Here is that code without BBCode Tags :

 


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



(defun c:mt2  (/ cEnt mEnt sLst)
 (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 "_X" '((-4 . "<NOT") (0 . "TEXT,MTEXT,INSERT") (-4 . "NOT>"))))
       (mapcar '(lambda (x) (redraw x 2)) (setq sLst (mapcar 'cadr (ssnamex ss)))))
     (while (and (setq mEnt (car (nentsel "\nSelect Destination Text: ")))
                 (member (cdr (assoc 0 (entget mEnt)))
                         '("TEXT" "MTEXT" "ATTRIB")))
       (entmod (subst (assoc 1 (entget cEnt))
                      (assoc 1 (entget mEnt))
                      (entget mEnt)))))
   (princ "\n<!> Incorrect Selection <!>"))
 (command "_regenall")
 (princ))



(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))

HTH., M.R.

  • Like 2
Link to comment
Share on other sites

7 hours ago, masondino2 said:

Hi Lee ... I was hoping to give this a go - but why do all the lsp options you post look like gibberish? I am i missing something ... doing something wrong?

cheers

 

This is caused by the new forum software no longer supporting the use of BBCode (forum formatting) within code blocks, so the BBCode is now displayed.

Link to comment
Share on other sites

On ‎1‎/‎17‎/‎2019 at 12:48 PM, Lee Mac said:

 

This is caused by the new forum software no longer supporting the use of BBCode (forum formatting) within code blocks, so the BBCode is now displayed.

 Is there a quick and simple way to change it to normal like Marko_ribar did? (say copy to a text file or something?)

Link to comment
Share on other sites

  • 3 years later...

Hi all

 

Could someone help me to tweak this great mt.lisp , please.

I am looking to add additional code which could keep prefixes when match number content.

 

For example I have any text and number IL1.50 . I would like to match only number content 95.40 to get IL95.40

 

Many thanks for help!

Link to comment
Share on other sites

6 hours ago, Paulsub said:

Hi all

 

Could someone help me to tweak this great mt.lisp , please.

I am looking to add additional code which could keep prefixes when match number content.

 

For example I have any text and number IL1.50 . I would like to match only number content 95.40 to get IL95.40

 

Many thanks for help!

Please upload yoursample.dwg with before and after

 

Link to comment
Share on other sites

3 hours ago, mhupp said:

Might need a 3rd lisp

https://www.theswamp.org/index.php?topic=53496.msg584464#msg584464

 

(SplitStrToStrAndNumbers "CL1.06")
("CL" 1.06)

 

*do math stuff

join back togther

CL1.72

 

Thank you mhupp for your good idea. Text should  not be set specifically to CL,IL,WL etc... it could be anything, somehow text needs to be ignored and matched only numbers. 

 

I am new to lisp editing, but trying to learn.

Edited by Paulsub
Link to comment
Share on other sites

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"))))))))

 

Edited by BIGAL
Link to comment
Share on other sites

  • 3 weeks later...

Hi guys

 

Is there a way to change ''Place result''  to ''replace result'' 

 

 "_button  : image_button { width = 8.33; height = 3.85; fixed_width = true; fixed_height = true; alignment = centered; color = -15; }"

     

 

        ""

              "textcalc : dialog { key = \"dcltitle\"; spacer;"

              "  : row {"

              "    : _button { label = \"+\"; key = \"+\"; }"

              "    : _button { label = \"-\"; key = \"-\"; }"

              "    : _button { label = \"×\"; key = \"*\"; }"

              "    : _button { label = \"÷\"; key = \"/\"; }"

              "  }"

              "  spacer;"

              "  : button { key = \"accept\"; label = \"Place Result >>\"; is_default = true; height = 2; fixed_height = true; }"

              "  : button { key = \"cancel\"; label = \"Cancel\";           is_cancel = true; }"

              "}"

            )

 

 

instead placing result anywhere, I would need to replace existing text  for example  SL1.10 replace with a  ''place result'' content?

 

Link to comment
Share on other sites

Is there  a way to adjust this script so its not eliminating specific prefixes when matching content? for exampe: IL1.10  SL1.10  etc.. 

Currently its replacing and leaving 1.10

 


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



(defun c:mt2  (/ cEnt mEnt sLst)
 (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 "_X" '((-4 . "<NOT") (0 . "TEXT,MTEXT,INSERT") (-4 . "NOT>"))))
       (mapcar '(lambda (x) (redraw x 2)) (setq sLst (mapcar 'cadr (ssnamex ss)))))
     (while (and (setq mEnt (car (nentsel "\nSelect Destination Text: ")))
                 (member (cdr (assoc 0 (entget mEnt)))
                         '("TEXT" "MTEXT" "ATTRIB")))
       (entmod (subst (assoc 1 (entget cEnt))
                      (assoc 1 (entget mEnt))
                      (entget mEnt)))))
   (princ "\n<!> Incorrect Selection <!>"))
 (command "_regenall")
 (princ))



(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

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...