基本使用

  1. 新建类库项目 PdmsAddin
  2. 引入以下PMDS程序集(在PDMS安装目录下可以找到)
  • Aveva.ApplicationFramework.dl
  • Aveva.ApplicationFramework.Presentation.dll
  1. 新建 PdmsAddin类 ,添加如下代码
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
public class PdmsAddin : IAddin
{
public void Start(ServiceManager serviceManager)
{
System.Windows.MessageBox.Show("Hello Pdms");
}

public void Stop()
{

}

public string Name => "Pdms Addin";
public string Description => "Pdms Addin";
}
  1. 生成解决方案,将生成的PdmsAddin.dll文件拷贝到PMDS安装路径下的MyAddins目录下
  2. 编辑PDMS安装目录下的DesignAddins.xml,添加一条如下记录
1
<string>MyAddins\PdmsAddin</string>

停靠窗口

  1. 新建DockedWindowCmd类,添加如下代码
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
public class DockedWindowCmd : Command
{
private readonly DockedWindow _myWindow;

public DockedWindowCmd(WindowManager windowManager)
{
base.Key = "PdmsAddin.DockedWindowCmd";

MainView wpfMainView = new MainView(); // 这是一个wpf用户控件
ElementHost wpfHost = new ElementHost(); // 在.csproj中启用WindowsForm: <UseWindowsForms>true</UseWindowsForms>
wpfHost.Child = wpfMainView;

_myWindow = windowManager.CreateDockedWindow(
key: "CreateDockedWindow" , // 必须唯一
title: "MyDockedWindow",
control: wpfHost,
position: DockedPosition.Right
);

_myWindow.SaveLayout = true;

windowManager.WindowLayoutLoaded += WindowManagerOnWindowLayoutLoaded;

_myWindow.Closed += MyWindowOnClosed;

this.ExecuteOnCheckedChange = false;
}

private void MyWindowOnClosed(object sender,EventArgs e)
{
this.Checked = false;
}

private void WindowManagerOnWindowLayoutLoaded(object sender,EventArgs e)
{
this.Checked = _myWindow.Visible;
}

public overrider void Execute()
{
try
{
if(_myWindow.Visible)
{
_myWindow.Hide();
}
else
{
_myWindow.Show();
}

base.Execute();
}
catch(Exception ex)
{
System.Windows.MessageBox.Show(ex.Message);
}
}
}
  1. 修改PdmsAddin类内容如下
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
public class PdmsAddin : IAddin
{
public void Start(ServiceManager serviceManager)
{
WindowManager windowManager = (WindowManager)serviceManager.GetService(typeof(WindowManager));
CommandManager commandManager = (CommandManager)serviceManager.GetService(typeof(CommandManager));

DockedWindowCmd dockedWindowCmd = new DockedWindowCmd(windowManager);
dockedWindowCmd.Commands.Add(dockedWindowCmd);
}

public void Stop()
{

}

public string Name => "Pdms Addin";
public string Description => "Pdms Addin";
}
  1. 重新生成解决方案,将生成的PdmsAddin.dll文件拷贝到PMDS安装路径下的MyAddins目录下
  2. 编辑PDMS安装目录下的DesignAddins.xml,添加一条如下记录
1
<string>MyAddins\PdmsAddin</string>
  1. 在PMDS安装目录下新建MyUIC目录,将PDMS根目录下的design.uic文件拷贝一份到MyUIC目录,编辑内容如下(删掉多余内容即可)
1
2
3
4
<?xml version="1.0" encoding="utf-8"?>
<UserInterfaceCustomization xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns="www.aveva.com">
<Version>1.0</Version>
</UserInterfaceCustomization>
  1. 编辑PDMS安装目录下的DesignCustomization.xml,添加一条如下记录
