Fire Notification When Activating a Sheet Example (C#)
This example shows how to fire a notification when a sheet is activated in a
drawing document.
//---------------------------------------------------------------
//Preconditions:
// 1. Open
// install_dir\samples\tutorial\advdrawings\foodprocessor.slddrw.
// 2. Run this macro (press F5).
//
// Postconditions: A message box informs you that a sheet is about to be
// activated. Click OK to close the message box.
//
// NOTE: The IDrawingDoc ActivateSheetPostNotify event only fires
// when a sheet is interactively activated in SOLIDWORKS; this event
// does not fire when a sheet is activated through the API.
//---------------------------------------------------------------
using SolidWorks.Interop.sldworks;
using SolidWorks.Interop.swconst;
using System;
using System.Diagnostics;
using System.Windows.Forms;
namespace ActivateSheetEventsCSharp.csproj
{
public partial class SolidWorksMacro
{
public DrawingDoc swDrawingDoc;
public void Main()
{
ModelDoc2 swModel;
Boolean status;
swModel = (ModelDoc2)swApp.ActiveDoc;
//Set up events
swDrawingDoc = (DrawingDoc)swModel;
AttachEventHandlers();
// Activate Sheet 4
status = swDrawingDoc.ActivateSheet("Sheet4");
}
public void AttachEventHandlers()
{
AttachSWEvents();
}
public void AttachSWEvents()
{
swDrawingDoc.ActivateSheetPreNotify += this.swDraw_ActivateSheetPreNotify;
}
private int swDraw_ActivateSheetPreNotify(string SheetName)
{
MessageBox.Show("A sheet is about to be activated.");
return 1;
}
/// <summary>
/// The SldWorks swApp variable is pre-assigned for you.
/// </summary>
public SldWorks swApp;
}
}