Jump to content

add + symbol to positive values


CADWORKER

Recommended Posts

Hai Dudes,

 

I have been looking for a code that will set the decimals to 3 and add a prefix "+" to all positive values and "m" as suffix for all the selected text.

 

ex. -3

-3.002

5.01

5.005

the output should be

-3.000m

-3.002m

+5.010m

+5.005m

 

Thanks for your help in advance.

Link to comment
Share on other sites

  • 2 weeks later...
Something like this?

(strcat (if (> MyRealValue 0) "+" "") (rtos MyRealValue 2 3) "m")

 

 

Iam new to coding so if anyone can write a small lisp for this.

Link to comment
Share on other sites

Check this out ..... :)

 

(defun c:Test (/ ss i sn str e) (vl-load-com)
 ;;; Tharwat 08. May. 2012 ;;;
 (if (setq ss (ssget "_:L" '((0 . "TEXT,MTEXT"))))
   (repeat (setq i (sslength ss))
     (setq sn (ssname ss (setq i (1- i))))
     (if
       (and (not
              (eq 45
                  (nth 0
                       (vl-string->list
                         (setq str (cdr (assoc 1 (setq e (entget sn)))))
                       )
                  )
              )
            )
            (numberp (read str))
       )
        (entmod
          (subst (cons 1 (strcat "+" (rtos (read str) 2 3) "m"))
                 (assoc 1 e)
                 e
          )
        )
     )
   )
   (princ)
 )
 (princ)
)

Link to comment
Share on other sites

I forgot to change the decimal values of minus values , so try this if it is better for you... :)

 

(defun c:Test (/ ss i sn str e)
 (vl-load-com)
;;; Tharwat 08. May. 2012 ;;;
 (if (setq ss (ssget "_:L" '((0 . "TEXT,MTEXT"))))
   (repeat (setq i (sslength ss))
     (setq sn (ssname ss (setq i (1- i))))
     (setq str (cdr (assoc 1 (setq e (entget sn)))))
     (cond ((and (not
                   (eq 45
                       (nth 0
                            (vl-string->list
                              str
                            )
                       )
                   )
                 )
                 (numberp (read str))
            )
            (entmod
              (subst (cons 1 (strcat "+" (rtos (read str) 2 3) "m"))
                     (assoc 1 e)
                     e
              )
            )
           )
           ((and (eq 45 (nth 0 (vl-string->list str)))
                 (numberp (read str))
            )
            (entmod
              (subst (cons 1 (rtos (read str) 2 3))
                     (assoc 1 e)
                     e
              )
            )
           )
     )
   )
   (princ)
 )
 (princ)
)


Link to comment
Share on other sites

My version:

 

(defun c:fixtxt ( / d e i s x ) ;; Lee Mac 2012
   (setq d (getvar 'dimzin))
   (setvar 'dimzin 0)
   (if (setq s (ssget "_:L" '((0 . "TEXT,MTEXT") (1 . "*#*"))))
       (repeat (setq i (sslength s))
           (setq e (entget (ssname s (setq i (1- i)))))
           (if (setq x (distof (cdr (assoc 1 e))))
               (setq x (strcat (if (< 0 x) "+" "") (rtos x 2 3) "m")
                     e (entmod (subst (cons 1 x) (assoc 1 e) e))
               )
           )
       )
   )
   (setvar 'dimzin d)
   (princ)
)

Link to comment
Share on other sites

Thanks lee and sorry for the delay. I just get very little access to internet during office hours.

 

This is all my requirements,

 

Thanks to all for their efforts and contributions

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