Example: Creating a .
NET Addin
In this example you’ll create a simple addin in Visual Studio. The addin will register a command with the
command manager which will show a docked form containing database attributes.
Add a Class: AttributeBrowserAddin
1 Create a new C# class library called
AttributeBrowserAddin
Set the namespace in Project
Settings to:
[Link]
2 using [Link]; Add a new class
using [Link]; AttributeBrowserAddin.
using [Link];
using [Link]; Add references to
using [Link];
[Link]
[Link].P
namespace [Link] resentation;
{ [Link];
public class AttributeBrowserAddin : IAddin [Link];
{ [Link];
public string Description
{
implement the IAddin interface
get
methods Description, Name, Start
{
return "a simple attribute browser"; and Stop
}
}
public string Name
{
get
{
return "AttributeBrowserAddin";
}
}
public void Start(ServiceManager
-1-
serviceManager)
{
}
public void Stop()
{
}
}
}
Add a Class: AttributeListControl
3 Add a new user control
AttributeListControl to the project.
4 In the designer add a ListView to the
user control and set it’s dock
property to Fill
(Use View>Toolbox)
Add 2 columns Attribute and Value
to the ListView
Set the GridLines property to True
Set the View property to Details
Build the project
5 public void AddAttribute(string name, string value) Add methods to the control to add an
{ attribute to the list and clear the list
ListViewItem newItem = new ListViewItem(name);
-2-
[Link](value);
[Link](newItem);
}
public void Clear()
{
[Link]();
}
Add a Class: ShowAttributesCommand
6 Add another new class
ShowAttributesCommand to the
project. This command will show the
attributes browser.
7 using [Link];
using System; The command needs to derive from
[Link]
namespace [Link] [Link] and implement the
{ Execute() method which will be
public class ShowAttributesCommand : Command
called when the tool associated with
{
it is clicked.
private DockedWindow _window;
public ShowAttributesCommand(DockedWindow
window)
{
}
public override void Execute()
{
}
}
}
8 [Link] = "[Link]"; In the constructor set the command
key
9 _window = window; Save the docked window
10 _window.Closed += new EventHandler(_window_Closed); Add an event handler for when the
window closes. This will update the
void _window_Closed(object sender, EventArgs e) command state when the window is
{ closed
[Link] = false;
}
11 [Link] += new Add an event handler for when the
EventHandler(Instance_WindowLayoutLoaded); window is first loaded. Update the
command state to match initial
-3-
void Instance_WindowLayoutLoaded(object sender, window visibility
EventArgs e)
{
[Link] = _window.Visible;
}
12 public override void Execute() Show or hide the window in the
{ Execute() method.
if ([Link])
{
_window.Show();
}
else
{
_window.Hide();
}
}
Update the class: AttributeBrowesrAddin
13 private DockedWindow attributeListWindow; Going back to the addin class
private AttributeListControl attributeListControl; (AttributeBrowserAddin), add 2
private members
14 WindowManager windowManager = In the Start() method Get the
(WindowManager)[Link](typeof(Windo WindowManager service
wManager)); and create the Addin window
attributeListControl = new AttributeListControl();
15 attributeListWindow = Create a docked window to host an
[Link]("[Link] AttributeListControl
[Link]", "Attributes",
attributeListControl, [Link]);
[Link] = 200;
16 [Link] = true; Docked windows created at addin
start should ensure their layout is
saved between sessions.
17 CommandManager commandManager = Get the CommandManager and
(CommandManager)[Link](typeof(Comm create and register addins commands
andManager));
ShowAttributesCommand showCommand = new
ShowAttributesCommand(attributeListWindow);
[Link](showCommand);
18 [Link] += new Add event handler for current
CurrentElementChangedEventHandler(CurrentElement_Curr element changed event.
entElementChanged);
void CurrentElement_CurrentElementChanged(object
sender, CurrentElementChangedEventArgs e)
{
}
19 string windowTitle = "Attributes of element " + In the event handler populate the
[Link](DbAttributeInstanc ListView
[Link]);
[Link] = windowTitle;
[Link]();
foreach (DbAttribute attribute in
[Link]())
{
-4-
[Link]([Link],
[Link](attribute));
}
Build the Project
20 Build the project and copy the
assembly to your %PDMSEXE%
directory
Update Addins XML file: [Link]
21 <?xml version="1.0" encoding="utf-8"?> Add the AttributeBrowserAddin to
<ArrayOfString the [Link] file. This will
xmlns:xsd="[Link] then be loaded when the application
xmlns:xsi="[Link] runs.
instance">
<string>ExplorerAddin</string>
<string>DrawListAddin</string>
<string>MyDataAddin</string>
<string>HistoryAddin</string>
<string>ReferenceListAddin</string>
<string>PipeCheckAddin</string>
<string>OutputAddin</string>
<string>FindAddin</string>
<string>LinksAddin</string>
<string>AttributesAddin</string>
<string>ScheConnMapAddin</string>
<string>CatalogSearchAddin</string>
<string>AttributeBrowserAddin</string>
</ArrayOfString>
Enter PDMS Design and add a menu to show the addin
22 Create a CommandBar state button
and attach it to the command
ShowAttributeBrowserCommand
-5-
Run the Addin
24 Execute the command to show the
form.
-6-