CTInterfaceOnSavePost Event |
Namespace: ATR.CT.CTInterface
using System; using System.IO; using System.Collections.Generic; using System.Text; using System.Windows.Forms; using CTEngineLib; using ATR.CT.CTInterface; using SolidWorks.Interop.sldworks; using SolidWorks.Interop.swconst; using SolidWorks.Interop.swdocumentmgr; namespace GetDocumentTypeAfterSave { public class GetDocumentTypeAfterSave { public GetDocumentTypeAfterSave(CTInterface ctInterface) { // Attach event handler to catch the OnSavePost event. ctInterface.OnSavePost += new EventHandler<CTInterface.SavePostArgs2>(_ctInterface_OnSavePostEvent); } void _ctInterface_OnSavePostEvent(object sender, CTInterface.SavePostArgs2 e) { // Check the SW document type. If the document is not a model, the SQL Server connection is not needed. if (e.moFilename.EndsWith(".sldasm", true, null) | e.moFilename.EndsWith(".sldprt", true, null)) { // Initialize the ModelDoc2 object. ModelDoc2 oDoc = (ModelDoc2)e.moSWDoc; // Ensure that the model exist. If not, just return and do nothing. if (oDoc == null) return; // In case the model exist as expected, show a message box to the user having notice that we have saved a model document type and also show the filename. MessageBox.Show(string.Format(@"We have saved a SOLIDWORKS model document which file name is {0}.", e.moFilename), "Information"); } } } } // Sample output: // -------------- // Let's say that the user have created a SOLIDWORKS part document called Part1.sldprt into folder C:\Workspace\SolidWorks\ // So, using the script implementation above, the message box with a text like "We have saved a SOLIDWORKS model document which file name is C:\Workspace\SolidWorks\Part1.sldprt.".
CUSTOMTOOLS 2013 SP3