首页 > 编程语言 >c# aveva marine 批量导出图纸到dxf格式

c# aveva marine 批量导出图纸到dxf格式

时间:2022-10-30 15:33:26浏览次数:44  
标签:dwgType c# DraftApp aveva item dwgs var dxf AmEnv

获取图纸数据库

查看代码

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

效果见视频

https://www.bilibili.com/video/BV1a14y1L749/?spm_id_from=333.999.0.0

标签:dwgType,c#,DraftApp,aveva,item,dwgs,var,dxf,AmEnv
From: https://www.cnblogs.com/NanShengBlogs/p/16841392.html

相关文章

  • C语言之存储类,枚举,结构体,共用体,typedef
    目录1存储类1.1auto存储类1.2register存储类1.3static存储类1.4extern存储类2枚举2.1定义2.2操作枚举2.2.1用for循环遍历枚举3结构体3.1定义结构3.2操作结构......
  • CSP-S 2022 游记
    前言\(2020\)被儒略日干爆\(2021\)被括号和回文干爆\(2022\)不知道会不会被干爆Day-2某群一张聊天截图,CSP取消。我:???Day-1某群又一张聊天截图,CSP恢复。我:???是......
  • 【C++】右值引用
    来源于:https://zhuanlan.zhihu.com/p/3359943701.什么是右值引用左值可以取地址、位于等号左边。右值没法取地址、位于等号右边。有地址的变量就是左值,没有地址的字面......
  • CSP2022 S游记
    9.26:开坑。没报J组主要是因为J比较垃圾,去抢小朋友的一等没什么意思。初赛刚拿到试卷就直接懵了,这tm是给人做的题?宇宙射线是什么奇妙东西,还有基数排序我根本不会啊......
  • WPF里ItemsControl的分组实现
    一、WPF里ItemsControl的分组实现我们在用到ItemsControl时,有时会用到分组。如下图所示,绑定一个普通一个数组如下所示:数据类型为:publicclassStudent{......
  • python 爬虫 -----selenium自动化测试工具的使用 + Microsoft edge driver 的安装
    selenium的安装python-mpip--default-timeout=100installselenium-ihttp://pypi.douban.com/simple/--trusted-hostpypi.douban.com Microsoftedged......
  • Mac开发_隐藏与显示Dock 上的程序图标
    1、启动时就处理选中target->info,点击任意key值中有个中有个加号,新增Applicationisagent(UIElement)字段,设置值为YES(隐藏)、NO(显示).2、动态调整//应用......
  • masm specification
    masmspecification目录1.preparedosbox1.1setmasmdriver1.2setourownworkspace1.3forwardtoworkspaceandset(masm)path2.compile.asminto.objlinke......
  • 2022CSP-S游记
    day-998244353:模拟赛联考,被吊打了,为csp攒rp。day-1:颓颓颓颓颓颓颓颓颓颓颓颓颓颓颓颓颓颓颓颓颓颓颓颓颓颓颓颓颓颓颓颓颓颓颓颓颓颓颓颓颓颓颓颓颓颓颓颓颓颓颓颓颓颓......
  • Fluent让colormap始终显示在云图的顶部
    打开View->Options->Colormap,选择Top。   ......