Find Next

Discussion in 'AutoCAD' started by inthepickle, Sep 13, 2007.

  1. inthepickle

    inthepickle Guest

    We use AutoCAD 14. This LISP routine was written by someone that is
    no longer with our company. The program asks a user what number they
    want to search for. It then searches a drawing for that number, and
    zooms in on the number if found. The problem is that it will only do
    this for the first instance of that number that it finds. Can someone
    please modify this program so that the user can hit a button, and go
    to the next instance of that number until it zooms to them all. I am
    unfamiliar with AutoCAD's lisp programs, and would not any clue where
    to start.

    Any help will be greatly appreciated.



    ;PROGRAM FINDS THE TEXT STRING ENTERED BY USER
    ;AND ZOOMS INTO THE LOCATION OF THE NUMBER
    (defun c:partnum (/ ANAME ALIST BNAME BLIST PNSET POS NB MATCH
    END LOCATION)
    ;ask user for part number and store in PNUM
    (setq PNUM (getstring "Enter Part # To Search For...."))
    ;create selection set of all blocks and text with filter-list
    (setq PNSET (ssget "X" (list (cons -4 "<OR")(cons 0 "insert")
    (cons 66 1)(cons 0 "text")(cons -4 "OR>"))))
    ;get number of entities in "PNSET"
    (setq NB (sslength PNSET))
    ;set ssname position number to 0
    (setq POS 0)
    ;enter while loop and remain looped until (MATCH = 1) or (1 + POS =
    NB)
    ;this is due to position starting at 0
    (while
    (and
    (= MATCH nil)
    (/= (+ POS 1) NB)
    );and
    ;get entity name of entity in selection set "PNSET"
    (setq BNAME (ssname PNSET POS))
    ;set ssname position number to 1 + POS
    (setq POS (1+ POS))
    ;get association list for entity
    (setq BLIST (entget BNAME))
    ;enter block cond if entity is a block
    (cond
    ( (and
    (= "INSERT" (cdr (assoc 0 BLIST)))
    (= 1 (cdr (assoc 66 BLIST)))
    );and
    ;get next entity name after block entity name
    ;this may or may not be an attribute
    (setq ANAME (entnext BNAME))
    ;get association list for this entity
    (setq ALIST (entget ANAME))
    ;test to see if it is an attribute and if not
    ;then loop until attribute is present
    (while
    (/= "ATTRIB" (cdr (assoc 0 ALIST)))
    (setq ANAME (entnext ANAME))
    (setq ALIST (entget ANAME))
    );while
    ;get number from ALIST
    (setq NUM (cdr (assoc 1 ALIST)))
    ;test for end of sequence
    (setq END (cdr (assoc 0 ALIST)))
    ;test for match between PNUM and NUM
    (if
    (= PNUM NUM)
    (progn
    (setq MATCH 1)
    (setq LOCATION (cdr (assoc 10 ALIST)))
    (setq THEIGHT (cdr (assoc 40 ALIST)))
    );
    );if
    ;enter block while loop to get next entity and re-test attributes for
    match (with PNUM)
    (while
    (and
    (= END "ATTRIB")
    (= MATCH nil)
    );and
    (setq ANAME (entnext ANAME))
    (setq ALIST (entget ANAME))
    (setq NUM (cdr (assoc 1 ALIST)))
    (setq END (cdr (assoc 0 ALIST)))
    (if
    (= PNUM NUM)
    (progn
    (setq MATCH 1)
    (setq LOCATION (cdr (assoc 10 ALIST)))
    (setq THEIGHT (cdr (assoc 40 ALIST)))
    );progn
    );if
    );while
    );cond
    );cond
    ;enter conditional for text
    (cond
    ((= "TEXT" (cdr (assoc 0 BLIST)))
    ;get number from BLIST
    (setq NUM (cdr (assoc 1 BLIST)))
    ;test for match between PNUM and NUM
    (if
    (= PNUM NUM)
    (progn
    (setq MATCH 1)
    (setq LOCATION (cdr (assoc 10 BLIST)))
    (setq THEIGHT (cdr (assoc 40 BLIST)))
    );progn
    );if
    );COND
    );COND
    );while
    ;zoom to location if MATCH = 1
    (cond
    ((= MATCH 1)
    (setq DIST (* THEIGHT 8.5))
    (setq P1 (polar LOCATION 3.2 DIST))
    (setq P2 (polar LOCATION 0.3 DIST))
    (command "zoom" "w" p1 p2)
    ));cond
    ;print message if no number found
    (if (= MATCH nil)
    (progn
    (princ "\n Part #.. ")(princ PNUM)(princ "..Not Found")(princ)
    );progn
    );if
    );defun partnum
     
    inthepickle, Sep 13, 2007
    #1
  2. You're asking someone to help your commercial venture for free, right?
    This wouldn't be too hard, but what motive would anyone have?
     
    Michael Bulatovich, Sep 13, 2007
    #2
  3. inthepickle

    Paul Turvill Guest

    :cool:
     
    Paul Turvill, Sep 13, 2007
    #3
  4. Hi Paul. How've you been?

     
    Michael Bulatovich, Sep 13, 2007
    #4
  5. inthepickle

    Paul Turvill Guest

    Still hangin' in there. About to take off for a two-week Alaska cruise,
    Juneau to Seattle on Emperor of the North. Yeah, it's the one that went
    aground last spring. :cool:
    ___
     
    Paul Turvill, Sep 13, 2007
    #5
  6. So pay someone who is an expert in LISP, you are trying to get something for
    nothing.
     
    Spooky Mulder, Sep 13, 2007
    #6
  7. You'll still get a normal day/night, and a bit of a nip in the air too. Is
    there booze on board? ; )
     
    Michael Bulatovich, Sep 14, 2007
    #7
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.