I'm trying to get some code to run whenever a document is saved. Can anyone advise?
Catch one of the following events:
for Part, Assembly and Drawing documents.
Nice one Ta.
How exactly do I use this to monitor for any save event, at any time, and keep monitoring ? I've found examples based on forms that monitor for any save event, but the functinon part of the code is not clear at all. All I want is an example that could (for example) display a msgbox on the FileSavePostNotifyEvent.
Please find a sample macro in the attachment.
This doesn't work at all...
What the error (please attahc the screenshot)?
The Part Document must be opened before running the macro.
Not sure what your experience level is with SW API and VBA or whatever language you intend to program in - sounds like you may be a bit of a novice? I'm not trying to put you down or anything, just need to confirm where the starting point is.
Basically, this is likely going to be a bit more involved than it seems on the surface. You need to know exactly when you want your code to run and what file you want to run it on.
All of the OnSave type events are fired for specific types of documents - PartDoc, AssemblyDoc, and DrawingDoc. Your code will have to have a variable for whatever type of document you are trying to save.
If you want code to run whenever the active document is saved, you will need to have code in your macro that monitors the SldWorks application object for the ActiveDocChangeNotify event, and assign the new active document to the proper type of specific document object.
SolidWorks often saves a document that is not the active document. For example, if you insert a part into an assembly, switch to the part, change it, then switch back to the assembly and save the assembly, the part document is automatically saved. If you want to be notified any time any document open in SW memory is saved, you will have to get a variable for every single open document in SW, and manage them all. That means cleaning them up when SW closes them, monitoring SW for any new documents that open, etc. I've never really considered even trying to do this, but it may be possible.
Events are only available for use in class objects or in forms, not in modules. You must either use a form or wrap your objects in a class module.
You need to use early binding and "Withevents" qualifier to define your object variables.
Dim WithEvents swApp as Sldworks.SldWorks
Retrieving data ...