In this Part, we will learn about MicroStation Events. The following table lists the most common event types and event handlers.
|
Event type |
Event handler |
|
Reference design file |
ReferenceAttachedEvent method |
|
Uninstall reference files |
ReferenceDetachedEvent method |
|
Open or close the design file |
NewDesignFileEvent (attached to NewDesignFileEvent) |
|
Save As command |
FileSaveAsEvent method |
|
Activation model |
ModelChangedEvent method |
|
Tracking element changes |
ElementChangedEvent methods |
|
Selection set changes |
SelectionChangedEvent method |
|
Layer changes |
LevelChangeEvent method |
|
Select different views |
SelectedViewChangedEvent method |
|
Uninstall program |
UnloadAnyAppEvent method |
In this part, we will use ILevelChangeEvents and NewDesignFileEventHandler. This example shows the layers in the current DGN file in a dialog box. If you add, delete, or rename a layer in MicroStation's layer manager, the layer information in this dialog box is modified synchronously. In addition, when you open a new file, the layer information in the dialog box is automatically updated. Below we will step by step to construct this function.
1. Create a new WinForm in your VS, name it LevelChangedForm, and add a unique list box control to it. The generated form is shown below:
Properties:
2. Open LevelChangedForm.cs in code mode and modify its content. Here are a few things to note:
3. Open the commands.xml file, add the command csAddins DemoForm LevelChanged, and specify its processing function as csAddins.DemoForm.LevelChanged. If you are not familiar with XML format command list files, please refer to the related topics in Chapter 4.
4. Open DemoForm.cs, turn to the end of the code and add the command processing function LevelChanged as follows. This code opens the LevelChangedForm in Singleton mode, which guarantees that only one form can be opened at the same time.
private static LevelChangedForm myLevelForm = null;
public static void LevelChanged(string unparsed)
{
if (myLevelForm == null || myLevelForm.IsDisposed)
{
myLevelForm = new LevelChangedForm();
myLevelForm.AttachAsTopLevelForm(MyAddin.Addin, false);
myLevelForm.Show();
}
else
myLevelForm.Activate();
}
5. Rebuild csAddins in VS. Then start MicroStation, type mdl load csAddins to load csAddins, and then type csaddins demoform levelchanged to open the LevelChanged form. Open MicroStation's layer manager, as shown in the figure below. When you add, delete or rename a layer in the Level Manager window, the display in our LevelChanged form will also be updated immediately. You can also test further by opening another DGN, and you will find that the content in the LevelChanged form will change as a new file is opened.
| Prev:[[Use DgnPrimitiveTool and DgnElementSetTool to implement interactive commands]] | Next:[[Calling C/C++ Functions in Add-ins]] |