1
<CustomizationFileFile Name="MyAddin" Path="MyUIC\MyDesignUic.uic">
  1. 启动PDMS,在菜单栏空白处右键点击最底下的Customize...菜单,弹出Customize窗口

    1. Active Customization File下拉框切换为MyAddin
    2. 选中Command Bars菜单项,右键选择New CommandBar
    3. 右侧可修改CommandBar1菜单项的相关信息,例如将Caption改为MyPdmsAddin,将Name改为MyAddin.MyPdmsAddin
    4. 在侧边工具栏点击倒数第四个图标New StateButton新建带状态的按钮
    5. 右侧可修改StateButton1项的相关信息,例如将Caption改为DockedWindow,将Name改为MyAddin.DockedWindow,将DisplayStyle改为TextOnlyAlways
    6. 最后还需为StateButton设置Command,还是在右侧,点击Command项,在弹出的窗口中找到要绑定的命令的Key,例如DockedWindowCmd的Key为PdmsAddin.DockedWindowCmd
    7. 将新建的StateButton(DockedWindow)拖动到CommandBar
    8. 修改完成后,点击Apply应用更改,关闭Customize窗口后,即可看到工具栏中的DockedWindow按钮

多文档窗口

  1. 新建MdiWindowCmd类,添加如下代码
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
public class MdiWindowCmd : Command
{
private readonly MdiWindow _myWindow;

public DockedWindowCmd(WindowManager windowManager)
{
base.Key = "PdmsAddin.MdiWindowCmd";

MainView wpfMainView = new MainView(); // 这是一个wpf用户控件
ElementHost wpfHost = new ElementHost(); // 在.csproj中启用WindowsForm: <UseWindowsForms>true</UseWindowsForms>
wpfHost.Child = wpfMainView;

_myWindow = windowManager.CreateMdiWindow(
key: "CreateMdiWindow" , // 必须唯一
title: "MyMdiWindow",
control: wpfHost
);

_myWindow.Closing += MyWindowOnClosing;

this.ExecuteOnCheckedChange = false;

_myWindow.Form.TopMost = true;
}

private void MyWindowOnClosing(object sender,CancelEventArgs e)
{
this.Checked = false;

_myWindow.Hide();
e.Cancel = true;
}

public overrider void Execute()
{
try
{
if(_myWindow.Visible)
{
_myWindow.Hide();
}
else
{
_myWindow.Show();
_myWindow.Float();
}

base.Execute();
}
catch(Exception ex)
{
System.Windows.MessageBox.Show(ex.Message);
}
}
}
  1. 修改PdmsAddin类内容如下
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
public class PdmsAddin : IAddin
{
public void Start(ServiceManager serviceManager)
{
WindowManager windowManager = (WindowManager)serviceManager.GetService(typeof(WindowManager));
CommandManager commandManager = (CommandManager)serviceManager.GetService(typeof(CommandManager));

MdiWindowCmd mdiWindowCmd = new MdiWindowCmd(windowManager);
commandManager.Commands.Add(mdiWindowCmd);
}

public void Stop()
{

}

public string Name => "Pdms Addin";
public string Description => "Pdms Addin";
}
  1. 重新生成解决方案,将生成的PdmsAddin.dll文件拷贝到PMDS安装路径下的MyAddins目录下
  2. 编辑PDMS安装目录下的DesignAddins.xml,添加一条如下记录
1
<string>MyAddins\PdmsAddin</string>
  1. 在PMDS安装目录下新建MyUIC目录,将PDMS根目录下的design.uic文件拷贝一份到MyUIC目录,编辑内容如下(删掉多余内容即可)
1
2
3
4
<?xml version="1.0" encoding="utf-8"?>
<UserInterfaceCustomization xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns="www.aveva.com">
<Version>1.0</Version>
</UserInterfaceCustomization>
  1. 编辑PDMS安装目录下的DesignCustomization.xml,添加一条如下记录
1
<CustomizationFileFile Name="MyAddin" Path="MyUIC\MyDesignUic.uic">
  1. 启动PDMS,在菜单栏空白处右键点击最底下的Customize...菜单,弹出Customize窗口

    1. Active Customization File下拉框切换为MyAddin
    2. 选中Command Bars菜单项,右键选择New CommandBar
    3. 右侧可修改CommandBar1菜单项的相关信息,例如将Caption改为MyPdmsAddin,将Name改为MyAddin.MyPdmsAddin
    4. 在侧边工具栏点击倒数第四个图标New StateButton新建带状态的按钮
    5. 右侧可修改StateButton1项的相关信息,例如将Caption改为MdiWindow,将Name改为MyAddin.MdiWindow,将DisplayStyle改为TextOnlyAlways
    6. 最后还需为StateButton设置Command,还是在右侧,点击Command项,在弹出的窗口中找到要绑定的命令的Key,例如MidWindowCmd的Key为PdmsAddin.MdiWindowCmd
    7. 将新建的StateButton(MdiWindow)拖动到CommandBar
    8. 修改完成后,点击Apply应用更改,关闭Customize窗口后,即可看到工具栏中的MdiWindow按钮

