![]() |
【转帖】batch w user input macro
batch w/ user input macro
hello, i'm relatively new to solidworks api development (and vb), and i've written a macro in order to save a coordinate system based on axis selection. the macro is based loosely on the solidworks "vba_propertymanagerpage.swp" and works well for single files. i have written the batch macro below in order to automate the open/close keystrokes for a large number of files as well as call the coordinate save macro. i am having problems with the batch process waiting for the macro to receive user input (and complete the macro's operations) before closing the file and opening the next. i will open the propertymanager page, and then proceed to close the file and open the next (without waiting for a okay/cancel from the user). is there a good way to go about waiting for the macro to finish before closing the file? am i going about this the wrong way? any help is appreciated. global swapp as sldworks.sldworks global swmodel as sldworks.modeldoc2 sub main() dim spath as string dim sfilespec as string dim sfile as string dim sfilelist() as string dim sfilename as string dim mfilename as string dim i as integer dim bret as boolean dim boolfiles as boolean dim fileerror as long dim filewarning as long 'set console standards set swapp = application.sldworks swapp.visible = true 'set macro filname variable mfilename = "c:\\propertymanagerfunctionedv2.swp" ' get folder spath = "c:\\api test part" 'spath = inputbox("enter job folder folder to process", "batch", "") ' clean up spath = trim(spath) if right(spath, 1) <> "\" then spath = spath & "\" debug.print spath ' add solidworks extention sfilespec = spath & "*.sldprt" ' get all filenames in the folder sfile = dir$(sfilespec) 'loop to set file name array i = -1 do until sfile = "" i = i + 1 redim preserve sfilelist(i) as string sfilelist(i) = sfile sfile = dir$ loop 'check for correct folder debug.print ubound(sfilelist) if ubound(sfilelist) < 0 then msgbox ("no .sldprt files in this folder!! please rerun macro and select another.") end if ' process each file for i = 0 to ubound(sfilelist) debug.print "filename" & i; ": " & spath & sfilelist(i) swapp.opendoc6 spath & sfilelist(i), swdocpart, swopendocoptions_silent, "", fileerror, filewarning set swmodel = swapp.activedoc 'call the coord save macro bret = swapp.runmacro(mfilename, "macro11", "main") ' release the part pointer, close file set part = nothing swapp.closedoc sfilename next i ' release dynamic array erase sfilelist end sub look at this example thanks for the link ivana, i've set the propertymanager page to 'fixed' - which seemed to fix lenny's problem of a closing page. however, my batch macro still closes the file before the user can make a selection/access the propertymanager page. is there a wait comment that i should be using after my swapp.runmacro(mfilename, "macro11", "main") command? quick |
所有的时间均为北京时间。 现在的时间是 01:57 AM. |