获取图纸数据库
public static Dictionary<string,List<DbElement>> GetDbElements(DbType dbtype)
{
Dictionary<string, List<DbElement>> rtn = new Dictionary<string, List<DbElement>>();
Aveva.Pdms.Database.MDB mdb = Aveva.Pdms.Database.MDB.CurrentMDB;
var dbs = mdb.GetDBArray(dbtype);
foreach (var item in dbs)
{
rtn[item.Name] = item.WorldMembers().ToList();
}
return rtn;
}
public List<DbElement> GetDrawingsDB()
{
var designs = DbExtension.GetDbElements(Aveva.Pdms.Database.DbType.Draft);
return designs.Values.First().Where(c => c.GetActualType() == DbElementTypeInstance.DEPT).ToList();
}
获取某一数据库的图纸
public List<DbElement> GetDrawings(string dbName)
{
var dwgs = new List<DbElement>();
var db = DbElement.GetElement(dbName.StartsWith("/")?dbName: "/"+dbName);
var regis = db.Members().Where(c => c.GetActualType() == DbElementTypeInstance.REGISTRY);
foreach (var item in regis)
{
if (item.FirstMember() != null)
{
var curRegDwgs = item.Members().Where(d => d.GetActualType() == DbElementTypeInstance.DRWG);
if (curRegDwgs.Any())
dwgs.AddRange(curRegDwgs.ToList());
}
}
return dwgs.Where(d=>!d.IsNull).ToList();
}
主函数
AMHullEnv AmEnv = new AMHullEnv();
try
{
var dwgTypes = AmEnv.GetDrawingsDB().Select(c => c.GetAsString(DbAttributeInstance.NAMN)).ToList();
//dwgTypes.ToCSVFile($@"C:\{dwgTypes.First().GetType().FullName}.csv");
MarStringlist strs = new MarStringlist();
dwgTypes.ForEach(c => strs.AddString(c));
var ints = AmEnv.Ui.StringSelect("选择数据库", "select DataBank to save drawing", "", strs);
if (ints[0] == AmEnv.MarUtil.Ok())
{
var dwgType = dwgTypes.First(c => c == strs[ints[1] - 1]);
var dwgs = AmEnv.GetDrawings(dwgType);
if (dwgs != null)
{
wm.StatusBar.Text = dwgType.ToString();
foreach (var item in dwgs)
{
try
{
var dwgName = item.GetAsString(DbAttributeInstance.NAMN).Replace("/" + item.GetAsString(DbAttributeInstance.TYPE), "");
//var curDwgName = AmEnv.DraftApp.DwgNameGet();
if (AmEnv.DraftApp.DwgCurrent()) AmEnv.DraftApp.DwgClose();
AmEnv.DraftApp.DwgOpen(dwgName);
var dxfName = $@"C:\{dwgType}_{item.GetAsString(DbAttributeInstance.OWNER).Replace("/", "")}_{dwgName}.dxf";
AmEnv.DraftApp.DwgDxfExport(dxfName);
//AmEnv.DraftApp.DwgWmfExport(Path.ChangeExtension(dxfName, ".wmf"));
AmEnv.DraftApp.DwgClose();
}
catch (Exception ex)
{
AmEnv.Ui.MessageNoConfirm(ex.StackTrace);
continue;
}
}
}
else
AmEnv.Ui.MessageNoConfirm(dwgType + "数据库下无任何图纸!");
}
else
AmEnv.Ui.MessageNoConfirm("未选择到数据库!");
}
catch (Exception ex)
{
wm.StatusBar.Text = ex.StackTrace;
}
效果见视频