模态窗口

  1. 引用程序集
    • Aveva.Pdms.Database.dll
  2. 新建MdiWindowCmd类,添加如下代码
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
public class DialogWindowCmd : Command
{
private PromptDialog _prompt;

public DockedWindowCmd(WindowManager windowManager)
{
base.Key = "PdmsAddin.DialogWindowCmd";


_prompt = new PromptDialog();

this.ExecuteOnCheckedChange = false;

_prompt.Closing += PromptOnClosing;
}

private void PromptOnClosing(object sender,CancelEventArgs e)
{
this.Checked = false;

_prompt.Hide();
e.Cancel = true;
}

public override void Execute()
{
try
{
if(_prompt.IsVisible)
{
_prompt.Hide();
}
else
{
_prompt.Show();
}

base.Execute();
}
catch(Exception ex)
{
System.Windows.MessageBox.Show(ex.Message);
}
}
}
  1. 修改PdmsAddin类内容如下
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
public class PdmsAddin : IAddin
{
public void Start(ServiceManager serviceManager)
{
CommandManager commandManager = (CommandManager)serviceManager.GetService(typeof(CommandManager));

DialogWindowCmd dialogWindowCmd = new DialogWindowCmd();
commandManager.Commands.Add(dialogWindowCmd);
}

public void Stop()
{

}

public string Name => "Pdms Addin";
public string Description => "Pdms Addin";
}
  1. 重新生成解决方案,将生成的PdmsAddin.dll文件拷贝到PMDS安装路径下的MyAddins目录下
  2. 编辑PDMS安装目录下的DesignAddins.xml,添加一条如下记录
1
<string>MyAddins\PdmsAddin</string>
  1. 在PMDS安装目录下新建MyUIC目录,将PDMS根目录下的design.uic文件拷贝一份到MyUIC目录,编辑内容如下(删掉多余内容即可)
1
2
3
4
<?xml version="1.0" encoding="utf-8"?>
<UserInterfaceCustomization xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns="www.aveva.com">
<Version>1.0</Version>
</UserInterfaceCustomization>
  1. 编辑PDMS安装目录下的DesignCustomization.xml,添加一条如下记录
1
<CustomizationFileFile Name="MyAddin" Path="MyUIC\MyDesignUic.uic">
  1. 启动PDMS,在菜单栏空白处右键点击最底下的Customize...菜单,弹出Customize窗口

    1. Active Customization File下拉框切换为MyAddin
    2. 选中Command Bars菜单项,右键选择New CommandBar
    3. 右侧可修改CommandBar1菜单项的相关信息,例如将Caption改为MyPdmsAddin,将Name改为MyAddin.MyPdmsAddin
    4. 在侧边工具栏点击倒数第四个图标New StateButton新建带状态的按钮
    5. 右侧可修改StateButton1项的相关信息,例如将Caption改为DialogWindow,将Name改为MyAddin.DialogWindow,将DisplayStyle改为TextOnlyAlways
    6. 最后还需为StateButton设置Command,还是在右侧,点击Command项,在弹出的窗口中找到要绑定的命令的Key,例如DialogWindowCmd的Key为PdmsAddin.DialogWindowCmd
    7. 将新建的StateButton(MdiWindow)拖动到CommandBar
    8. 修改完成后,点击Apply应用更改,关闭Customize窗口后,即可看到工具栏中的DialogWindow按钮

事件

UserChanges

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
public void Start(ServiceManager serviceManager)
{
try
{
DbEvents.AddHandleUserChanges(new DbEvents.UserChangesEventHandler(UserChanges));
}
catch{}
}

