0% found this document useful (0 votes)
45 views6 pages

Example - Addin

Example - Addin

Uploaded by

QuangTonthat
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
45 views6 pages

Example - Addin

Example - Addin

Uploaded by

QuangTonthat
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 6

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:
Aveva.TechCon.Examples

2 using Aveva.ApplicationFramework; Add a new class


using Aveva.ApplicationFramework.Presentation; AttributeBrowserAddin.
using Aveva.Pdms.Shared;
using Aveva.Pdms.Database; Add references to
using Aveva.Pdms.Utilities;
Aveva.ApplicationFramework
Aveva.ApplicationFramework.P
namespace Aveva.TechCon.Examples resentation;
{ Aveva.Pdms.Shared;
public class AttributeBrowserAddin : IAddin Aveva.Pdms.Database;
{ Aveva.Pdms.Utilities;
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-
newItem.SubItems.Add(value);
this.listView1.Items.Add(newItem);
}

public void Clear()


{
this.listView1.Items.Clear();
}
Add a Class: ShowAttributesCommand
6 Add another new class
ShowAttributesCommand to the
project. This command will show the
attributes browser.

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)
{
}

public override void Execute()


{
}
}
}
8 this.Key = "Aveva.ShowAttributeBrowserCommand"; 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
this.Checked = false;
}
11 WindowManager.Instance.WindowLayoutLoaded += 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)
{
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();

15 attributeListWindow = Create a docked window to host an


windowManager.CreateDockedWindow("Aveva.AttributeBrow AttributeListControl
ser.AttributeList", "Attributes",
attributeListControl, DockedPosition.Right);
attributeListWindow.Width = 200;
16 attributeListWindow.SaveLayout = true; Docked windows created at addin
start should ensure their layout is
saved between sessions.

17 CommandManager commandManager = Get the CommandManager and


(CommandManager)serviceManager.GetService(typeof(Comm create and register addins commands
andManager));

ShowAttributesCommand showCommand = new


ShowAttributesCommand(attributeListWindow);
commandManager.Commands.Add(showCommand);
18 CurrentElement.CurrentElementChanged += 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
CurrentElement.Element.GetAsString(DbAttributeInstanc ListView
e.FLNM);

attributeListWindow.Title = windowTitle;
attributeListControl.Clear();

foreach (DbAttribute attribute in


CurrentElement.Element.GetAttributes())
{

-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-

You might also like