快速读取和筛选分段元素
[MyAmFunctionAtt(nameof(测试功能), nameof(读取分段))]
public void 读取分段(WindowManager wm)
{
try
{
foreach (var item in wm.Windows)
{
if (item is DockedWindow)
{
var w = item as DockedWindow;
if (w.Title.ToLower() == "messages")
{
if (!w.Visible)
{
w.Show();
wm.MainForm.Refresh();
}
}
}
}
//提取全部分段信息
var flType = new TypeFilter(DbElementTypeInstance.BLOCK);//只筛选分段,添加引用的dll==> C:\AVEVA\Marine\OH12.1.SP4\PDMSFilters.dll
var searchStr = "ER*";
var nameLikeStr = new AttributeLikeFilter(DbAttributeInstance.NAMN, searchStr);//根据名称筛选,添加引用 C:\AVEVA\Marine\OH12.1.SP4\Aveva.Pdms.Database.dll
var andFl = new AndFilter(flType, nameLikeStr);//两个条件同时满足
var blkeles = FindElements(DbType.Design, andFl);
var ui = new MarUi(); //添加引用 C:\AVEVA\Marine\OH12.1.SP4\marAPI.dll
if (!blkeles.Any())
{
ui.MessageConfirm($"找不到名称类似‘{searchStr}’的分段!");//发送文本到message window窗口
ui.Dispose();
return;
}
blkeles.ForEach(c => ui.MessageNoConfirm(c.GetAsString(DbAttributeInstance.NAMN)));
ui.Dispose();
}
catch (System.Exception ex)
{
Interaction.MsgBox(ex.Message, MsgBoxStyle.Exclamation);// 添加引用C:\Windows\Microsoft.NET\Framework64\v2.0.50727\Microsoft.VisualBasic.dll
}
}
/// <summary>
///
/// </summary>
/// <param name="dbType">数据类型</param>
/// <param name="filter">筛选器</param>
/// <param name="condtion">对dbelement需要筛选的条件</param>
/// <returns></returns>
public static List<DbElement> FindElements(DbType dbType, BaseFilter filter, Func<DbElement, bool> condtion = null)
{
List<DbElement> resDbElements = new List<DbElement>();
DBElementCollection dbeEleCol = new DBElementCollection(dbType, filter);
var res = dbeEleCol.Cast<DbElement>();
if (!res.Any()) return resDbElements;
res.ToList().ForEach(c =>
{
if (condtion != null)
{
if (condtion.Invoke(c)) resDbElements.Add(c);
}
resDbElements.Add(c);
});
return resDbElements;
}
测试结果