Results 1 to 2 of 2

Thread: Lisp to extract and add numbers from mtext string

  1. #1
    Woo! Hoo! my 1st post
    Join Date
    2017-07
    Posts
    1
    Login to Give a bone
    0

    Default Lisp to extract and add numbers from mtext string

    Hello everyone,
    I am trying to automate footage counting in my drawings
    I'm looking for help on making a LISP routine that would look through the entire drawing for any mtext which has an associated string. It would than display the sum of these associated strings in a block.
    For examples,

    ASPHALT TRENCH 55'
    ASPHALT TRENCH 5'
    DIRT TRENCH 4'
    DIRT TRENCH 8'
    BORE 164'
    BORE 12'

    value of asphalt trench block= 60'
    value of Dirt trench block=12'
    value of bore block=176'

    There are usually around 1-6 mtext with those associated strings in the whole drawing. That mtext string is usually on the same line and its always the first line. The blocks for the sum of the strings are on the layout tabs.
    I have looked and couldn't find anything that would achieve this.
    Hope this long explanation is clear enough..
    Let me know if any routine is available or if clarifications are needed.
    Any suggestion on how to solve this differently would be welcome as well

  2. #2
    All AUGI, all the time
    Join Date
    2003-07
    Posts
    555
    Login to Give a bone
    0

    Default Re: Lisp to extract and add numbers from mtext string

    Here is an start need to add the search for 55' or actually the ' and get the length. Need some time to do its late here. There is a bit to be added to allow for different string combos and probably needs a strip mtext string to remove the hidden characters in mtext. should wok with plain text a well.

    Code:
    (defun  AH:finddist (x  str / )
    (setq ans "")
    (setq do "yes")
    (setq x(+ x 16))
    (while (= do  "yes")
    (setq text (substr str  x 1))
    (if (= text (chr 39))(setq do "no")
    (progn
    (setq  ans (strcat ans text)) 
    (setq  x (+ x 1))
    )
    )
    )
    )
    
    (defun ah:addstr ( /  obj textans num )
    (setq total 0.0)
    (while (setq obj (vlax-ename->vla-object (car (entsel "pick MTEXT object"))))
    (setq textans (vla-get-textstring obj))
    (setq num (vl-string-search  "ASPHALT TRENCH" (strcase textans)))
    (if (/= num nil)
    (progn
    (alert (strcat "ASPHALT TRENCH found at " (rtos num 2 0) " position"))
    (aH:finddist num  textans  )
    )
    (alert "sorry no match")
    )
    (setq total (+ total (atof ans)))
    (alert (strcat "total is " (rtos total 2 2 )))
    )
    )
    (aH:addstr)
    Last edited by BIG-AL; 2018-07-25 at 12:03 PM.

Similar Threads

  1. Need a lisp that can extract the numbers from selected Text
    By brahmanandam.thadikonda762224 in forum AutoLISP
    Replies: 6
    Last Post: 2016-12-10, 11:04 PM
  2. List for Sum of first numbers in text string
    By kumar2589 in forum AutoLISP
    Replies: 11
    Last Post: 2014-08-28, 08:03 AM
  3. String to list of real numbers
    By feargt in forum AutoLISP
    Replies: 4
    Last Post: 2013-05-28, 07:07 AM
  4. Replies: 7
    Last Post: 2013-03-19, 08:26 AM
  5. Lisp to extract and add numbers from text/mtext string
    By cblendermann.91943 in forum AutoLISP
    Replies: 26
    Last Post: 2005-08-18, 03:25 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
  •