Author Topic: Too few arguments  (Read 9586 times)

0 Members and 1 Guest are viewing this topic.

T.Willey

  • Needs a day job
  • Posts: 5251
Re: Too few arguments
« Reply #30 on: May 14, 2009, 03:15:54 PM »
...and again, I show my ignorance.  How do you do a text search?  I did a search using the start up search program for file and folders and found nothing.
Pockets

I'm with you on this one though.  I have seen it described, but have never done it, so maybe someone who has will be nice enough to chime in.
Tim

I don't want to ' end-up ', I want to ' become '. - Me

Please think about donating if this post helped you.

Matt__W

  • Seagull
  • Posts: 12955
  • I like my water diluted.
Re: Too few arguments
« Reply #31 on: May 14, 2009, 03:33:18 PM »
...and again, I show my ignorance.  How do you do a text search?  I did a search using the start up search program for file and folders and found nothing.
Pockets

I'm with you on this one though.  I have seen it described, but have never done it, so maybe someone who has will be nice enough to chime in.
http://www.kellys-korner-xp.com/xp_s.htm

Scroll down to SEARCH - ALL FILE TYPES.  Might be of some help...??
Autodesk Expert Elite
Revit Subject Matter Expert (SME)
Owner/FAA sUAS Pilot @ http://skyviz.io

CAB

  • Global Moderator
  • Seagull
  • Posts: 10401
Re: Too few arguments
« Reply #32 on: May 14, 2009, 03:37:19 PM »
Using FileExployer


You may need to search other folders depending on where you keep your lisp files.
I've reached the age where the happy hour is a nap. (°¿°)
Windows 10 core i7 4790k 4Ghz 32GB GTX 970
Please support this web site.

Matt__W

  • Seagull
  • Posts: 12955
  • I like my water diluted.
Re: Too few arguments
« Reply #33 on: May 14, 2009, 03:39:38 PM »
Using FileExployer


You may need to search other folders depending on where you keep your lisp files.

If only it worked.   :|
Autodesk Expert Elite
Revit Subject Matter Expert (SME)
Owner/FAA sUAS Pilot @ http://skyviz.io

POCKETS

  • Guest
Re: Too few arguments
« Reply #34 on: May 14, 2009, 04:01:28 PM »
CAB,
That's the way I did my search and I came up empty.  So, I would say that was a good thing.
Pocketw

gile

  • Gator
  • Posts: 2507
  • Marseille, France
Re: Too few arguments
« Reply #35 on: May 14, 2009, 04:06:50 PM »
Hi

Here's a little LISP to make text searchs from AutoCAD



Code: [Select]
;; SEARCH (gile)
;; Search for a string in a directory (and sub-directories)
;; Returns the list of the files which countain the string

(defun c:search (/ path lst rslt file line)
  (and
    (setq path (dirbox "Select a directory" "" 512))
    (setq lst (searchbox))
    (setq rslt "")
    (mapcar
      (function
(lambda (d)
  (mapcar
    '(lambda (f)
       (setq file (open (strcat d "\\" f) "r")
     loop T
       )
       (while (and loop (setq line (read-line file)))
(if
   (vl-string-search (strcase (cadr lst)) (strcase line))
    (setq rslt (strcat rslt d "\\" f "\n")
  loop nil
    )
)
       )
       (close file)
     )
    (vl-directory-files d (car lst))
  )
)
      )
      (cons path (getfolders path))
    )
    (and (/= "" rslt) (princ rslt) (textscr))
  )
  (princ)
)

