几何尺寸与公差论坛------致力于产品几何量公差标准GD&T (GDT:ASME)|New GPS(ISO)研究/CAD设计/CAM加工/CMM测量  


返回   几何尺寸与公差论坛------致力于产品几何量公差标准GD&T (GDT:ASME)|New GPS(ISO)研究/CAD设计/CAM加工/CMM测量 » 仿射空间:CAX软件开发(三)二次开发与程序设计 » CAD二次开发 » SolidWorks二次开发
用户名
密码
注册 帮助 会员 日历 银行 搜索 今日新帖 标记论坛为已读


 
 
主题工具 搜索本主题 显示模式
旧 2009-04-12, 08:17 PM   #1
yang686526
高级会员
 
注册日期: 06-11
帖子: 14579
精华: 1
现金: 224494 标准币
资产: 234494 标准币
yang686526 向着好的方向发展
默认 【转帖】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
yang686526离线中   回复时引用此帖
GDT自动化论坛(仅游客可见)
 


主题工具 搜索本主题
搜索本主题:

高级搜索
显示模式

发帖规则
不可以发表新主题
不可以回复主题
不可以上传附件
不可以编辑您的帖子

vB 代码开启
[IMG]代码开启
HTML代码关闭

相似的主题
主题 主题发起者 论坛 回复 最后发表
【转帖】run macro when saving yang686526 SolidWorks二次开发 0 2009-04-12 07:29 PM
如何用用程序模拟键盘来控制 Media Player 7? huangyhg vc编程 9 2007-11-14 09:18 AM


所有的时间均为北京时间。 现在的时间是 09:11 AM.


于2004年创办,几何尺寸与公差论坛"致力于产品几何量公差标准GD&T | GPS研究/CAD设计/CAM加工/CMM测量"。免责声明:论坛严禁发布色情反动言论及有关违反国家法律法规内容!情节严重者提供其IP,并配合相关部门进行严厉查处,若內容有涉及侵权,请立即联系我们QQ:44671734。注:此论坛须管理员验证方可发帖。
沪ICP备06057009号-2
更多