Jump to content

Coding Help - Adding numbers to text


Piper

Recommended Posts

Here's what I have:

 

;;===================================================================
(if (eq "AcDbText" (vla-get-objectname obj))
   (if (wcmatch (setq st (vla-get-textstring obj)) "EL +0'*")
     (vla-put-textstring obj (Replace "EL +0" "EL +845" st))
   )
)
(if (eq "AcDbText" (vla-get-objectname obj))
   (if (wcmatch (setq st (vla-get-textstring obj)) "EL +1'*")
     (vla-put-textstring obj (Replace "EL +1" "EL +846" st))
   )
)
(if (eq "AcDbText" (vla-get-objectname obj))
   (if (wcmatch (setq st (vla-get-textstring obj)) "EL +2'*")
     (vla-put-textstring obj (Replace "EL +2" "EL +847" st))
   )
)
(if (eq "AcDbText" (vla-get-objectname obj))
   (if (wcmatch (setq st (vla-get-textstring obj)) "EL +3'*")
     (vla-put-textstring obj (Replace "EL +3" "EL +848" st))
   )
)
(if (eq "AcDbText" (vla-get-objectname obj))
   (if (wcmatch (setq st (vla-get-textstring obj)) "EL +4'*")
     (vla-put-textstring obj (Replace "EL +4" "EL +849" st))
   )
)
(if (eq "AcDbText" (vla-get-objectname obj))
   (if (wcmatch (setq st (vla-get-textstring obj)) "EL +5'*")
     (vla-put-textstring obj (Replace "EL +5" "EL +850" st))
   )
)
(if (eq "AcDbText" (vla-get-objectname obj))
   (if (wcmatch (setq st (vla-get-textstring obj)) "EL +6'*")
     (vla-put-textstring obj (Replace "EL +6" "EL +851" st))
   )
)
(if (eq "AcDbText" (vla-get-objectname obj))
   (if (wcmatch (setq st (vla-get-textstring obj)) "EL +7'*")
     (vla-put-textstring obj (Replace "EL +7" "EL +852" st))
   )
)
(if (eq "AcDbText" (vla-get-objectname obj))
   (if (wcmatch (setq st (vla-get-textstring obj)) "EL +8'*")
     (vla-put-textstring obj (Replace "EL +8" "EL +853" st))
   )
)
(if (eq "AcDbText" (vla-get-objectname obj))
   (if (wcmatch (setq st (vla-get-textstring obj)) "EL +9'*")
     (vla-put-textstring obj (Replace "EL +9" "EL +854" st))
   )
)
(if (eq "AcDbText" (vla-get-objectname obj))
   (if (wcmatch (setq st (vla-get-textstring obj)) "EL +10'*")
     (vla-put-textstring obj (Replace "EL +10" "EL +855" st))
   )
)
;;===================================================================

 

What I am trying to accomplish is this:

 

I want it to find EL +10' for example and add 845' to it, or more specifically. Find x' and add x'+845' to it.

 

Also, I want the new text to be placed on a layer called 'ISOMOD'

 

Thanks for your help.

Link to comment
Share on other sites

  • Replies 37
  • Created
  • Last Reply

Top Posters In This Topic

  • alanjt

    12

  • SteveBubendorf

    7

  • Piper

    5

  • Lee Mac

    4

:unsure:

 