(defun SearchBox (/ temp file dcl_id ext pat lst)
  (setq temp (vl-filename-mktemp "Tmp.dcl")
file (open temp "w")
  )
  (write-line
    "SearchBox
    :dialog{label=\"Search\";initial_focus=\"ext\";
    :row{
    :text{label=\"File type\";}
    :edit_box{key=\"ext\";edit_width=15;allow_accept=true;}
    }
    spacer;
    :text{label=\"Text to search\";}
    :edit_box{key=\"pat\";edit_width=40;allow_accept=true;}
    spacer;
    ok_cancel;}"
    file
  )
  (close file)
  (setq dcl_id (load_dialog temp))
  (if (not (new_dialog "SearchBox" dcl_id))
    (exit)
  )
  (action_tile
    "accept"
    "(setq lst (list (get_tile \"ext\") (get_tile \"pat\"))) (done_dialog)"
  )
  (start_dialog)
  (unload_dialog dcl_id)
  (vl-file-delete temp)
  lst
)

;;; DirBox -Patrick_35-

(defun DirBox (Message Chemin Drapeau / rep sh)
  (setq sh (vlax-create-object "Shell.Application"))
  (if (setq
rep (vlax-invoke sh 'browseforfolder 0 Message Drapeau Chemin)
      )
    (setq rep (vlax-get-property (vlax-get-property rep 'self) 'path))
    (setq rep nil)
  )
  (vlax-release-object sh)
  rep
)

;;; GetFolders (gile)
;;; Returns the list of all sub-folders of the specified folder (or drive)

(defun GetFolders (path / c)
  (apply 'append
(mapcar
   (function
     (lambda (x)
       (cons (setq c (strcat path "\\" x)) (GetFolders c))
     )
   )
   (vl-remove "."
      (vl-remove ".." (vl-directory-files path nil -1))
   )
)
  )
)
Speaking English as a French Frog

Chuck Gabriel

  • Guest
Re: Too few arguments
« Reply #36 on: May 14, 2009, 04:30:07 PM »
If only it worked.   :|

The reason it worked for Alan but not for you is because Alan is using Windows 2000, and you are using Windows XP.  In XP and Vista you have to screw around in the registry to get search to look inside of lisp souce files.  I'll see if I can find the article that explains how to fix this and post a link.

POCKETS

  • Guest
Re: Too few arguments
« Reply #37 on: May 14, 2009, 04:38:27 PM »
Gile,
Thank You.
The search program works great.  I found one lisp with a defun trans attached.
...and here it is:


; The following program is written as an aid to finding occurances of
; a string within an Autocad drawing.  Strings which are part of
; primary text entities, attributes, and blocks (one level deep) are found.
;
; The user is prompted to enter a target string, pick a base point and
; indicate whether blocks are to be searched.  The target string is the
; string of text you want to find.  Using upper or lower case does not
; affect the results.  The program uses the base point you select to draw
; lines to the insertion point of all text entities which contain the
; target string.
;
;
;
(defun trans (base ip scale rang tbase / dist ang xr yr pt2)
   (setq dist (* (distance base tbase) scale)
     ang (angle base tbase)
      xr (+ (car ip) (* dist (cos (+ ang rang))))
      yr (+ (cadr ip) (* dist (sin (+ ang rang))))
     pt2 (list xr yr)
   )
)
(defun match (target test / tstlen tarlen dif z ind temp )
   (setq tstlen (strlen test)
    tarlen (strlen target)
    dif (+ (- tstlen tarlen) 1)
      z 1
    ind 0
      v 'Q
   )
   (if (> dif 0)
       (repeat dif
     (while z
        (setq ind (+ ind 1)
         temp (substr test ind tarlen)
        )
        (if (= temp target)
       (setq v 'T
             z nil
       )
        )
        (if (>= ind tstlen)(setq z nil))
     )
       )
   )
   (eval v)
)
(defun c:fndtxt (/ p1 ss1 ss2 ss3 ss1len ss2len ss3len index mat target
       test p2 name atfl ent blknm blkstuf base ename tbase
       count en2 bname ip scale rang i ques
         )
   (graphscr)
   (setvar "cmdecho" 0)
   (setq target (strcase (getstring T "\nEnter target string: "))
        p1 (getpoint "\nPick base point for marks ")
      ques (strcase (substr (getstring "\nDo you wish to search blocks too? <Y>: ") 1 1))
   )
   (if (= ques "")(setq ques "Y"))
   (prompt "\nCreating selection sets -Please wait ")
   (setq ss1 (ssget "x" '((0 . "TEXT")))
    ss1len (if (/= ss1 nil)(sslength ss1)(eval 0))
    index -1
    mat 0
   )
   (prompt (strcat "\nNumber of text entities in drawing: " (itoa ss1len)))
   (prompt (strcat "\n        Entities checked        Matches found for <"
         target ">"
      )
   )
   (terpri)
   (repeat ss1len
      (prompt (strcat "\r             " (itoa (+ index 2))
            "                        "(itoa mat)
         )
      )
      (setq index (+ index 1)
        test (strcase (cdr (assoc 1 (entget (ssname ss1 index)))))
      )
      (if (match target test)
    (progn
       (setq p2 (cdr (assoc 10 (entget (ssname ss1 index))))
        mat (+ mat 1)
       )
       (command "line" p1 p2 "")
    )
      )
   )
   (if (= ques "Y")
   (progn
   (prompt "\nChecking blocks for attributes: ")
   (setq ss2 (ssget "x" '((0 . "INSERT")))
    ss2len (if (/= ss2 nil)(sslength ss2)(eval 0))
   )
   (prompt (strcat "\n        Blocks checked          Matches found for <"
         target ">"
      )
   )
   (terpri)
   (setq index -1)
   (repeat ss2len
      (prompt (strcat "\r             " (itoa (+ index 2))
            "                        "(itoa mat)
         )
      )
      (setq index (+ index 1)
        name (ssname ss2 index)
        atfl (cdr (assoc 66 (setq ent (entget name))))
      )
      (if (= atfl 1)
     (while (/= (cdr (assoc 0 ent)) "SEQEND")
        (if (= (cdr (assoc 0 ent)) "ATTRIB")
      (if (match target (strcase (cdr (assoc 1 ent))))
         (progn
            (command "line" p1 (cdr (assoc 10 ent)) "")
            (setq mat (+ mat 1))
            (prompt (strcat "\r             " (itoa (+ index 2))
                  "                        "(itoa mat)
               )
            )
         )
      )
        )
        (setq ent (entget (setq name (entnext name))))
     )
      )
   )
   (setq index -1)
   (repeat ss2len
      (setq index (+ index 1)
        name (ssname ss2 index)
       blknm (cdr (assoc 2 (entget name)))
      )
      (setq i (substr blknm 1 1))
      (if (and (not (member blknm ss3)) (/= i "*"))(setq ss3 (cons blknm ss3)))
   )
   (prompt (strcat "\nChecking " (itoa (length ss3)) " blocks for imbedded text: " ))
   (prompt (strcat "\nBlock     Entities checked      Matches found for <"
         target ">"
      )
   )
   (terpri)
   (setq index -1)
   (repeat (length ss3)
      (setq index (+ index 1)
       blknm (nth index ss3)
       blkstuf (tblsearch "block" blknm)
       base (cdr (assoc 10 blkstuf))
       ename (cdr (assoc -2 blkstuf))
      )
      (setq i -1)
      (while ename
    (setq i (+ i 1))
    (prompt (strcat "\r" blknm "          " (itoa i) "                        "(itoa mat))
    )
    (setq ent (entget ename))
    (if (= (cdr (assoc 0 ent)) "TEXT")
       (progn
          (setq test (cdr (assoc 1 ent)))
          (if (match target test)
        (progn
           (setq tbase (cdr (assoc 10 ent))
            count -1
           )
           (repeat ss2len
         (setq count (+ count 1)
               en2 (ssname ss2 count)
               bname (cdr (assoc 2 (entget en2)))
         )
         (if (= bname blknm)
            (progn
               (setq ip (cdr (assoc 10 (entget en2)))
                scale (cdr (assoc 41 (entget en2)))
                rang (cdr (assoc 50 (entget en2)))
               )
               (command "line" p1 (trans base ip scale rang  tbase) "")
               (setq mat (+ mat 1))
               (prompt (strcat "\r" blknm "          "(itoa i)
                     "                        "(itoa mat)
                  )
               )
            )
         )
           )
        )
          )
       )
    )
    (setq ename (entnext ename))
      )
   )
   )
   )
   (princ)
)


Matt__W

  • Seagull
  • Posts: 12955
  • I like my water diluted.
Re: Too few arguments
« Reply #38 on: May 14, 2009, 04:42:41 PM »
If only it worked.   :|

The reason it worked for Alan but not for you is because Alan is using Windows 2000, and you are using Windows XP.  In XP and Vista you have to screw around in the registry to get search to look inside of lisp souce files.  I'll see if I can find the article that explains how to fix this and post a link.

I found one hot-fix, but that was for searching within Excel files.  Oh, well.  Not a big deal (for me anyways) since I can't hack the registry here.  I can't even see my C:\ drive - they've got that "hidden" from us so we don't accidentally delete any important DLLs.    :lol:
Autodesk Expert Elite
Revit Subject Matter Expert (SME)
Owner/FAA sUAS Pilot @ http://skyviz.io

CAB

  • Global Moderator
  • Seagull
  • Posts: 10401
Re: Too few arguments
« Reply #39 on: May 14, 2009, 04:49:06 PM »
Wow, thanks Gile, very nice..

Pockets, here is the revised/repaired LISP.
Distroy the other copy!
Code: [Select]
; The following program is written as an aid to finding occurances of
; a string within an Autocad drawing.  Strings which are part of
; primary text entities, attributes, and blocks (one level deep) are found.
;
; The user is prompted to enter a target string, pick a base point and
; indicate whether blocks are to be searched.  The target string is the
; string of text you want to find.  Using upper or lower case does not
; affect the results.  The program uses the base point you select to draw
; lines to the insertion point of all text entities which contain the
; target string.
;
;
;

(defun c:fndtxt (/ p1 ss1 ss2 ss3 ss1len ss2len ss3len index mat target
       test p2 name atfl ent blknm blkstuf base ename tbase
       count en2 bname ip scale rang i ques transl match
         )

(defun transl (base ip scale rang tbase / dist ang xr yr pt2)
   (setq dist (* (distance base tbase) scale)
     ang (angle base tbase)
      xr (+ (car ip) (* dist (cos (+ ang rang))))
      yr (+ (cadr ip) (* dist (sin (+ ang rang))))
     pt2 (list xr yr)
   )
)
(defun match (target test / tstlen tarlen dif z ind temp )
   (setq tstlen (strlen test)
    tarlen (strlen target)
    dif (+ (- tstlen tarlen) 1)
      z 1
    ind 0
      v 'Q
   )
   (if (> dif 0)
       (repeat dif
     (while z
        (setq ind (+ ind 1)
         temp (substr test ind tarlen)
        )
        (if (= temp target)
       (setq v 'T
             z nil
       )
        )
        (if (>= ind tstlen)(setq z nil))
     )
       )
   )
   (eval v)
)

 
   (graphscr)
   (setvar "cmdecho" 0)
   (setq target (strcase (getstring T "\nEnter target string: "))
        p1 (getpoint "\nPick base point for marks ")
      ques (strcase (substr (getstring "\nDo you wish to search blocks too? <Y>: ") 1 1))
   )
   (if (= ques "")(setq ques "Y"))
   (prompt "\nCreating selection sets -Please wait ")
   (setq ss1 (ssget "x" '((0 . "TEXT")))
    ss1len (if (/= ss1 nil)(sslength ss1)(eval 0))
    index -1
    mat 0
   )
   (prompt (strcat "\nNumber of text entities in drawing: " (itoa ss1len)))
   (prompt (strcat "\n        Entities checked        Matches found for <"
         target ">"
      )
   )
   (terpri)
   (repeat ss1len
      (prompt (strcat "\r             " (itoa (+ index 2))
            "                        "(itoa mat)
         )
      )
      (setq index (+ index 1)
        test (strcase (cdr (assoc 1 (entget (ssname ss1 index)))))
      )
      (if (match target test)
    (progn
       (setq p2 (cdr (assoc 10 (entget (ssname ss1 index))))
        mat (+ mat 1)
       )
       (command "line" p1 p2 "")
    )
      )
   )
   (if (= ques "Y")
   (progn
   (prompt "\nChecking blocks for attributes: ")
   (setq ss2 (ssget "x" '((0 . "INSERT")))
    ss2len (if (/= ss2 nil)(sslength ss2)(eval 0))
   )
   (prompt (strcat "\n        Blocks checked          Matches found for <"
         target ">"
      )
   )
   (terpri)
   (setq index -1)
   (repeat ss2len
      (prompt (strcat "\r             " (itoa (+ index 2))
            "                        "(itoa mat)
         )
      )
      (setq index (+ index 1)
        name (ssname ss2 index)
        atfl (cdr (assoc 66 (setq ent (entget name))))
      )
      (if (= atfl 1)
     (while (/= (cdr (assoc 0 ent)) "SEQEND")
        (if (= (cdr (assoc 0 ent)) "ATTRIB")
      (if (match target (strcase (cdr (assoc 1 ent))))
         (progn
            (command "line" p1 (cdr (assoc 10 ent)) "")
            (setq mat (+ mat 1))
            (prompt (strcat "\r             " (itoa (+ index 2))
                  "                        "(itoa mat)
               )
            )
         )
      )
        )
        (setq ent (entget (setq name (entnext name))))
     )
      )
   )
   (setq index -1)
   (repeat ss2len
      (setq index (+ index 1)
        name (ssname ss2 index)
       blknm (cdr (assoc 2 (entget name)))
      )
      (setq i (substr blknm 1 1))
      (if (and (not (member blknm ss3)) (/= i "*"))(setq ss3 (cons blknm ss3)))
   )
   (prompt (strcat "\nChecking " (itoa (length ss3)) " blocks for imbedded text: " ))
   (prompt (strcat "\nBlock     Entities checked      Matches found for <"
         target ">"
      )
   )
   (terpri)
   (setq index -1)
   (repeat (length ss3)
      (setq index (+ index 1)
       blknm (nth index ss3)
       blkstuf (tblsearch "block" blknm)
       base (cdr (assoc 10 blkstuf))
       ename (cdr (assoc -2 blkstuf))
      )
      (setq i -1)
      (while ename
    (setq i (+ i 1))
    (prompt (strcat "\r" blknm "          " (itoa i) "                        "(itoa mat))
    )
    (setq ent (entget ename))
    (if (= (cdr (assoc 0 ent)) "TEXT")
       (progn
          (setq test (cdr (assoc 1 ent)))
          (if (match target test)
        (progn
           (setq tbase (cdr (assoc 10 ent))
            count -1
           )
           (repeat ss2len
         (setq count (+ count 1)
               en2 (ssname ss2 count)
               bname (cdr (assoc 2 (entget en2)))
         )
         (if (= bname blknm)
            (progn
               (setq ip (cdr (assoc 10 (entget en2)))
                scale (cdr (assoc 41 (entget en2)))
                rang (cdr (assoc 50 (entget en2)))
               )
               (command "line" p1 (transl base ip scale rang  tbase) "")
               (setq mat (+ mat 1))
               (prompt (strcat "\r" blknm "          "(itoa i)
                     "                        "(itoa mat)
                  )
               )
            )
         )
           )
        )
          )
       )
    )
    (setq ename (entnext ename))
      )
   )
   )
   )
   (princ)
)
I've reached the age where the happy hour is a nap. (°¿°)
Windows 10 core i7 4790k 4Ghz 32GB GTX 970
Please support this web site.

gile

  • Gator
  • Posts: 2507
  • Marseille, France
Re: Too few arguments
« Reply #40 on: May 14, 2009, 04:50:24 PM »
You're welcome POCKETS.

I suggest you rename this trans function (findtxt_trans for example) and you replace the only call to this function (about the end of the code):
(command "line" p1 (trans base ip scale rang  tbase) "")
by
(command "line" p1 (findtxt_trans base ip scale rang  tbase) "")

trans is a very usefull pre defined LISP function, it's a shame to redefine it !

<EDIT>: CAB was faster...
Speaking English as a French Frog

POCKETS

  • Guest
Re: Too few arguments
« Reply #41 on: May 14, 2009, 04:58:48 PM »
Again,

Many, many thanks to all (CAB, T. WILLEY, GILES)

T.Willey

  • Needs a day job
  • Posts: 5251
Re: Too few arguments
« Reply #42 on: May 14, 2009, 05:05:43 PM »
You're welcome for my part.  I'm just glad we found what the issue was.
Tim

I don't want to ' end-up ', I want to ' become '. - Me

Please think about donating if this post helped you.

Lee Mac

  • Seagull
  • Posts: 12913
  • London, England
Re: Too few arguments
« Reply #43 on: May 15, 2009, 07:50:05 AM »
I can't believe someone would redefine the trans function... glad you got it sorted Pockets, lets just hope there aren't any other functions that have been redefined...

wizman

  • Bull Frog
  • Posts: 290
Re: Too few arguments
« Reply #44 on: May 15, 2009, 12:51:41 PM »
Just adding, ultraedit got a nice find in files feature and even vlide has a built in same function too.