Author Topic: 'Findfile' question...  (Read 3735 times)

0 Members and 1 Guest are viewing this topic.

whdjr

  • Guest
'Findfile' question...
« on: April 23, 2007, 08:04:11 AM »
I use 'findfile' to find a path for a block I know exists.  My code tells it to look in the current directory which is "Y:\\Common\\Projects\\School\\0603" and then it is supposed to search the support paths listed in AutoCAD:
Y:\\Common\\Standard DBs 2006
Y:\\Common\\Standard
C:\\Documents and Settings\\xp2\\Application Data\\Autodesk\\ADT 2006\\enu\\support
C:\\Program Files\\Autodesk Architectural Desktop 2006\\support
C:\\Program Files\\Autodesk Architectural Desktop 2006\\help
C:\\Program Files\\Autodesk Architectural Desktop 2006\\express
C:\\Program Files\\Autodesk Architectural Desktop 2006\\support\\color
Y:\\AutoCad 2006 ADT\\Configuration\\AutoLisp
Y:\\AutoCad 2006 ADT\\Configuration\\Fonts
Y:\\AutoCad 2006 ADT\\Configuration\\Template

If it still doesn't find my block it is supposed to show a dialog box asking for the location of the file.  The file is actually in "Y:\\Common\\Standard DBs 2006" but it finds it here "C:\\Documents and Settings\\xp2\\My Documents\\DR-THRESHOLD2.dwg" which is not even in the search path.

Can someone explain this to me?

Thanks,

CAB

  • Global Moderator
  • Seagull
  • Posts: 10401
Re: 'Findfile' question...
« Reply #1 on: April 23, 2007, 08:24:40 AM »
Wild guess.

Perhaps "My Documents" is a default search path.
It may be that you will have to test for that path & reject that hit.
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.

whdjr

  • Guest
Re: 'Findfile' question...
« Reply #2 on: April 23, 2007, 09:05:32 AM »
Didn't think of that one CAB.  How would I go about making it generic for multiple users?  I know other languages use a variable for the username but I'm not sure about lisp.

whdjr

  • Guest
Re: 'Findfile' question...
« Reply #3 on: April 23, 2007, 09:08:50 AM »
This is my code now.  'name' is the block name and 'path' is the current dwg path.  I'm not sure how you would use an exception with 'findfile'?

Code: [Select]
(cond ((setq file (findfile (strcat path "\\" name ".dwg")))); current folder
       ((setq file (findfile (strcat name ".dwg")))); current search path
       ((if (and $db_path$ (eq (vl-filename-base $db_path$) name))
(setq file $db_path$)
)
       )
       (T
(setq file (getfiled "Select a Block"
  (strcat path "\\")
  "dwg"
  (+ 64 128)
)
      $db_path$ file
)
       )
 )

Mark

  • Custom Title
  • Seagull
  • Posts: 28753
Re: 'Findfile' question...
« Reply #4 on: April 23, 2007, 09:11:56 AM »
This is from the documentation.

Quote from: findfile function
Searches the AutoCAD library path for the specified file or directory
(findfile filename)
The findfile function makes no assumption about the file type or extension of filename. If filename does not specify a drive/directory prefix, findfile searches the AutoCAD library path. If a drive/directory prefix is supplied, findfile looks only in that directory.


Quote from: acad_dev.chm
Library Search Path
The library search path specifies where the program searches for files when you do not specify a full path name, as follows:

Current directory. (This is typically determined by the “Start In” setting in your shortcut icon.)
Directory that contains the current drawing file.
Directories listed in the search path specified on the Files tab in OPTIONS. (See “Specify Search Paths, File Names, and File Locations” on page 12 in the User’s Guide.)
Directory that contains the AutoCAD program files.
Depending on the current environment, two or more directories may be the same.

If a file is not in this search path, you must specify both its path name and file name before AutoCAD can find it. For example, if you want to insert the part5.dwg drawing into your current drawing and it is not in the library search path, you must specify its full path name, as shown here:

Command: insert

Enter block name or [?]: /files2/olddwgs/part5

If the drawing exists in that location, AutoCAD prompts you to finish the INSERT command in the usual manner.

-HTH
TheSwamp.org  (serving the CAD community since 2003)

CAB

  • Global Moderator
  • Seagull
  • Posts: 10401
Re: 'Findfile' question...
« Reply #5 on: April 23, 2007, 09:28:58 AM »
Well, looks like you will have to Limit the FindFile.
Get the search paths in a list & search each one directly.
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.

whdjr

  • Guest
Re: 'Findfile' question...
« Reply #6 on: April 23, 2007, 09:42:20 AM »
Mark,

Thanks for the info.  That's what I thought it said and as far I can tell there is no reason it should be looking in the 'My Documents' folder.

CAB,

I can do that.  When I get some time (probably next week) I will redraft that portion of code to search those specifically.

Thanks for the insight guys,

CAB

  • Global Moderator
  • Seagull
  • Posts: 10401
Re: 'Findfile' question...
« Reply #7 on: April 23, 2007, 10:15:24 AM »
Will, something like this?
Code: [Select]
(defun c:test ()
  ;;++++++++++++++++++
  ;;  phraser by CAB 
  ;;++++++++++++++++++
  (defun sparser (str delim / ptr lst)
    (while (setq ptr (vl-string-search delim str))
      (setq lst (cons (substr str 1 ptr) lst))
      (setq str (substr str (+ ptr 2)))
    )
    (reverse (cons str lst))
  )

  (setq name "Outline")  ;  <===<<  My Test File
  (vl-load-com)
  (setq files (vla-get-files (vla-get-preferences (vlax-get-acad-object))))
  (setq paths (cons (vl-filename-directory(findfile "Acad.exe"))
                    (sparser (vla-get-supportpath files) ";")))

  (cond
    ;;  current directory
    ((setq file (findfile
                  (strcat
                    (vl-filename-directory
                      (vla-get-fullname (vla-get-ActiveDocument (vlax-get-acad-object))))
                    "\\" name ".dwg")))
    )
    ;;  ACAD search Paths
    ((setq file (vl-some '(lambda (x)
                            (findfile (strcat x "\\" name ".dwg"))
                          )
                         paths
                )
     )
    )
    ;|((if (and $db_path$ (eq (vl-filename-base $db_path$) name))
       (setq file $db_path$)
     )
    )
    (t
     (setq file      (getfiled "Select a Block"
                               (strcat path "\\")
                               "dwg"
                               (+ 64 128)
                     )
           $db_path$ file
     )
    )|;
  )



  (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.

whdjr

  • Guest
Re: 'Findfile' question...
« Reply #8 on: April 23, 2007, 11:40:49 AM »
Thanks, CAB.  Any thoughts on this?

...  How would I go about making it generic for multiple users?  I know other languages use a variable for the username but I'm not sure about lisp.

JohnK

  • Administrator
  • Seagull
  • Posts: 10605
Re: 'Findfile' question...
« Reply #9 on: April 23, 2007, 01:18:18 PM »
Loginname
TheSwamp.org (serving the CAD community since 2003)
Member location map - Add yourself

Donate to TheSwamp.org

whdjr

  • Guest
Re: 'Findfile' question...
« Reply #10 on: April 23, 2007, 01:35:06 PM »
Thanks, Se7en.

VVA

  • Newt
  • Posts: 166
Re: 'Findfile' question...
« Reply #11 on: April 24, 2007, 03:28:04 AM »
Code: [Select]
(alert (strcat "User Name :" (if (setq str (getenv "USERNAME")) str "") "\n"
               "Computer Name :" (if (setq str (getenv  "COMPUTERNAME")) str "") "\n"
               "Domain Name :" (if (setq str (getenv  "USERDOMAIN")) str "")))