private void UserChanges(DbUserChanges changes)
{
DbElement[] createdElements = changes.GetCreations(); // 新建的模型,测试指令: new equi /Test1

DbElement[] mermberChangeElements = changes.GetMemberChanges(); // 子元素变化

DbElement[] deletedElements = changes.GetDeletions(); // 删除模型

DbElement[] nodifyedElements = changes.GetModified(); // 修改模型

DbElement[] movedElements = changes.GetMoved(); // 移动模型

DbElement[] reorderedElements = changes.GetReordered(); // 重新排序

bool isAttributeModify = changes.IsAttributeModified; // 是否是属性修改操作
}

运用工具栏组件

  1. 引用程序集
    • Aveva.Pdms.Geometry.dll
    • Aveva.Pdms.Shared.dll
  2. 新建以下三个类
1
2
3
4
5
6
7
public class TboxCmd : Command
{
public TboxCmd()
{
this.Key = "PdmsAddin.TboxCmd";
}
}
1
2
3
4
5
6
7
public class ComBoxCmd : Command
{
public ComBoxCmd()
{
this.Key = "PdmsAddin.ComBoxCmd";
}
}
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
public class CreateEquiCmd : Command
{
private readonly TboxCmd _tboxCmd;
private readonly ComBoxCmd _comBoxCmd;

public CreateEquiCmd(TboxCmd tboxCmd,ComBoxCmd comBoxCmd)
{
this.Key = "PdmsAddin.CreateEquiCmd";

_tboxCmd = tboxCmd;
_comBoxCmd = comBoxCmd;
}

public override void Execute()
{
string cmbSelectedValue = (string)_comBoxCmd.Value;
string nameOfEqui = @"/" + (string)_tboxCmd.Value;

CreateEqui(nameOfEqui,cmbSelectedValue);
base.Execute();
}

// 这里可以采用类似于重载的效果,在绑定命令中Caption上面的Arguments可绑定参数,使其执行此带参数的Execute()
public void Execute(string prefix)
{
string cmbSelectedValue = (string)_comBoxCmd.Value;
string nameOfEqui = @"/" + prefix + (string)_tboxCmd.Value;

CreateEqui(nameOfEqui,cmbSelectedValue);
base.Execute();
}

private void CreateEqui(string nameOfEqui,string cmbSelectedValue)
{
try
{
DbElement ce = CurrentElement.Element;

DbElement newEqui = ce.Create(1, DbElementTypeInstance.EQUIPMENT);
newEqui.SetAttribute(DbAttributeInstance.NAME, nameOfEqui);
newEqui.SetAttribute(DbAttributeInstance.DESC, cmbSelectedValue);

CurrentElement.Element = newEqui;
}
catch(Exception ex)
{
System.Windows.MessageBox.Show(ex.Message);
}
}
}
  1. 验证输入合法性(可选),新建ValidationRules类,内容如下
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
public class ValidationRules
{
private readonly CommandManager _commandManager;

public ValidationRules(CommandManager commandManager)
{
_commandManager = commandManager;
}

public void CheckName()
{
Command createEquiCmd = _commandManager.Commands["PdmsAddin.CreateEquiCmd"];
createEquiCmd.BeforeCommandExecute += CreateEquiCmdOnBeforeCommandExecute;
}

private void CreateEquiCmdOnBeforeCommandExecute(object sender, CancelEventArgs e)
{
Command tboxCmd = _commandManager.Command["PdmsAddin.TboxCmd"];

if(string.IsNullOrEmpty(tboxCmd.Value.ToString()))
{
e.Cancel = true;

Aveva.Pdms.Utilities.CommandLine.Command.CreateCommand(@"$P Name field cannot be empty").RunInPdms();
}
}
}
  1. 修改PdmsAddin类内容如下
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
public class PdmsAddin : IAddin
{
public void Start(ServiceManager serviceManager)
{
CommandManager commandManager = (CommandManager)serviceManager.GetService(typeof(CommandManager));

TboxCmd tboxCmd = new TboxCmd();
ComBoxCmd comBoxCmd = new ComBoxCmd();
CreateEquiCmd createEquiCmd = new CreateEquiCmd(tboxCmd, comBoxCmd);

commandManager.Commands.Add(tboxCmd);
commandManager.Commands.Add(comBoxCmd);
commandManager.Commands.Add(createEquiCmd);

// Add validation
ValidationRules validationRules = new ValidationRules(commandManager);
validationRules.CheckName();
}

public void Stop()
{

}

public string Name => "Pdms Addin";
public string Description => "Pdms Addin";
}
  1. 重新生成解决方案,将生成的PdmsAddin.dll文件拷贝到PMDS安装路径下的MyAddins目录下
  2. 编辑PDMS安装目录下的DesignAddins.xml,添加一条如下记录
