See the top rated post in this thread. Click here

Results 1 to 8 of 8

Thread: Rounding text to nearest 5 - values inside text

  1. #1
    Active Member
    Join Date
    2011-10
    Posts
    83
    Login to Give a bone
    0

    Default Rounding text to nearest 5 - values inside text

    Dear users,

    do you have any routine that can round text to the nearest values?
    I have a lots of texts in autocad (not mtext, if importatnt), there are values inside text (only values, no additional text or symbols), I need to round all of them to the nearest 5 (eg. 122 -> 120 or 123->125).
    Do you have any idea?

    Thanks in advance!

  2. #2
    Certifiable AUGI Addict
    Join Date
    2001-03
    Location
    Tallahassee, FL USA
    Posts
    3,667
    Login to Give a bone
    0

    Default Re: Rounding text to nearest 5 - values inside text


  3. #3
    Active Member
    Join Date
    2011-10
    Posts
    83
    Login to Give a bone
    0

    Default Re: Rounding text to nearest 5 - values inside text

    not realy, these codes erase unnecessary zeros from the end of number (eg. 123.00 -> 123 or 21.40 -> 21.4), did not round up or down...
    but thanks for replay!

  4. #4
    I could stop if I wanted to
    Join Date
    2002-08
    Posts
    231
    Login to Give a bone
    0

    Default Re: Rounding text to nearest 5 - values inside text

    With this?

    Code:
    (defun round_number (xr n / )
      (* (fix (atof (rtos (/ xr (float n)) 2 0))) n)
    )
    Model use:
    (round_number 122 5) ->120
    (round_number 123 5) ->125

    or (round_number 123.123 0.005) -> 123.125

  5. #5
    Active Member
    Join Date
    2011-10
    Posts
    83
    Login to Give a bone
    0

    Default Re: Rounding text to nearest 5 - values inside text

    thanks Bruno, but I have no idea how to use it I am poor in routines
    can you help and provide full code? please...
    How to change in code rounding method, eg. I would like to round up to nearest 5 or 0.5...?
    thanks in advance!

  6. #6
    Certifiable AUGI Addict
    Join Date
    2001-03
    Location
    Tallahassee, FL USA
    Posts
    3,667
    Login to Give a bone
    0

    Default Re: Rounding text to nearest 5 - values inside text

    Quote Originally Posted by Arterius View Post
    not realy, these codes erase unnecessary zeros from the end of number (eg. 123.00 -> 123 or 21.40 -> 21.4), did not round up or down...
    but thanks for replay!
    C3PO rounds to two decimal places, just change the 2 on the line 21 to 0 and it should do as you want.
    For 2dp change (rtos item 2 2) to (rtos item 2 0)

  7. #7
    I could stop if I wanted to
    Join Date
    2002-08
    Posts
    231
    Login to Give a bone
    1

    Default Re: Rounding text to nearest 5 - values inside text

    Try this
    Code:
    (defun round_number (xr n / )
      (* (fix (atof (rtos (/ xr (float n)) 2 0))) n)
    )
    (defun c:round_text ( / js dxf_cod mod_sel n round lremov ename)
      (princ "\nSelect an model object text for filtering: ")
      (while
        (null
          (setq js
            (ssget "_+.:E:S"
              (list
                '(0 . "*TEXT")
                (cons 67 (if (eq (getvar "CVPORT") 1) 1 0))
                (cons 410 (if (eq (getvar "CVPORT") 1) (getvar "CTAB") "Model"))
              )
            )
          )
        )
        (princ "\nIsn't an object available for this fonction!")
      )
      (vl-load-com)
      (setq dxf_cod (entget (ssname js 0)))
      (foreach m (foreach n dxf_cod (if (not (member (car n) '(0 67 410 8 6 62 48 420 70))) (setq lremov (cons (car n) lremov))))
        (setq dxf_cod (vl-remove (assoc m dxf_cod) dxf_cod))
      )
      (initget "Single All Manual")
      (if (eq (setq mod_sel (getkword "\nSelection filtered by, [Single/All/Manual]<Manual>: ")) "Single")
        (setq n -1)
        (if (eq mod_sel "All")
            (setq js (ssget "_X" dxf_cod) n -1)
            (setq js (ssget dxf_cod) n -1)
        )
      )
      (initget 1)
      (setq round (getreal "\nRound up to near at?: "))
      (repeat (sslength js)
        (setq ename (vlax-ename->vla-object (ssname js (setq n (1+ n)))))
        (if (vlax-property-available-p ename 'TextString)
          (cond
            ((eq (type (setq value (read (vlax-get ename 'TextString)))) 'REAL)
              (vlax-put ename 'TextString (rtos (round_number value round) 2 2))
            )
            ((eq (type value) 'INT)
              (vlax-put ename 'TextString (rtos (round_number value round) 2 0))
            )
          )
        )
      )
      (prin1)
    )

  8. #8
    Active Member
    Join Date
    2011-10
    Posts
    83
    Login to Give a bone
    0

    Default Re: Rounding text to nearest 5 - values inside text

    Thanks a lot for routine!
    Works perfect.

Similar Threads

  1. 2013: Rounding to nearest .5 in schedules
    By jplatte in forum Revit MEP - General
    Replies: 8
    Last Post: 2013-04-08, 06:30 PM
  2. Rounding up, down or to nearest... any interval
    By DoTheBIM in forum Revit Architecture - General
    Replies: 11
    Last Post: 2013-03-20, 03:07 PM
  3. Rounding to the nearest integer in Tables
    By kkinchen in forum AutoCAD Tables
    Replies: 1
    Last Post: 2007-04-26, 04:23 PM
  4. Rounding up to the nearest 5
    By ReachAndre in forum AutoLISP
    Replies: 7
    Last Post: 2007-01-29, 06:56 PM
  5. Rounding Text Values
    By martyk in forum AutoLISP
    Replies: 8
    Last Post: 2006-04-11, 01:30 PM

Posting Permissions

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