|
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. |
|