1
<string>MyAddins\PdmsAddin</string>
  1. 在PMDS安装目录下新建MyUIC目录,将PDMS根目录下的design.uic文件拷贝一份到MyUIC目录,编辑内容如下(删掉多余内容即可)
1
2
3
4
<?xml version="1.0" encoding="utf-8"?>
<UserInterfaceCustomization xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns="www.aveva.com">
<Version>1.0</Version>
</UserInterfaceCustomization>
  1. 编辑PDMS安装目录下的DesignCustomization.xml,添加一条如下记录
1
<CustomizationFileFile Name="MyAddin" Path="MyUIC\MyDesignUic.uic">
  1. 启动PDMS,在菜单栏空白处右键点击最底下的Customize...菜单,弹出Customize窗口

    1. Active Customization File下拉框切换为MyAddin
    2. 选中Command Bars菜单项,右键选择New CommandBar
    3. 右侧可修改CommandBar1菜单项的相关信息,例如将Caption改为MyPdmsAddin,将Name改为MyAddin.CommandBarEqui
    4. 新建文本框,修改以下信息
      • Caption: Name:
      • Command: PdmsAddin.TboxCmd
      • DisplayStyle: TextOnlyAlways
      • Name: MyAddin.TxtName
    5. 新建下拉框,修改以下信息
      • Caption: Desc:
      • Command: PdmsAddin.ComBoxCmd
      • DisplayStyle: TextOnlyAlways
      • Name: MyAddin.ComBoxDesc
    6. 新建按钮,修改以下信息
      • Caption: Create
      • Command: PdmsAddin.CreateEquiCmd
      • DisplayStyle: ImageAndText
      • Icon : Shared:EQUI (Resource Files菜单下的Shared菜单中的Icons选项卡可看到图标)
      • Name: MyAddin.BtnCreate
    7. 三个控件都要拖到CommandBar下
    8. 修改完成后,点击Apply应用更改,关闭Customize窗口,即可看到表单
  2. 注意新建Equi后CurrentElement会变,需要重新选择CurrentElement(不能在EQUI下新建EQUI)

NetGridControl

  1. 引用程序集
    • GridControl.dll
  2. 新建一个名为NetGridAddinControl的Winform用户控件,其中上下结构包含一个Panel和Button,代码如下
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
public partial class NetGridAddinControl : UserControl
{
private NetGridControl _netGridControl;
private string _tableName;
private Hashtable _atts;
private Hashtable _titles;

public NetGridAddinControl()
{
InitializeComponent();

AddGridToForm();
InitGrid();
}

private void InitGrid()
{
_tableName = "Sample Grid";

_atts = new Hashtable();
_atts[1.0] = "Name";
_atts[2.0] = "Type";
_atts[3.0] = "Owner";

_titles = new Hashtable();
_titles[1.0] = "Name of Item";
_titles[2.0] = "Type of Item";
_titles[3.0] = "Owner of Item";
}

private void AddGridToForm()
{
this._netGridControl = new NetGridControl();
this.panel1.Controls.Add(this._netGridControl);
}

// 按钮的点击事件
private void button1_Click(object sender,EventArgs e)
{
DbElement ce = CurrentElement.Element;
DbElement[] members = ce.Members();

Hashtable items = new Hashtable();
double i = 1.0;
foreach(DbElement element in members)
{
items.Add(i, element);
i++;
}

NetDataSource dataSource = new NetDataSource(_tableName,_atts,_titles,items);
this._netGridControl.BindToDataSource(dataSource);
}
}
  1. 新建GridCmd类内容如下
