![]() |
【转帖】proccessing multiple files with api
proccessing multiple files with api
i would like to add a list of user selected files to a macro but i'm not sure where to start re achieving this goal, essentially to extend a save as pdf etc macro to more than one file. i have used the task manager but would like to add in the current revison etc. any suggestions, example macros (i have been looking but none to date), and/or suggested reading thanks john john fisher there are many ways to do this. what do you have in mind for a process? if you already have a macro for saving a single file, make that entire code into a module/method/function that accepts a filename as a variable, and then you can simply change the part of the code that asks the user for the filename and replace it with the variable passed in. then in the main code ask the user for the files (using a list where they can add files one at a file, select mutliple, or select a folder), and then with that list simply loop each file in a for loop and pass it into the function. there are however another 100 ways to achieve this goal but it all depends on your preference and requirements. i see two scenerios both while running solidworks (note i'm quite new to api) open a dwg in solidworks initiate the macro the macro would then loop through all the files in the currently directory of drawingdoc type or when wanting to select a range of files (from a large directory) initiate the macro enter required files in a list box start the print/export process via a button re using a list box, is it possible to define an array with a variable (driven by the number of selections) then use an if - next loop to process? thanks for your input john fisher this reply is a little late, but if you would like to process a directory for all files in the directory, here's my fav. code snippet. you'll need to add a referenc to microsoft scripting runtime library. this code is vb6 (macro flava), but it ports well to .net if needed. dim mypath as string mypath = "c:\temp\" 'set to desired folder to process dim fso as scripting.filesystemobject set fso = createobject("scripting.filesystemobject") dim myfiles as scripting.files set myfiles = fso.getfolder(mypath).files dim myfile as scripting.file for each myfile in myfiles 'process the file here... debug.print myfile.name debut.print myfile.path next myfile mike spens "automating solidworks using macros" leap frog leap pad x64 this thread comes at the right time for me i'm looking for something that saves all the drawing document in a folder as pdf file. if any one got something pleas post it if possible mohamed abdel moniem | mechanical engineer cswp, cswa, cswp core, cswp-smtl solidworks 2009 sp3.0 vista x64 sp1.0 intel q6600, 8gb ram ati hd 4850 3dconnexions spacenavigator all you'll need is the following additional code to upen the drawing, then save it as a pdf. add this in the for loop of the code earlier in the thread. '=========== dim pathsize as long dim pathnoextension as string dim newfilepath as string pathsize = strings.len(myfile.path) pathnoextension = strings.left(filepath, pathsize - 6) 'remove extension newfilepath = pathnoextension & "pdf" dim mydoc as sldworks.modeldoc2 dim longerrors as long dim longwarnings as long set mydoc = swapp.opendoc6(myfile.path, swdocdrawing, _ swopendocoptions_silent, "", longerrors, longwarnings) mydoc.saveas2 newfilepath, 0, true, false swapp.closedoc mydoc.gettitle '=========== **i don't have the declaration or attachment to swapp in this code, so make sure it is in your macro. if you want to filter drawings, you can check myfile.extension to see if it is slddrw before opening and saving as pdf. mike spens "automating solidworks using macros" leap frog leap pad x64 quick |
所有的时间均为北京时间。 现在的时间是 12:42 PM. |