欢迎来到我的博客
Civil 3D开发与应用,欢迎加入QQ群:484124761
AutoCAD开发,欢迎加入QQ群:193522571

论坛中看到的代码,留存备用 批量创建dwg文件

OpenFileDialog ofd = new OpenFileDialog();
            ofd.Title = "Select PointFiles to import";
            ofd.CheckFileExists = true;
            ofd.Multiselect = true;
            if (ofd.ShowDialog() != System.Windows.Forms.DialogResult.OK)
                return;
            dynamic prefs = Autodesk.AutoCAD.ApplicationServices.Application.Preferences;
            dynamic files = prefs.Files;
            string qnew = files.QNewTemplateFile;

            foreach (string file in ofd.FileNames)
            {
                string path = Path.GetDirectoryName(file);
                string filename = Path.GetFileNameWithoutExtension(file);
                string newname = path + "\\" + filename + ".dwg";
                using (Database db = new Database(false, true))
                {
                    db.ReadDwgFile(qnew, FileOpenMode.OpenForReadAndWriteNoShare, false, "");
                    using (Transaction tr = db.TransactionManager.StartTransaction())
                    {
                        CivilDocument civdoc = CivilDocument.GetCivilDocument(db);
                        ObjectId styleId = civdoc.Styles.SurfaceStyles["TDG - Border Only"];
                        ObjectId surfId = TinSurface.Create(db, filename);
                        TinSurface surf = (TinSurface)surfId.GetObject(OpenMode.ForWrite);
                        PointFileFormatCollection ptFileFormats = PointFileFormatCollection.GetPointFileFormats(db);
                        PointFileFormat ptFormat = ptFileFormats["PNEZD (comma delimited)"];
                        surf.StyleId = styleId;
                        surf.PointFilesDefinition.AddPointFile(file, ptFormat);
                        tr.Commit();
                    }
                    db.SaveAs(newname, DwgVersion.Current);
                }
            }

 

posted @ 2020-02-19 15:07  david96007  阅读(502)  评论(0编辑  收藏  举报