Example - Addin
Example - Addin
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.
-1-
serviceManager)
{
}
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-
newItem.SubItems.Add(value);
this.listView1.Items.Add(newItem);
}
7 using Aveva.ApplicationFramework.Presentation;
using System; The command needs to derive from
Aveva.ApplicationFramework.Presen
namespace Aveva.TechCon.Examples tation.Command 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)
{
}
-3-
void Instance_WindowLayoutLoaded(object sender, window visibility
EventArgs e)
{
this.Checked = _window.Visible;
}
12 public override void Execute() Show or hide the window in the
{ Execute() method.
if (this.Checked)
{
_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)serviceManager.GetService(typeof(Windo WindowManager service
wManager)); and create the Addin window
attributeListControl = new AttributeListControl();
void CurrentElement_CurrentElementChanged(object
sender, CurrentElementChangedEventArgs e)
{
}
19 string windowTitle = "Attributes of element " + In the event handler populate the
CurrentElement.Element.GetAsString(DbAttributeInstanc ListView
e.FLNM);
attributeListWindow.Title = windowTitle;
attributeListControl.Clear();
-4-
attributeListControl.AddAttribute(attribute.Name,
CurrentElement.Element.GetAsString(attribute));
}
Build the Project
20 Build the project and copy the
assembly to your %PDMSEXE%
directory
Update Addins XML file: DesignAddins.xml
21 <?xml version="1.0" encoding="utf-8"?> Add the AttributeBrowserAddin to
<ArrayOfString the DesignAddins.xml file. This will
xmlns:xsd="http://www.w3.org/2001/XMLSchema" then be loaded when the application
xmlns:xsi="http://www.w3.org/2001/XMLSchema- 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-