Continue to Site

Eng-Tips is the largest engineering community on the Internet

Intelligent Work Forums for Engineering Professionals

  • Congratulations MintJulep on being selected by the Eng-Tips community for having the most helpful posts in the forums last week. Way to Go!

Find Files Macro 1

Status
Not open for further replies.

aamoroso

Mechanical
Mar 5, 2003
432
Anyone know of a way I can search a server for a file with a macro. I have to iterate through a large number of folders and sub folders to find my files. I would like to write a macro to iterate through them for me and open or give me options of files to open. I would like to do this in a macro simply so that I do not have to use MS search and then have to open the files via MSExplorer. Any Ideas?????????

Thanks
 
Replies continue below

Recommended for you

Why can't you use MS search engine and look for certain file types? Like "*.sldprt" then once SW find the files simply RMB and click Open.

I don't you could do this from a standalone SW macro. This would have to be a external program to do that... IMO

Regards,

Scott Baugh, CSWP [pc2]

If you are in the SW Forum Check out the FAQ section

To make the Best of Eng-Tips Forums FAQ731-376
 
Here is an example macro that I used to do the same thing where I worked.
In the macro, you type in the part number (file name) and it automatically figures out where the file should be located and opens it.
It requires that the file be organized in some sort of logical manner so that an algorithm can be written to figure out the folder from the file name. Feel free to take a look and modify it to your needs.
 
Well the dilema is this:

I have about 100-150 directories containing thousands of parts.

When a shop employee calls with a question on a drawing I have to hunt and peck for the SLDDRW or use MS Search which is slow due to the amount of files to sift through, not to mention the server is mac based (not really relevant though). But it would be nice when the phone rings to click a button in SW and type in the Part Number and the drawing opens for me. We use a database system on our macs that allow me to pull the DXF files easily but we do not fully dimension them so usually we have to open the SLDDRW to answer questions.
 
Thanks man, that should do it. I appreciate your help.
 
Scott, I have been using MS Search to accomplish this, the downside: Opening parts via explorer or search tend to cause instability in SW for me. I have written it off as having something to do with the files being on a Mac server but maybe that is not the case. Anyway thank you for your help guys.
 
Store all of your macros in one folder on the server and go to Tools, Options, System Options, File locations, scroll to macros, brouse to macro folder on server. Next time you go to run macro it will go to that folder and list your macros. I hope this is what you are looking for.
 
Sorry ctopher I think you misunderstood. I was looking for a macro that would search for a SolidWorks Drawing File on a seperate server and then open said file. The macro that Arlin posted works great, it will take alot of manipulating and editing to work for us but it has all the basics we need to get us moving.
 
OK, sorry. I'm having a stressful morning. Yes, I misunderstood. I'm happy Arlin's suggestion worked, I will take note. regards, ctopher
 
Yeah, I have begun to edit this macro and I am loving it already. This is going to be one of the more useful macros I use.
 
aamoroso:
Glad to help. If you need any more help or have any questions, let me know.
 
This is a Function from a batch-program i've written:

Code:
Function GetAllFiles(ByVal path As String, ByVal filespec As String, _
    Optional RecurseDirs As Boolean) As Collection
    
    Dim spec As Variant
    Dim file As Variant
    Dim subdir As Variant
    Dim subdirs As New Collection
    Dim specs() As String
    
    ' initialize the result
    Set GetAllFiles = New Collection
    DoEvents
    ' ensure that path has a trailing backslash
    If Right$(path, 1) <> "\" Then path = path & "\"
    
    ' get the list of provided file specifications
    specs() = Split(filespec, ";")
    
    ' this is necessary to ignore duplicates in result
    ' caused by overlapping file specifications
    On Error Resume Next
                
    ' at each iteration search for a different filespec
    For Each spec In specs
        ' start the search
        file = Dir$(path & spec)
        Do While Len(file)
            ' we've found a new file
            file = path & file
            GetAllFiles.Add file, file
            
            fCount = fCount + 1: fcountlbl.Caption = fCount & " files found..."
            
            ' get ready for the next iteration
            file = Dir$
        Loop
    Next
    
    ' first, build the list of subdirectories to be searched
    If RecurseDirs Then
        ' get the collection of subdirectories
        ' start the search
        file = Dir$(path & "*.*", vbDirectory)
        Do While Len(file)
            ' we've found a new directory
            If file = "." Or file = ".." Then
                ' exclude the "." and ".." entries
            ElseIf (GetAttr(path & file) And vbDirectory) = 0 Then
                ' ignore regular files
            Else
                ' this is a directory, include the path in the collection
                file = path & file
                subdirs.Add file, file
            End If
            ' get next directory
            file = Dir$
        Loop
        
        ' parse each subdirectory
        For Each subdir In subdirs
            ' use GetAllFiles recursively
            For Each file In GetAllFiles(subdir, filespec, True)
                GetAllFiles.Add file, file
            Next
        Next
    End If
    
End Function
 
I, too, have a recursive search function for SWX files,API based. But I use it to seed a database with not only DXFs, but export paths and dates....it seems the most robsut solution may be to add a field or 2 in your database....
 
aamoroso,
I see you’re already set to go on your new macro. (Please do not take me wrong.) I love writing macros. One of the things I always forget is, do not spend more time writing a macro than it saves. I have spent 80 hours writing a macro that saved 1 hour per week. I would do it again because of the frustration it saved.
With that being said, I would recommend looking into getting SolidWorks PDM\Works. We use it and just love it. Drawings are fast to find, it keeps history and easy to use. We have saved thousands of dollars restoring files that someone has messed up. Once an assembly is in the PDM it does not get lost. We have lost lots of files while keeping them on the network.
Good luck with your macro.


Bradley
 
Thanx Brad, I agree it is easy to get caught up in a macro, the decision to persue this one was based on some outside projects. The production team works off of DXF files, and they call engineering when there is a question, well most of the "in-house" work is near top level in our file hierchy (I know I spelled that wrong) but the outside projects tend to be burried 10 - 15 levels deep in some cases. We have had one customer start to dominate our outside work and now have accumulated thousands of files for them. It is when the shop calls for questions on thier parts that it is beneficial to the engineer to punch in the part number and viola a drawing opens. Any way back to the subject, yeah macros are fun and I do enjoy working on them, I only hope that they remain usable long enough to pay off. I hate to see them go obsolete on me.
 
For components that do not have meaningful names we start .bat file with dir command that writes all files with paths from subdirectories into one logfile and our custom search program is able to quickly find file and open them by using this logfile.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor