几何尺寸与公差论坛------致力于产品几何量公差标准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-13, 10:45 AM   #1
yang686526
高级会员
 
注册日期: 06-11
帖子: 14579
精华: 1
现金: 224494 标准币
资产: 234494 标准币
yang686526 向着好的方向发展
默认 【转帖】event triggering

event triggering
hello all,
i have written a macro using the editor within sw but when i come to run it i get the following error:
swmacro file has wrong format and cannot be converted to vba macro file
the file contains these sections:
thislibrary
==================================
private sub workspace_startup()
dim t as new class1
msgbox "class initialised"
end sub
==================================
class1
==================================
option explicit
dim swapp as object
private withevents swapp as sldworks.sldworks
private sub class_initialize()
set swapp = getobject(, "sldworks.application")
end sub
private function swapp_referencenotfoundnotify(byval filename as string) as long
msgbox "reference not found: " & filename
end function
==================================
anyone have any ideas why this cannot be run?
thanks
i believe a sw macro requires that there is a "sub main()". there was a time when sw also required that sub main() be at the bottom of the main module.
thanks roland,
i have moved the code from the thislibrary section into the modules section and made the modifications as suggested:
sub main()
dim t as new class1
msgbox "class initialised"
end sub
i can now runt he macro but none of the events trigger - would you have any idea why?
thanks
try this:
' ========================================================================
' ========================================================================
option explicit
public t as class1
sub main()
set t = new class1
t.monitorsolidworks
end sub
' ========================================================================
'class1
' ========================================================================
option explicit
public withevents swapp as sldworks.sldworks
public sub monitorsolidworks()
set swapp = application.sldworks
end sub
private function swapp_referencenotfoundnotify(byval filename as string) as long
msgbox "!!!!reference not found: " & filename
end function
you're a star wally,
thanks very much.
i assume that if i do this:
private function swapp_referencenotfoundnotify(byval filename as string) as long
msgbox "!!!!reference not found: " & filename
swapp_referencenotfoundnotify = s_false
end function
i can stop the existing dialog box from appearing after my one?
if that is correct, do you know which reference i need to add as it does not recognise s_false
thanks
i'm not sure what you're trying to do.
you only want the message box to alert you once if a single reference is missing?
what about messages for any other files?
you can put the msgbox into a conditional statement inside the notify event.
dim trigger = 0
if trigger = 0 then
msgbox("missing reference")
end if
trigger = 1
wally,
although the code you provided triggered and produced the message box as i wanted, when you clicked ok the original reference missing dialog appears afterwards (the one created by sw).
what i want to do is stop the second original one from appearing.
does that make sense?
thanks
i have managed to get to this stage:
private function swapp_referencenotfoundnotify(byval filename as string) as long
dim searchlocations(0) as string
dim i as integer
searchlocations(0) = "c:\temp"
for i = lbound(searchlocations) to ubound(searchlocations)
call searchfolderlist(searchlocations(i), filename)
if (newfilelocation <> "") then
swapp.setmissingreferencepathname newfilelocation
end if
next
end function
although the code does not produce any errors, i still get a dialog box produced by sw indicating that there are references missing.
it appears that either the setmissingreferencepathname method doesn't work or the way i am using it is wrong.
can anyone offer some advise?
thanks
this is probably not the answer you are looking for, but there's a "don't ask me again" check box for solidworks missing reference dialog. would clicking that solve your problem?
as a side note: on sw2008 sp3 when the "don't ask me again" is set for that dialog, you can not unsuppress a "lost" component in the assembly tree.
just engaging the referencenotfoundnotify event does not squelch the "file not found" dialog.
what you can try is opening the document using the option swopendocoptions_silent with opendoc6.
also, you are skipping this step:
swapp_referencenotfoundnotify = s_false 'or use long value 1 for s_false
that step is necessary to confirm changes to your file reference.
thanks everyone for your help,
i have now managed to solve that problem.
yang686526离线中   回复时引用此帖
GDT自动化论坛(仅游客可见)
回复


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

高级搜索
显示模式

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

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



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


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