Ah! the dilemma, and the posibilities...

Discussion in 'AutoCAD' started by Rudy Tovar, Dec 21, 2004.

  1. Rudy Tovar

    Rudy Tovar Guest

    Before I actually get started, perhaps someone has already done this... it's
    actually a no brainer, but like to see if anyone has come up with a
    condensed version that's a bit more efficient...

    OK...

    First a text a file that contains...

    ****THIS COMMENT OR THAT****

    **122 LINE ONE
    **123 LINE TWO
    **124 LINE THREE

    ********************************

    Considering it may contain spaces and more comments, I'd like to be able to
    use vl-position to located number "122" in a list that I'll be creating of a
    file reference.

    Also, eliminate any spaces, or tabs when returning the reference number
    "LINE ITEM NOTE".

    <list> = ("****THIS COMMENT OR THAT****" "" "**122 LINE ONE"
    .....etc.....)

    In the end I'd like to say (get-note "123" <list>) and all it returns is
    "LINE TWO" without any spaces or tabs in front of the note...

    I'd like to eliminate possibilities that someone may use spaces, tabs or
    both when writing the line item note.

    I know I could come up with a simple solution, but I'd like to see if
    someone may have a more efficient method, instead of having to compare each
    character in the LINE considering that the list could contain hundreds or
    items listed.

    Thank you for your comments
     
    Rudy Tovar, Dec 21, 2004
    #1
  2. What about using vl-string-trim, vl-string-search etc. to suit ...

    (vl-string-trim " */t" "***122 LINE ONE")

    => "122 LINE ONE"

    (if
    (setq pos
    (vl-string-search
    " "
    (setq temp
    (vl-string-trim
    " */t"
    "**122 LINE ONE"
    )
    )
    )
    )
    (substr temp 1 pos)
    )

    => "122"

    Etc.
     
    Michael Puckett, Dec 21, 2004
    #2
  3. Rudy Tovar

    Rudy Tovar Guest

    Thanks Michael, but I don't think the number reference would be to
    difficult, rather the contents after the number, which could include tabs or
    spaces, as I illustrated...I just don't want to go through another loop to
    get the note contents...

    Here's what I have...(masi-get-reference) is stored in drawing, but could be
    any file name.

    (defun c:test (/ file ofile oline olist)

    (setq file (masi-get-reference))

    (if (findfile file)
    (progn

    (setq ofile (open file "r"))
    (while (setq oline (read-line ofile))
    (setq olist (cons oline olist)
    nlist (cons (substr oline 1 5) nlist)
    )

    );end of while
    (close ofile)
    )
    )

    (list (reverse nlist)(reverse olist))
    )
     
    Rudy Tovar, Dec 21, 2004
    #3
  4. Rudy Tovar

    Rudy Tovar Guest

    Just so you know I could now use the vl-position to return the remaining
    values, but would like to see if it could be condensed a bit more to strip
    any spaces and or tabs.

    The illustrated function returns 2 list, one that contains the first 5
    charcters, and the second listing that returns anything remaining on that
    line...
     
    Rudy Tovar, Dec 21, 2004
    #4
  5. Rudy Tovar

    Rudy Tovar Guest

    One call in the beginning, it wouldn't be efficient to call the file several
    times.

    I gather the listing first then actually compare to a list of possible
    numbers.

    Although I only mention one number, it could be a list of random numbers.

    (list 122 123)
    read file
    return line for each number
     
    Rudy Tovar, Dec 21, 2004
    #5
  6. Rudy Tovar

    Dick Coy Guest

    Can you store the text file in list format ie.
    ((1 . 1)(2 . "Solid Surface")(10 . "SS1")(20 . "Fossil")(30 . "Corian")(40 .
    "1")(50 . "Tops and splash"))

    ((1 . 2)(2 . "Solid Surface")(10 . "SS2")(20 . "Pompeii Red")(30 .
    "Corian")(40 . "1")(50 . "Lavatories"))

    ((1 . 3)(2 . "Solid Surface")(10 . "SS4")(20 . "Anthracite")(30 .
    "Corian")(40 . "1")(50 . "Base"))

    then search it like the acad database?
     
    Dick Coy, Dec 22, 2004
    #6
  7. Rudy Tovar

    BillZ Guest

    One possibility?

    R2005:

    (setq test '("****THIS COMMENT OR THAT****" " " "**122 LINE ONE" " " "" "**133 LINE FIVE" "" "" "**142 LINE SIX"))

    Just to make the list longer:

    (repeat 10 (setq test (append test test)))

    (length test) = 9216

    (defun get-note (itm) ;integer input
    (setq itm (itoa itm)
    searchitem (strcat "*" itm "*"))
    (car (apply 'append (mapcar '(lambda (x)(if (wcmatch x searchitem)(list (vl-position x test)))) test)))
    )
    2

    Command: timer
    Elapsed time: 0.015000 seconds



    Bill
     
    BillZ, Dec 22, 2004
    #7
  8. Rudy Tovar

    Rudy Tovar Guest

    The file is external...

     
    Rudy Tovar, Dec 22, 2004
    #8
Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments (here). After that, you can post your question and our members will help you out.