几何尺寸与公差论坛

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

【转帖】event triggering

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

本版积分规则

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

GMT+8, 2024-12-24 02:47 , Processed in 0.036909 second(s), 19 queries .

Powered by Discuz! X3.4 Licensed

© 2001-2023 Discuz! Team.

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