Results 1 to 6 of 6

Thread: Include MTEXT in old routine

  1. #1
    Member
    Join Date
    2006-06
    Location
    Southern California
    Posts
    31

    Default Include MTEXT in old routine

    Hello all, I have found a couple similar requests on here but haven't been able to actually make those suggestions work for my particular case. I have an old LISP routine that will take any number you enter and add it (enter a negative number to subtract) to any selection of DText. There's the rub, we don't really use DText anymore. So, below is my failed attempt at including MText. If you look at the beginning of the IF statement you'll see the things I've tried. I've also tried different variations of each line but so far I've come up with a big fat zero:

    Code:
    (defun C:ADD  (/ dec corr p l cnt txt newtxt putin chng tochng befr aftr
                   txtlen count count1)
    
       (setq p (ssget))
           (setq corr (getreal "\nEnter correction: "))
           (setq dec (getint "\nEnter decimal precision to maintain<2>: "))
           (if (= dec nil) (setq dec 2))
          (setq l 0 n (sslength p) count 0 count1 0)
    
          (while (< l n)
    
    ;        (if (= "TEXT"
     	 (if (cons 0 "Text,Mtext"
    ;	 (if (wcmatch (vla-get-objectname a) "AcDbText,AcDbMText"
                 (cdr (assoc 0 (setq e (entget (setq en (ssname p l)))))))
    
                (progn
                    (setq t 1 count (+ count 1))
                    (setq txt (cdr (assoc 1 (setq e (entget (ssname p l))))))
                    (setq txtlen (strlen txt) cnt 0)
    
                 (while (<= cnt txtlen)
                     (setq ltr (substr txt (+ 1 cnt) 1))
                     (setq nxtltr (substr txt (+ 2 cnt) 1))
                    (if (or (and (= ltr ".")
                                 (or (= nxtltr "0") (/= 0 (atoi nxtltr))))
                            (= ltr "0") (/= 0 (atoi ltr)))
                      (progn
                        (if tochng (setq tochng (strcat tochng ltr))
                                   (setq tochng ltr)
                        )
                        (setq cnt (+ cnt 1))
                      )
                      (progn
                        (if tochng
                            (if aftr (setq aftr (strcat aftr ltr))
                                   (setq aftr ltr)
                             )
                             (if befr (setq befr (strcat befr ltr))
                                   (setq befr ltr)
                            )
                         )
                        (setq cnt (+ cnt 1))
                      )
                    )
    
                 )
        (if tochng
            (progn
              (setq count1 (+ count1 1))
              (setq chng (rtos (+ (atof tochng) corr) 2 dec))
              (if (= befr nil) (setq befr ""))
              (setq newtxt (strcat befr chng aftr))
              (setq putin (cons 1 newtxt))
              (setq e (subst putin (assoc 1 (entget en)) (entget en)))
              (setq e (entmod e))
              (setq en (entupd en))
            )
         )
              (setq l (+ 1 l))
              (setq befr nil aftr nil tochng nil)
    
           )
           (setq l (+ 1 l))
    
             )
           )
    (princ)
    (prompt "Of the ")(princ count) (princ) (prompt " pieces of text selected, ")
    (princ count1) (prompt " were changed.") (princ)
    )

    Thank you to anybody and everybody that spends any time looking at this!
    --
    matthew g.

  2. #2
    Member
    Join Date
    2006-06
    Location
    Southern California
    Posts
    31

    Default Re: Include MTEXT in old routine

    I forgot to mention that the top line of the IF statement is the original (and functional) version, so to make the routine work uncomment:

    (if (= "TEXT"

    instead of the line below it.
    --
    matthew g.

  3. #3
    Certifiable AUGI Addict irneb's Avatar
    Join Date
    2007-07
    Location
    Jo'burg SA
    Posts
    4,344

    Default Re: Include MTEXT in old routine

    You could do it this way:
    Code:
    (if (wcmatch (cdr (assoc 0 (setq e (entget (setq en (ssname p l)))))) "TEXT,MTEXT")
      ;; Continue reading and/or modifying the text's dxf data
    Another alternative is to filter the selection set so it can only select Text or MText. Something like this:
    Code:
    (setq p (ssget '((0 . "TEXT,MTEXT"))))
    Consider though that your routine might fail if the user selects nothing. The sslength call will error since p=nil instead of a selection set. You might want to combine those 3 user inputs in an and block and only continue running your code if all three was input by the user. To go further, perhaps something like this:
    Code:
    (if (and (setq p (ssget '((0 . "TEXT,MTEXT"))))
             (setq corr (getreal "\nEnter correction: "))
             (or (setq dec (getint "\nEnter decimal precision to maintain<2>: ")) (setq dec 2)))
      (progn (setq l      0
                   n      (sslength p)
                   count  0
                   count1 0)
             (while (< l n)
               ;;; continued
    If something differs in the dxf codes between TEXT & MTEXT (say something like width), then you can use the if statement as previous. Or even more useful might be cond, since then it's much simpler to extend later for other entity types as well. The idea is as follows:
    Code:
    (cond ((eq (cdr (assoc 0 (setq e (entget (setq en (ssname p l)))))) "TEXT")
           ;; Do whatever for only TEXT
           )
          ((eq (cdr (assoc 0 e)) "MTEXT")
           ;; Do whatever for only MTEXT
           ;; Notice you don't need progn if you've got more than one statement
           )
          (t ;This is like the Else portion of an if,
             ;it's not needed but I'm sowing it for completeness
           ;; Do something else if none of the above
           ))
    Knowledge is proportional to experience, but wisdom is inversely proportional to ego!
    My little bit of "wisdom": Hind-sight is useless, unless used to improve the next forethought!

  4. #4
    Administrator Opie's Avatar
    Join Date
    2002-01
    Location
    jUSt Here (a lot)
    Posts
    6,836

    Default Re: Include MTEXT in old routine

    Irneb,

    The only downside in this particular code and using the cond function, is the variable "t" is being assigned a value. That is easy to fix, but just wanted to point it out.

    Opie
    If you have a technical question, please find the appropriate forum and ask it there.
    You will get a quicker response from your fellow AUGI members than if you sent it to me via a PM or email.
    jUSt

  5. #5
    Certifiable AUGI Addict irneb's Avatar
    Join Date
    2007-07
    Location
    Jo'burg SA
    Posts
    4,344

    Default Re: Include MTEXT in old routine

    Oh! Yes! Didn't notice that! It's also not localized - so it might cause some pain somewhere else.
    Knowledge is proportional to experience, but wisdom is inversely proportional to ego!
    My little bit of "wisdom": Hind-sight is useless, unless used to improve the next forethought!

  6. #6
    Member
    Join Date
    2006-06
    Location
    Southern California
    Posts
    31

    Default Re: Include MTEXT in old routine

    Thank you irneb, it works great. Right now I just used your first suggestion to get it working but I will add the contingency for an empty selection set once this particular task is done. You saved us lots of time and I appreciate it very much.
    --
    matthew g.

Similar Threads

  1. Replies: 4
    Last Post: 2011-04-07, 09:23 AM
  2. Replies: 1
    Last Post: 2007-09-28, 06:59 PM
  3. Replies: 6
    Last Post: 2007-04-23, 01:40 AM
  4. routine to remove stacked fraction from Mtext
    By jgardner.79905 in forum AutoLISP
    Replies: 1
    Last Post: 2006-10-26, 09:43 PM
  5. Replies: 9
    Last Post: 2005-07-18, 07:59 PM

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •