Michaels Posted April 6, 2011 Posted April 6, 2011 Hello . Is it possible to look for a specific drawing all over my computer drives and open it for editing ? "findfile" is not a global searching method. many thanks . Quote
SOliver Posted April 6, 2011 Posted April 6, 2011 Hi Michaels (setq driveIndex 96) (while (< (setq driveIndex(1+ driveIndex)) 123) (if(vl-file-directory-p (strcat (chr driveIndex) ":\\") (someFunction (strcat (chr driveIndex) ":\\")) ) ) This can be used to determine if a drive exists. I don't know if changing DWGPREFIX system variable will change the drive. If it does problem solved start use findfile in each drive. if that doesn't work I thiink you'd have to write a recursive function to manually read through each directory in each drive. For example ;Disclaimer ; I've wrote this in the quick reply box and have no idea if it works and to be honest I'm not entirely sure ; that the way it pases results out of it will work but hey it's only an example. (someFunction baseDirectory findMe( / result) ;Get directory contents (setq contents (vl-directory-files baseDirectory) ;With each of the driectory contents (foreach c contents ;Determine if item is a file or folder (if(not(vl-filename-extension baseDirectory)) ;It's a directory! (setq result(apply 'append(list (someFunction path findMe)))) ;It's a file! (if(equal c findMe) (setq result c) ) ) result ) I'm sure that the above isn't the best approach but in the event that you can't get finfile to work in all drives I'd bite the bulet and go for something similar to the above What do you expect the outcome to be if a directory contains more than file sharing the search name and would you want to take, for example, the newest version of the file? SOliver Quote
ReMark Posted April 6, 2011 Posted April 6, 2011 What? You don't know how to use Windows Explorer? I thought the ability to search for a drawing was incorporated in the Design Center as well. I'm not 100% positive as I usually can find any drawing I've done within a few seconds. Is it that you have thousands of drawings or do you lack good organizational skills when it comes to folder management? Quote
Lee Mac Posted April 6, 2011 Posted April 6, 2011 What? You don't know how to use Windows Explorer? I've got to agree - this is a serious case of re-inventing the wheel. Quote
SOliver Posted April 6, 2011 Posted April 6, 2011 What? You don't know how to use Windows Explorer? I thought the ability to search for a drawing was incorporated in the Design Center as well. I'm not 100% positive as I usually can find any drawing I've done within a few seconds. Is it that you have thousands of drawings or do you lack good organizational skills when it comes to folder management? One of the last company's I contracted for had a diabolical file storage protocol that was based entirely on anarchy. The only way it could be described as tree-like would be if there was an M C Esher trees lol But yeah I agree if it's just a case iof looking for a file then windows explorer or design center would be the way forward. Quote
Michaels Posted April 6, 2011 Author Posted April 6, 2011 Thank you SOliver . If I have a drawing out of AutoCAD library , findfile can not find it , so I may have placed my drawing in derive D or E . I would like to be able to find the drawing and open it by Lisp codes not ( design Center or W. explorer ) . Lisp codes to find any drawing anywhere in any drive . Is it possible for anyone ?Thanks a lot . Michaels Quote
ReMark Posted April 6, 2011 Posted April 6, 2011 Have you tried to make use of the functionality built right into AutoCAD 2011 by using CONTENTEXPLORER? Quote
Michaels Posted April 6, 2011 Author Posted April 6, 2011 Have you tried to make use of the functionality built right into AutoCAD 2011 by using CONTENTEXPLORER? No I have not used it yet , although I am using cad 2010 now not 2011 as it shows in my user name details . What can that functionality do in my case ? Thanks Quote
Lee Mac Posted April 6, 2011 Posted April 6, 2011 If you must proceed with LISP, here is an example: ;;---------------------=={ FindFile }==-----------------------;; ;; ;; ;; Searches the supplied directory and all subdirectories of ;; ;; the supplied directory for the specified file. ;; ;;------------------------------------------------------------;; ;; Author: Lee Mac, Copyright © 2011 - www.lee-mac.com ;; ;;------------------------------------------------------------;; ;; Arguments: ;; ;; file - file to search (w/ext), e.g. "MyFile.txt" ;; ;; directory - Root Directory to search from ;; ;;------------------------------------------------------------;; ;; Returns: Full filename of file if found, else nil. ;; ;;------------------------------------------------------------;; (defun LM:FindFile ( file directory ) (cond ( (findfile (strcat (setq directory (vl-string-right-trim "\\" directory)) "\\" file)) ) ( (vl-some (function (lambda ( dir ) (LM:FindFile file (strcat directory "\\" dir)) ) ) (vl-remove "." (vl-remove ".." (vl-directory-files directory nil -1))) ) ) ) ) Perhaps use this to open the file when/if found. Quote
Michaels Posted April 6, 2011 Author Posted April 6, 2011 Thank you Lee. Am I using it the right way , of course after load the sub-routine? (LM:FindFile "Drawing7.dwg" "C") My drawing (Drawing7.dwg) existed on the Desktop and My Drive name is "C" . Many Thanks Quote
pBe Posted April 6, 2011 Posted April 6, 2011 My take (another method) (defun FindDwg (Drive Fle / CheckForSubFolders FilesAtFolder fso fldr rootfolder ) (vl-load-com) (defun CheckForSubFolders (itm) (FilesAtFolder itm) (vlax-for itmf (vlax-get-property itm 'Subfolders) (CheckForSubFolders itmf) ) ) (defun FilesAtFolder (itm) (vlax-for files (vla-get-files itm) (if (wcmatch (vla-get-name files) Fle) (print (vla-get-path files)) (princ) ) ) ) (setq fso (vlax-create-object "Scripting.FileSystemObject")) (setq fldr (vlax-invoke-method fso 'GetDrive Drive) rootfolder (vlax-get-property fldr 'RootFolder) ) (FilesAtFolder rootfolder) (vlax-for sf (vlax-get-property rootfolder 'Subfolders) (CheckForSubFolders sf) ) (princ) ) Usage: (findDwg "D:" "Master_Site_*.dwg") The arguments are Drive Letter and String pattern Quote
pBe Posted April 6, 2011 Posted April 6, 2011 If you must proceed with LISP, here is an example: (defun LM:FindFile ( file directory ) (cond.... ) . It took me hours to write my code, the recursive thing is giving me headaches Nice code Lee Quote
Lee Mac Posted April 6, 2011 Posted April 6, 2011 Am I using it the right way , of course after load the sub-routine? (LM:FindFile "Drawing7.dwg" "C") My drawing (Drawing7.dwg) existed on the Desktop and My Drive name is "C" . The correct syntax would be: (LM:FindFile "Drawing7.dwg" "C:") However, you do realise this is likely to take a very long time since, not only is LISP slow anyway, by the algorithm will look through every folder and subfolder of the root directory (in your case "C:") and will only stop when your file is found. Quote
Lee Mac Posted April 6, 2011 Posted April 6, 2011 It took me hours to write my code, the recursive thing is giving me headaches Nice code Lee Thanks pBe At least you have some practice using the FSO now - I'd tend to use what's already there though :wink: Quote
alanjt Posted April 6, 2011 Posted April 6, 2011 Anyone ever notice this? Command: (findfile ".") "C:\\Users\\athompson\\Documents" Command: (findfile "..") "C:\\Users\\athompson" Command: (findfile "...") "C:\\Users\\athompson\\Documents\\" Quote
ReMark Posted April 6, 2011 Posted April 6, 2011 Anyone ever notice this? Command: (findfile ".") "C:\\Users\\athompson\\Documents" Command: (findfile "..") "C:\\Users\\athompson" Command: (findfile "...") "C:\\Users\\athompson\\Documents\\" Too simple. I was hoping for something much more complicated. LOL Quote
ReMark Posted April 6, 2011 Posted April 6, 2011 Also: Command: (findfile "\\.") "C:\\" DIR C:\*.dwg Quote
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.