1
2
3
4
5
6
7
8
9
10
11
12
public class GridCmd : Command
{
private readonly DockedWindow _gridWindow;

public GridCmd(WindowManager windowManager)
{
this.Key = "PdmsAddin.GridCmd";

var netGridAddinControl = new NetGridAddinControl(); // winform用户控件

}
}
  1. Customize添加一个State Button绑定GridCmd即可

过滤器

TypeFilter

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
private void CollTypeFilter()
{
Dbelement ce = CurrentElement.Element;

TypeFilter typeFilter = new TypeFilter(DbElementTypeInstance.EQUIPMENT);
DBElementCollection coll = new DBElementCollection(ce,typeFilter);

Aveva.Pdms.Utilities.CommandLine.Command.CreateCommand(@"$P Count of EQUI:" + GetCount(coll)).RunInPdms();
}

private int DBElementCollection coll)
{
int i = 0;
foreach(var item in coll)
{
i++;
}
return i;
}

AttributeUnsetFilter

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
private void CollUnsetFilter()
{
Dbelement ce = CurrentElement.Element;

AttributeUnsetFilter unsetFilter = new AttributeUnsetFilter(DbAttributeInstance.DESC);
DBElementCollection coll = new DBElementCollection(ce,unsetFilter);

Aveva.Pdms.Utilities.CommandLine.Command.CreateCommand(@"$P Count DESC unset:" + GetCount(coll)).RunInPdms();
}

private int DBElementCollection coll)
{
int i = 0;
foreach(var item in coll)
{
i++;
}
return i;
}

AttributeRefFilter

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
private void CollUnsetFilter()
{
// Get element with name "/EQUIP"
DbElement zone = DbElement.GetElement("/EQUIP");
AttributeRefFilter refFilter = new AttributeRefFilter(DbAttributeInstance.OWNER,zone);

DBElementCollection coll = new DBElementCollection(DbElement.GetElement("/*"),unsetFilter);

Aveva.Pdms.Utilities.CommandLine.Command.CreateCommand(@"$P Count elems with owner ""/EQUIP"":" + GetCount(coll)).RunInPdms();
}

private int DBElementCollection coll)
{
int i = 0;
foreach(var item in coll)
{
i++;
}
return i;
}

AndFilter

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
private void CollAndFilter()
{
TypeFilter typeFilter = new TypeFilter(DbElementTypeInstance.EQUIPMENT);
AttributeUnsetFilter unsetFilter = new AttributeUnsetFilter(DbAttributeInstance.DESC);
// DESC为unset的EQUI
AndFilter andFilter = new AndFilter();
andFilter.Add(typeFilter);
andFilter.Add(unsetFilter);

DBElementCollection coll = new DBElementCollection(DbElement.GetElement("/*"),andFilter);
Aveva.Pdms.Utilities.CommandLine.Command.CreateCommand(@"$P Count of EQUI and DESC unset:" + GetCount(coll)).RunInPdms();
}

private int DBElementCollection coll)
{
int i = 0;
foreach(var item in coll)
{
i++;
}
return i;
}

操作PML变量

设置PML变量

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32

using Command = Aveva.Pdms.Utilities.CommandLine.Command;

public class SetPMLVarCmd : Aveva.ApplicationFramework.Presentation.Command
{
public SetPMLVarCmd()
{
this.Key = "PdmsAddin.SetPMLVarCmd";
}

public overrider void Execute()
{
try
{
string cmdText =
"$P Set PML varaibles\n"
+ "!!varString = 'SomeText' \n"
+ "!!varReal = 5 \n"
+ "!!varBool = true";

Command SetPml = Command.CreateCommand(cmdText);

if(SetPml.RunInPdms())
{
Command.CreateCommand("$P Ok!").RunInPdms();
}

base.Execute();
}
catch{}
}
}

获取PML变量

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38

using Command = Aveva.Pdms.Utilities.CommandLine.Command;

