+ Reply to Thread
Results 1 to 7 of 7
  1. #1
    Junior Member
    Using
    AutoCAD 2008
    Join Date
    Mar 2012
    Location
    Mongolia
    Posts
    12

    Default add + symbol to positive values

    Registered forum members do not see this ad.

    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.

  2. #2
    Forum Deity MSasu's Avatar
    Discipline
    Construction
    MSasu's Discipline Details
    Occupation
    engineer
    Discipline
    Construction
    Details
    AutoLISP programmer
    Using
    AutoCAD 2013
    Join Date
    Mar 2009
    Location
    Brasov, Romania
    Posts
    3,000

    Default

    Something like this?
    Code:
    (strcat (if (> MyRealValue 0) "+" "") (rtos MyRealValue 2 3) "m")
    Regards,
    Mircea

    AutoCAD's happy user equation: FILEDIA + PICKADD² + PICKFIRST = 3

  3. #3
    Junior Member
    Using
    AutoCAD 2008
    Join Date
    Mar 2012
    Location
    Mongolia
    Posts
    12

    Default

    Quote Originally Posted by MSasu View Post
    Something like this?
    Code:
    (strcat (if (> MyRealValue 0) "+" "") (rtos MyRealValue 2 3) "m")

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

  4. #4
    Forum Deity Tharwat's Avatar
    Discipline
    Mechanical
    Tharwat's Discipline Details
    Occupation
    MEP AutoCAD Draftsman
    Discipline
    Mechanical
    Using
    AutoCAD 2014
    Join Date
    Oct 2009
    Location
    Lives in Abu Dhabi
    Posts
    2,627

    Default

    Check this out .....

    Code:
    (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)
    )
    - When aim is being settled in my mind , I have to reach it and get it in hand whatever it costs and wherever it is and will never give up . Tharwat said

  5. #5
    Forum Deity Tharwat's Avatar
    Discipline
    Mechanical
    Tharwat's Discipline Details
    Occupation
    MEP AutoCAD Draftsman
    Discipline
    Mechanical
    Using
    AutoCAD 2014
    Join Date
    Oct 2009
    Location
    Lives in Abu Dhabi
    Posts
    2,627

    Default

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

    Code:
    (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)
    )
    - When aim is being settled in my mind , I have to reach it and get it in hand whatever it costs and wherever it is and will never give up . Tharwat said

  6. #6
    Quantum Mechanic Lee Mac's Avatar
    Computer Details
    Lee Mac's Computer Details
    Operating System:
    Windows 7 Ultimate (32-bit)
    Discipline
    Multi-disciplinary
    Lee Mac's Discipline Details
    Discipline
    Multi-disciplinary
    Details
    Custom Programming / Software Customisation
    Using
    AutoCAD 2013
    Join Date
    Aug 2008
    Location
    London, England
    Posts
    15,718

    Default

    My version:

    Code:
    (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)
    )
    Lee Mac Programming

    With Mathematics there is the possibility of perfect rigour, so why settle for less?

    Just another Swamper

  7. #7
    Junior Member
    Using
    AutoCAD 2008
    Join Date
    Mar 2012
    Location
    Mongolia
    Posts
    12

    Default

    Registered forum members do not see this ad.

    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

Similar Threads

  1. Help!! Decimal place values of Integers in a Lisp, importing values from excel
    By loveboatcaptain in forum AutoLISP, Visual LISP & DCL
    Replies: 4
    Last Post: 8th Feb 2012, 11:33 pm
  2. Import points with " symbol (that would be the inch symbol)
    By wrmurphy81 in forum Civil 3D & LDD
    Replies: 6
    Last Post: 11th Oct 2010, 03:08 am
  3. Positive list values
    By Small Fish in forum AutoLISP, Visual LISP & DCL
    Replies: 6
    Last Post: 15th Jun 2009, 01:05 am
  4. How to convert Latitude / Longitude values in to Northing / Easting values in meters
    By Chenna Siva Koteswara rao in forum AutoCAD 2D Drafting, Object Properties & Interface
    Replies: 2
    Last Post: 28th Dec 2008, 11:09 pm
  5. still not going into positive xyz octant!!!
    By Sanne03 in forum AutoCAD 3D Modelling & Rendering
    Replies: 2
    Last Post: 4th Dec 2008, 01:55 am

Bookmarks

Posting Permissions

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