(defun c:Test (/ ss ent s)
 (and
   (setq ss (ssget "_:L" '((0 . "TEXT") (1 . "EL +*"))))
   ((lambda (i)
      (while (setq e (ssname ss (setq i (1+ i))))
        (setq ent (entget e))
        (foreach n '(0 1 2 3 4 5 6 7 8 9 10)
          (if (vl-string-search (setq s (strcat "EL +" (itoa n) "'")) (cdr (assoc 1 ent)))
            (entmod
              (subst
                (cons 1
                      (vl-string-subst (strcat "EL +" (itoa (+ n 845)) "'") s (cdr (assoc 1 ent)))
                )
                (assoc 1 ent)
                ent
              )
            )
          )
        )
      )
    )
     -1
   )
 )
 (princ)
)

Link to comment
Share on other sites

:unsure:

 

(defun c:Test (/ ss ent s)
 (and
   (setq ss (ssget "_:L" '((0 . "TEXT") (1 . "EL +*"))))
   ((lambda (i)
      (while (setq e (ssname ss (setq i (1+ i))))
        (setq ent (entget e))
        (foreach n '(0 1 2 3 4 5 6 7 8 9 10)
          (if (vl-string-search (setq s (strcat "EL +" (itoa n) "'")) (cdr (assoc 1 ent)))
            (entmod
              (subst
                (cons 1
                      (vl-string-subst (strcat "EL +" (itoa (+ n 845)) "'") s (cdr (assoc 1 ent)))
                )
                (assoc 1 ent)
                ent
              )
            )
          )
        )
      )
    )
     -1
   )
 )
 (princ)
)

 

This didn't work. My text is in the format: EL +27'-0 15/16 for example (It appears your code tries to add 845 to 27'-0 15/16" which doesnt work). I'm guessing it needs to find the 27 in the string and add 845 to it. What I did above is to search for EL +1'* to EL +99'* and add 845' to it, but another LISP I have needs 845'-6" added to the number. Also, After the operation is complete, I need it placed on the 'ISOMOD' layer.

 

Basically, I'm looking for a way to simplify the code so I don't have to search for EL +1'*, EL +2'*, EL +3'*, etc (I'm always replacing values at the beginning of the string if that helps)... Plus trying to move the updated text value to the 'ISOMOD' layer.

Link to comment
Share on other sites

This didn't work. My text is in the format: EL +27'-0 15/16 for example (It appears your code tries to add 845 to 27'-0 15/16" which doesnt work). I'm guessing it needs to find the 27 in the string and add 845 to it. What I did above is to search for EL +1'* to EL +99'* and add 845' to it, but another LISP I have needs 845'-6" added to the number. Also, After the operation is complete, I need it placed on the 'ISOMOD' layer.

 

Basically, I'm looking for a way to simplify the code so I don't have to search for EL +1'*, EL +2'*, EL +3'*, etc (I'm always replacing values at the beginning of the string if that helps)... Plus trying to move the updated text value to the 'ISOMOD' layer.

 

It works based on the information you provided.

If you could construct the above coding, you should be able to take what I have and run with it. Give it a shot instead of rudely telling me that my help doesn't work.

Link to comment
Share on other sites

My apologies, being percieved as rude was not the intention. Thanks for your help.

 

Apology accepted. However, if you want proper help, you have to give ALL the information up front.

 

Give this a try...

(defun c:Test (/ ss ent s num)
 (and
   (setq ss (ssget "_:L" '((0 . "TEXT") (1 . "EL +*"))))
   ((lambda (i)
      (while (setq e (ssname ss (setq i (1+ i))))
        (setq ent (entget e)
              s   (cdr (assoc 1 ent))
              num (substr s (+ 2 (vl-string-search "+" s)) (- (vl-string-search "'" s) 4))
        )
        (entmod (subst (cons 1 (vl-string-subst (itoa (+ 845 (atoi num))) num s))
                       (assoc 1 ent)
                       ent
                )
        )
      )
    )
     -1
   )
 )
 (princ)
)

Link to comment
Share on other sites

Apology accepted. However, if you want proper help, you have to give ALL the information up front.

 

Give this a try...

(defun c:Test (/ ss ent s num)
 (and
   (setq ss (ssget "_:L" '((0 . "TEXT") (1 . "EL +*"))))
   ((lambda (i)
      (while (setq e (ssname ss (setq i (1+ i))))
        (setq ent (entget e)
              s   (cdr (assoc 1 ent))
              num (substr s (+ 2 (vl-string-search "+" s)) (- (vl-string-search "'" s) 4))
        )
        (entmod (subst (cons 1 (vl-string-subst (itoa (+ 845 (atoi num))) num s))
                       (assoc 1 ent)
                       ent
                )
        )
      )
    )
     -1
   )
 )
 (princ)
)

 

Nice work:

EL +50'-6" +845 >> EL +895'-6" fine

but

EL +50.5' +845 >> +895' ??

 

help us carpenter challenged measurement guys out !!

civils don't use those dumb rulers !!

give me a hint to revise prog

Steve

Link to comment
Share on other sites

I'd think you could change this:

 

(vl-string-search "'" s)

 

To this:

 

(vl-string-search "." s)

 

But, I haven't tested it and I've just started learning recently...

Link to comment
Share on other sites

Nice work:

EL +50'-6" +845 >> EL +895'-6" fine

but

EL +50.5' +845 >> +895' ??

 

help us carpenter challenged measurement guys out !!

civils don't use those dumb rulers !!

give me a hint to revise prog

Steve

I'm such a retard. I was converting to an integer instead of a real.

 

Untested...

(defun c:Test (/ ss ent s num)
 (and
   (setq ss (ssget "_:L" '((0 . "TEXT") (1 . "EL +*"))))
   ((lambda (i)
      (while (setq e (ssname ss (setq i (1+ i))))
        (setq ent (entget e)
              s   (cdr (assoc 1 ent))
              num (substr s (+ 2 (vl-string-search "+" s)) (- (vl-string-search "'" s) 4))
        )
        (entmod (subst (cons 1 (vl-string-subst (rtos (+ 845. (atof num))) num s))
                       (assoc 1 ent)
                       ent
                )
        )
      )
    )
     -1
   )
 )
 (princ)
)

You might have to play with the units...

Link to comment
Share on other sites

Works great. Could you show me how to make it work with all the text in the drawing and not just a selection set? Thanks.

 

Change "_:L" to "_X" :)

 

There you go. :) Know that if you change to all, locked layers will NOT be filtered out and it will error if it tries to edit text on a locked layer.

 

 

Nice one Alan :thumbsup:

:) Thanks Lee.

Link to comment
Share on other sites

I'm such a retard. I was converting to an integer instead of a real.

 

Untested...

(defun c:Test (/ ss ent s num)
 (and
   (setq ss (ssget "_:L" '((0 . "TEXT") (1 . "EL +*"))))
   ((lambda (i)
      (while (setq e (ssname ss (setq i (1+ i))))
        (setq ent (entget e)
              s   (cdr (assoc 1 ent))
              num (substr s (+ 2 (vl-string-search "+" s)) (- (vl-string-search "'" s) 4))
        )
        (entmod (subst (cons 1 (vl-string-subst (rtos (+ 845. (atof num))) num s))
                       (assoc 1 ent)
                       ent
                )
        )
      )
    )
     -1
   )
 )
 (princ)
)

You might have to play with the units...

 

 

Perfect, thx, S

Link to comment
Share on other sites

  • 6 months later...

Alan,

I have been trying to modify this code to add a user input elevation to the selected elevation, but I haven't been able to make it work. If it isn't too time-consuming, could you look at the code below (modified from your code), and suggest corrections as required? My elevations will be in the form of "El. xxx'-xx" ", without the outer quotation marks. The number of digits in the feet and in the inches may change.

Thank you.

 

 


(defun c:AddElevations (/ ss ent s num addelev);addelev added by SLB

(and
   (setq AddElev (getdist "\n Enter Elevation to Add: 
"));;setq addelev added by SLB
   (setq ss (ssget "_:L" '((0 . "TEXT") (1 . 
"EL.*"))))
   ((lambda 
(i)
      (while (setq e (ssname ss (setq i 
(1+ i))))
        (setq ent (entget 
e)

s   (cdr (assoc 1 
ent))

num (substr s (+ 3 (vl-string-search "." s)) (+ (vl-string-search "'" s) 
3));substring parameters and search string changed by SLB

)
        (entmod (subst (cons 1 
(vl-string-subst (rtos (+ AddElev (atof num))) num 
s));AddElev variable substituted for fixed number by SLB

(assoc 1 
ent)

ent

)

)
      )

)
     -1
   )

)
 (princ)
)

Link to comment
Share on other sites

I think I had some trouble logging into the forum for a while. (Misplaced my password or something after an OS reinstall.) I refer to AutoDesk's Discussion Groups for a lot of my Lisp referencing needs, and have posted there quite a bit requesting and sometimes even providing some help. I've been referencing this forum for the last couple of months quite heavily. I sure appreciate your posts and LeeMac's, in particular, although there a lot of other great contributors here, as well. I've been "dabbling" in Lisp for a number of years now, but I haven't grasped the "weightier" concepts. I barely manage to eek out some short "macros" more than fully developed programs. I love to see (and use, when possible) the great stuff on this and other forums that I tend to watch as much as possible.

 

Was my request something "do-able", or was the program which I was trying to adapt not the best way to solve the problem? I think I may have a Lisp program that does something similar to what I requested, but I liked the Visual Lisp. Unfortunately, I'm really poor with the Visual Lisp.

 

Thanks, Alan !!

Link to comment
Share on other sites

Ehh, WTH...

 

(defun c:Add (/ toNum toStr ss add)
 ;; Alan J. Thompson, 11.04.10

 (defun toNum (str)
   (+ (atof (substr str 4)) (/ (atof (substr str (+ 2 (vl-string-search "-" str)))) 12.))
 )

 (defun toStr (num)
   (strcat "EL." (rtos num 2 0) "'-" (rtos (* 12. (rem num (fix num))) 2 0) "\"")
 )

 (if (and (setq ss (ssget "_:L" '((0 . "TEXT") (1 . "EL.*'-*\""))))
          (setq add (getdist "\nSpecify number to add: "))
     )
   ((lambda (i / e d)
      (while (setq e (ssname ss (setq i (1+ i))))
        (entmod (subst (cons 1 (toStr (+ add (toNum (cdr (assoc 1 (setq d (entget e))))))))
                       (assoc 1 d)
                       d
                )
        )
      )
    )
     -1
   )
 )
 (princ)
)

Link to comment
Share on other sites

Thank you, Alan !! That was unbelievably quick ! "Forum Deity", you are !

 

I didn't get the results that I expected with the elevations that I tested on, but I will continue to look at your post and see if I can understand it enough to make changes. It may be units settings or something that may be giving us different results, perhaps? Anyway, this wasn't a program that I needed at this time, but rather, an example that I hoped to learn from. I'll do some more study and see what I can come up with.

 

Thanks, again !!

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