几何尺寸与公差论坛

 找回密码
 注册
查看: 857|回复: 0

【转帖】batch w user input macro

[复制链接]
发表于 2009-4-12 20:17:27 | 显示全部楼层 |阅读模式
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
您需要登录后才可以回帖 登录 | 注册

本版积分规则

QQ|Archiver|小黑屋|几何尺寸与公差论坛

GMT+8, 2024-12-23 05:45 , Processed in 0.035831 second(s), 19 queries .

Powered by Discuz! X3.4 Licensed

© 2001-2023 Discuz! Team.

快速回复 返回顶部 返回列表