lisp file that searches for numbers or/text and shows howmany of each is in DWG

Discussion in 'AutoCAD' started by maryam, Aug 4, 2004.

  1. maryam

    maryam Guest

    Hi.
    I know that you could simply use find from the toolbar menu.
    but I want to write a lisp file that looks for certain text (which is placed within attributes) and give a table indicating how many of each text is in the drawing.

    eg:

    text count
    1 10
    2 4
    3b 2

    I need to write a function that receives the text searches for it and returns count.
    In addition I need to know how to display the table visually. I need to make it in such a way that it could easily be copy pasted to excel.

    thank u

    maryam


    Message was edited by: maryam
     
    maryam, Aug 4, 2004
    #1
  2. maryam

    alexshein Guest

    Miriam, try this:
    (defun C:TxtFndr (/ kword str)
    (vl-load-com)
    (setq adoc (vla-get-activedocument (vlax-get-acad-object))
    n 0)
    (initget "Text String")
    (setq kword (getkword (strcat "\nSelect Search Object [Text/String/Pattern] <String>: ")))
    (if (null kword) (setq kword "String"))
    (vlax-for txt adoc
    (if (= (vla-get-objectname txt) "AcDbText")
    (cond ((= kword "Text") (setq n (1+ n)))
    ((= kword "String")
    (setq str (getstring "\nString to search: "))
    (if (= (vla-get-textstring txt) str) (setq n (1+ n))))
    ((= kword "Pattern")
    (setq str (getstring "\nEnter Pattern to search or <Enter>: "))
    (if (null str)
    (setq str (vla-get-textstring (vlax-ename->vla-object
    (car (entsel "\nSelect Pattern to search"))))))
    (if (vl-string-search str txt)) (setq n (1+ n))))
    );cond
    );if
    );vlax-for
    );end
     
    alexshein, Aug 4, 2004
    #2
  3. maryam

    alexshein Guest

    Sorry, it should be
    (initget "Text String Pattern")
     
    alexshein, Aug 4, 2004
    #3
  4. maryam

    maryam Guest

    alexshein, thank you very much for the code however, I have never wrote a lisp and I really have a hard time understanding it. I would really appreciate if you could explain what each part does.
     
    maryam, Aug 10, 2004
    #4
  5. maryam

    maryam Guest

    The algorithm that I have in mind is the following:
    I am used to C++....so this is in c++ terms:

    main function
    {
    char text-array[10];
    int count [10];

    text-array[0]='1' ;
    text-array[1]='2' ;
    text-array[2]='3' ;
     
    maryam, Aug 10, 2004
    #5
  6. maryam

    PG. Guest

    Hi maryam,


    Where does the Find() function search?

    In lisp text is stored as a string object unlike a character array in C/C++.
    (setq myText "abcdefgh")

    (vl-string-search) function would return the first occurance of the search
    string/pattern.
    (setq postion (vl-string-search "a" myText))

    or if you store the
    Note: the search is case sensitve.

    In case of numbers, you would store the numbers as a list.
    (setq myNumbers (list 1 2 3 4 5 6 7 8 9 10 12))
    or a string stored as a list
    (setq txtList (list "a" "b" "c"))

    (setq position (vl-position 5 myNumbers))
    or
    (setq position (vl-position "a" txtList))

    Hth,


     
    PG., Aug 10, 2004
    #6
  7. maryam

    PG. Guest

    (reposted with a change)

    Hi maryam,


    Where does the Find() function search?

    In lisp text is stored as a string object unlike a character array in C/C++.
    (setq myText "abcdefgh")

    (vl-string-search) function would return the first occurance of the search
    string/pattern.
    (setq postion (vl-string-search "a" myText))

    Note: the search is case sensitve.

    In case of numbers, you would store the numbers as a list.
    (setq myNumbers (list 1 2 3 4 5 6 7 8 9 10 12))
    or a string stored as a list
    (setq txtList (list "a" "b" "c"))

    (setq position (vl-position 5 myNumbers))
    or
    (setq position (vl-position "a" txtList))

    Hth,
    -PG.

     
    PG., Aug 10, 2004
    #7
  8. maryam

    maryam Guest

    hi

    the find function searches the drawing and looks for the text that it is given.

    by the way the text that I want to put in text-array is each a separate thing. and i want the find function to find them separately one by one. however I guess I Could also create 10 strings with different names and pass them to find function right?
     
    maryam, Aug 10, 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.