public class GetPMLVarCmd : Aveva.ApplicationFramework.Presentation.Command
{
public GetPMLVarCmd()
{
this.Key = "PdmsAddin.GetPMLVarCmd";
}

public overrider void Execute()
{
try
{
Command GetPml = Command.CreateCommand("");

// PML variables must be in UPPERCASE (PML变量必须采用大写)
string pmlStringValue = GetPml.GetPMLVariableString("VARSTRING");
double pmlRealValue = GetPml.GetPMLVariableReal("VARREAL");
bool pmlBoolValue = GetPml.GetPMLVariableBool("VARBOOL");

string newPmlStringValue = GetPml.GetPMLVariableString("NEWVAR"); // 不存在,可在控制台定义定义测试 !!NEWVAR = 'NewText'

string cmdText = string.Format(
"$P Get PML variables: {0} , {1} , {2} , {3}",
pmlStringValue,
pmlRealValue,
pmlBoolValue,
newPmlStringValue
);

Command.CreateCommand(cmdText).RunInPdms();

base.Execute();
}
catch{}
}
}

DatatableReference

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
using Command = Aveva.Pdms.Utilities.CommandLine.Command;

public class DbTableCmd : Aveva.ApplicationFramework.Presentation.Command
{
public DbTableCmd()
{
this.Key = "PdmsAddin.DbTableCmd";
}

public override void Execute()
{
try
{
// Get Reference table for ELBOWS in the MDB
MDB mdb = MDB.CurrentDB;
Db[] dbs = mdb.GetDBArray(DbType.Design);

foreach(Db db in dbs)
{
RefTable rtable = RefTable.GetRefTable(db, DbAttributeInstance.SPRE);

foreach(DbElement element in rtable)
{
if(element.GetActualType() == DbElementTypeInstance.ELBOW)
{
Command.CreateCommand(
string.Format(
"$P {0} == {1}",
element.GetAsString(DbAttributeInstance.SPRE),
element.GetAsString(DbAttributeInstance.NAMTYP)
)
).RunInPdms();
}
}
}

// Example
// Find all elements that use catalog item named "AAEA200N" (similar to "DESGEO" command)
Command.CreateCommand(@"$P").RunInPdms();
Command.CreateCommand(@"$P List of all elements that use catalog item named ""AAEA200NN""").RunInPdms();

DbElement catElem = mdb.FindElement(DbType.Catalogue,@"/AAEA200NN");
DbElement[] sprefs = mdb.FindElements(DbType.Catalogue,DbAttributeInstance.CATR,catELem);

List<DbELement> elDes = new List<DbELement>();
foreach(DbELement spref in sprefs)
{
elDes.AddRange(mdb.FindElements(DbType.Design, DbAttributeInstance.SPRE,spref));
}

foreach(DbELement element in elDes)
{
string name = element.GetAsString(DbAttributeInstance.NAMTYP);

Command.CreateCommand(string.Format("$P {0}",name)).RunInPdms();
}

}
catch{}
}
}

独立运行

  1. 新建控制台应用程序TestPdmsStandalone
  2. 引用如下程序集
    • Aveva.Pdms.Database.dll
    • Aveva.Pdms.Standalone.dll
    • Aveva.Pdms.Utilities.dll
  3. 编辑Program内容如下:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
class Program
{
static void Main(string[] args)
{
try
{
PdmsStandalone.Start();

PdmsStandalone.Open("Sample", "SYSTEM", "XXXXXX", "SAMPLE");

string zoneName = "/EQUIP";
int countOfEquip = MDB.CurrentMDB.FindElement(zoneName).Members(DbELementTypeInstance.EQUIPMENT).Length;

Console.WriteLine("------------------------------");
Console.WriteLine($"Element {zoneName} contains {countOfEquip} elements");

PdmsStandalone.Close();
}
catch(Exception ex)
{
Console.WriteLine(ex.Message);
}
finally
{
Console.ReadKey();
}
}
}
  1. 将应用程序改为x86平台(必须)
  2. 将生成的exe应用拷贝到Pdms安装目录
  3. 拷贝一份Pdms安装目录下的pdms.bat重命名为RunPdmsStandalone.bat
  4. 编辑RunPdmsStandalone.bat,滚动到内容末尾
1
2
3
4
5
6
7
8
# 使用rem注释下面三行
rem echo running: %monexe%\%executable% %args%
rem cmd/c "%monexe%\%executable% %args%"
rem goto end

# 在其下面加上如下内容
cmd/c "TestPdmsStandalone.exe"

  1. 运行RunPdmsStandalone.bat