+ Reply to Thread
Results 1 to 5 of 5
  1. #1
    Forum Newbie
    Discipline
    Mechanical
    Using
    AutoCAD 2017
    Join Date
    Aug 2017
    Posts
    1

    Default Need LISP Function to read text contents and convert ratio to number.

    Registered forum members do not see this ad.

    I have a vector map of a floor and all i am given are vectors and grade ratios (i.e. 1:155.095, 1:97.561) of the floor. The problem is that I only want to look at the areas of the floor that are below a certain grade ratio (1:69), but they are ratios set as Text Contents so AutoCAD doesnt understand that these ratios are numbers.

    I am looking for a Lisp function that, for each text if a ratio across an entire floor (or the layout), copy the text (which is a ratio), find out the number that the ratio is (i.e. take the 1 and divide by 69), then replace the text with just the number (0.0145). I want this to do this for every instance, and there are over 37,000 of these texts on the floor in question.

    I have attached an image that depicts what I have in the layout.

    Does anyone know of a lisp function that can do this?
    Attached Images

  2. #2
    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
    19,322

    Default

    Quickly written:
    Code:
    (defun c:fixratios ( / a b e i p s x )
        (if (setq s (ssget "_:L" '((0 . "TEXT")(1 . "#*:#*")(1 . "~*[~.:0-9]*")(1 . "~*:*:*"))))
            (repeat (setq i (sslength s))
                (setq e (entget (ssname s (setq i (1- i))))
                      x (cdr (assoc 1 e))
                      p (vl-string-position 58 x)
                )
                (if (and (setq a (distof (substr x 1 p) 2))
                         (setq b (distof (substr x (+ 2 p)) 2))
                         (not (equal 0.0 b 1e-8))
                    )
                    (entmod (subst (cons 1 (rtos (/ a b))) (assoc 1 e) e))
                )
            )
        )
        (princ)
    )
    Lee Mac ProgrammingTwitterExchange App StoreDropbox (500MB free)

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

  3. #3
    Luminous Being
    Using
    Civil 3D 2016
    Join Date
    Dec 2005
    Location
    GEELONG AUSTRALIA
    Posts
    9,738

    Default

    Hi Lee needs a second part say a copy of the text onto a different layer where the result is < 1/69 0.0144927536 this is part of the request, maybe a seperate defun this way the code re grade remains intact.

    had a little bit of time.

    Code:
    ; original code by Lee-mac Aug 2017
    ; changed to only modify 1:x below 1:69
    ; by Alan H Aug 2017
    
    (defun c:fixratios ( / a b e i p s x ab)
    ; new layer added 
    (if (/= (tblsearch "Layer" "Xgrade") nil)
          (setvar 'clayer "Grade2")
          (command "-layer" "m" "Xgrade" "c" 10 "Xgrade" "")
    )
    
    (if (setq s (ssget "_:L" '((0 . "TEXT")(1 . "#*:#*")(1 . "~*[~.:0-9]*")(1 . "~*:*:*"))))
      (repeat (setq i (sslength s))
        (setq e (vlax-ename->vla-object (ssname s (setq i (1- i)))))
        (setq x (vla-get-textstring e))
        (setq p (vl-string-position 58 x))
        (if (and 
              (setq a (distof (substr x 1 p) 2))
              (setq b (distof (substr x (+ 2 p)) 2))
              (not (equal 0.0 b 1e-8))
              (< (setq ab (/ a b)) (/ 1.0 69.0))
               )
              (progn
                (vla-put-textstring  e (rtos ab 2 3))
                (vla-put-layer e "Xgrade")
              )
          )
      )
    )
    (princ)
    )
    Last edited by BIGAL; 27th Aug 2017 at 02:35 am.
    A man who never made mistakes never made anything

  4. #4
    Senior Member devitg's Avatar
    Computer Details
    devitg's Computer Details
    Operating System:
    XP
    Monitor:
    VG2021WM VIEW SONIC
    Using
    AutoCAD 2008
    Join Date
    Apr 2005
    Location
    CORDOBA ARGENTINA
    Posts
    143

    Default

    Hi lee , nice lisp.

    Could you explain

    Code:
    (setq s (ssget "_:L" '((0 . "TEXT")(1 . "#*:#*")(1 . "~*[~.:0-9]*")(1 . "~*:*:*"))))
    About the 1 filter

    Also it can be add the 8 dxf code to TABLE , as it is the text's layer.

  5. #5
    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
    19,322

    Default

    Registered forum members do not see this ad.

    Quote Originally Posted by devitg View Post
    Could you explain
    Code:
    (setq s (ssget "_:L" '((0 . "TEXT")(1 . "#*:#*")(1 . "~*[~.:0-9]*")(1 . "~*:*:*"))))
    About the 1 filter
    (1 . "#*:#*")
    Matches text starting with a number and containing a colon followed by a number, e.g. "1abc:2def"

    (1 . "~*[~.:0-9]*")
    Matches text which only contains the characters ".:0123456789", e.g. "1.23:4.56:7.89"

    (1 . "~*:*:*")
    Ensures that the string only contains one colon.

    This doesn't account for all cases, as you could perform additional validation on the decimal point (ensuring it appears at most once on either side of the colon).

    The layer filter could also be included, but it would reduce the ability for other members to easily use the code.
    Lee Mac ProgrammingTwitterExchange App StoreDropbox (500MB free)

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

Similar Threads

  1. LISP to read text label as attribute in properties
    By Jakub in forum AutoLISP, Visual LISP & DCL
    Replies: 5
    Last Post: 21st Apr 2016, 09:51 am
  2. convert the number to text number in Arabic language
    By mahmoudqaswal in forum AutoLISP, Visual LISP & DCL
    Replies: 13
    Last Post: 3rd Apr 2016, 11:00 am
  3. A non lisp way to populate a table with contents of text objects?
    By YZ in forum The CUI, Hatches, Linetypes, Scripts & Macros
    Replies: 6
    Last Post: 26th Nov 2015, 09:30 am
  4. Record a Macro and Then Read the Action File Contents
    By Brenda Tanner in forum The CUI, Hatches, Linetypes, Scripts & Macros
    Replies: 3
    Last Post: 10th Jul 2012, 08:38 pm
  5. Convert .dwg to PDF and retain scale ratio
    By Bill.3 in forum AutoCAD Beginners' Area
    Replies: 4
    Last Post: 15th Mar 2009, 09:51 pm

Tags for this Thread

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