multiple file selection in macro
multiple file selection in macro
(OP)
I have several macros that do various things to drawings (alter file names, save as PDF, change revisions, sign offs etc). Right now I either have the macro process a whole directory, or all open files. Is there a way to use a dialog to select multiple files, and I guess it would return an array of files I can iterate through?






RE: multiple file selection in macro
-handleman, CSWP (The new, easy test)
RE: multiple file selection in macro
btw, the macro on that 2nd link doesnt work. It crashes and says my machine is out of memory and a couple other goofy things.
RE: multiple file selection in macro
Any links to snippets that might show how this is done? I can write everything in SW API easily, 'cept the multiple file/add etc setup. So this might be a good project to learn with!
RE: multiple file selection in macro
-handleman, CSWP (The new, easy test)
RE: multiple file selection in macro
To add one file at a time, leave the box on the form un-checked. This will use the SolidWorks GetOpenFileName function, which only allows for one file at a time to be selected but it shows the thumbnail preview, etc. Checking the Multi-Select box will cause SW to create an instance of Excel and use the multiple file selection capability of Excel's API to select multiple files at once. All files selected by either method are added to the list on the form. The code checks for files that are already in the list, so duplicates can't be introduced. However, there is no error checking for the user simply typing in some name that doesn't exist, so the macro you use will have to check for the possibility of non-existent files.
-handleman, CSWP (The new, easy test)
RE: multiple file selection in macro
Dim arr() As String
s = Dir("C:\temp\*", vbNormal)
ReDim arr(0)
Do While s <> ""
Select Case MsgBox("Add file " & s & " to array?", vbYesNoCancel Or vbExclamation Or vbDefaultButton1, App.Title)
Case vbYes
arr(UBound(arr)) = s
ReDim Preserve arr(UBound(arr) + 1)
Case vbNo
Case vbCancel
Exit Do
End Select
s = Dir
Loop
RE: multiple file selection in macro
Handle, thanks I just downloaded the file and am going to look at it.
Any comments on launching SW functions from a general VB program?
RE: multiple file selection in macro
1. Lots of stuff going on that's not particularly related to SW - database stuff, external calculations, etc. A compiled .exe will run faster, although not noticeably unless you are really doing a lot.
2. More GUI stuff available, including file/folder browsing.
3. Better IDE.
4. More code security if you care about that stuff. It's harder (although far from impossible) to reverse-engineer compiled code than a .swp!
Reasons to use a SolidWorks macro include:
1. Easier to integrate into SolidWorks - you can make a button or shortcut key for a macro very easily.
2. Slightly easier to code, since you are controlling SolidWorks with SolidWorks.
3. Easy to tweak/improve after you get it working - no recompiling, etc.
4. Everything is in one file rather than a collection of files.
-handleman, CSWP (The new, easy test)
RE: multiple file selection in macro
http
It has a good interface to select files in a directory.
-Dustin
Professional Engineer
Certified SolidWorks Professional
Certified COSMOSWorks Designer Specialist
Certified SolidWorks Advanced Sheet Metal Specialist