Beispiel #1
0
        public void Dll加载到内存并卸载()
        {
            AppDomain.CurrentDomain.AssemblyResolve += CurrentDomain_AssemblyResolve;
            Autodesk.AutoCAD.Windows.OpenFileDialog ofd = new Autodesk.AutoCAD.Windows.OpenFileDialog("Dll加载到内存并卸载", "Dll加载到内存并卸载", "dll", "Dll加载到内存并卸载", Autodesk.AutoCAD.Windows.OpenFileDialog.OpenFileDialogFlags.AllowMultiple);
            //        而其中最重要的是这个事件: 运行域事件它会在运行的时候找已经载入内存上面的程序集.
            AppDomain.CurrentDomain.AssemblyResolve += RunTimeCurrentDomain.DefaultAssemblyResolve;

            if (ofd.ShowDialog() == System.Windows.Forms.DialogResult.OK)
            {
                foreach (var dllpath in ofd.GetFilenames())
                {
                    //come from JJ
                    var  ad     = new AssemblyDependent(dllpath);
                    var  msg    = ad.Load();
                    bool allyes = true;
                    foreach (var item in msg)
                    {
                        if (!item.LoadYes)
                        {
                            Application.DocumentManager.MdiActiveDocument.Editor.WriteMessage(Environment.NewLine + "**" + item.Path + Environment.NewLine + "**此文件已加载过,重复名称,重复版本号,本次不加载!" + Environment.NewLine);
                            allyes = false;
                        }
                    }
                    if (allyes)
                    {
                        Application.DocumentManager.MdiActiveDocument.Editor.WriteMessage(Environment.NewLine + "**链式加载成功!" + Environment.NewLine);
                    }
                }
            }
            else
            {
                Autodesk.AutoCAD.ApplicationServices.Application.ShowAlertDialog("请选择一个或者多个dll文件!");
            }
        }
Beispiel #2
0
        private bool SelectTemplateFileAndLoad(ref DxExtractionSettings extractionSettings, out string fileName)
        {
            // set no urls or ftp sites
            var flags = OpenFileDialog.OpenFileDialogFlags.NoUrls | OpenFileDialog.OpenFileDialogFlags.NoFtpSites;
            // create a new select dialog
            var ofd = new OpenFileDialog("Select Template file", string.Empty, "dxe", "BrowseTemplateFile", flags);

            var bCheckFile = true;

            while (bCheckFile)
            {
                if (ofd.ShowDialog() == DialogResult.OK)
                {
                    fileName = ofd.Filename;

                    if (LoadTemplateFromFile(ofd.Filename, ref extractionSettings))
                    {
                        bCheckFile = false;
                        return(true);
                    }

                    MessageBox.Show("Failed to open that template file, please try again...");
                }
                else
                {
                    bCheckFile = false;
                }
            }

            fileName = null;

            return(false);
        }
Beispiel #3
0
        getFileToProcess()
        {
            OpenFileDialog ofd = new OpenFileDialog("SELECT POINT FILE", "default", "txt", "Select Point File to Import",
                                                    OpenFileDialog.OpenFileDialogFlags.DefaultIsFolder);

            DialogResult dr = ofd.ShowDialog();

            if (dr == DialogResult.OK)
            {
                TXTFILE = ofd.Filename;
            }
            else
            {
                return;
            }
            DWGNAME = Path.GetFileNameWithoutExtension(TXTFILE);
            if (DWGNAME != "")
            {
                JN      = DWGNAME.Substring(0, 4);
                TOP     = DWGNAME.Substring(4);
                PATH    = Misc.resolvePath(JN);
                DWGNAME = string.Format("{0}.dwg", DWGNAME);
                DWGPATH = string.Format("{0}{1}{2}{3}", PATH, JN, @"\", DWGNAME);
            }
        }
Beispiel #4
0
        DwgStatsBatch()
        {
            // get multiple files to batch process
            Autodesk.AutoCAD.Windows.OpenFileDialog dwgsForm = new Autodesk.AutoCAD.Windows.OpenFileDialog("Drawing Files To Process",
                                                                                                           null, "dwg", "DwgStatsBatch", Autodesk.AutoCAD.Windows.OpenFileDialog.OpenFileDialogFlags.AllowMultiple);
            if (dwgsForm.ShowDialog() != DialogResult.OK)
            {
                return;
            }

            // get output file to save XML report to
            System.Windows.Forms.SaveFileDialog dbox = new System.Windows.Forms.SaveFileDialog();
            dbox.CreatePrompt    = false;
            dbox.OverwritePrompt = true;
            dbox.AddExtension    = true;
            dbox.DefaultExt      = "xml";
            dbox.Filter          = "XML Files (*.xml)|*.xml";
            dbox.Title           = "XML file to save report as";

            if (dbox.ShowDialog() == DialogResult.OK)
            {
                DwgStats.Report statReport = new DwgStats.Report();
                statReport.XmlReport(dbox.FileName, dwgsForm.GetFilenames());
            }
        }
Beispiel #5
0
        public static string[] selectFiles(string title, string filter, string dialog)
        {
            //use autodesk windows rather than windows form
            Autodesk.AutoCAD.Windows.OpenFileDialog ofd = new Autodesk.AutoCAD.Windows.OpenFileDialog(title, null, filter, dialog, Autodesk.AutoCAD.Windows.OpenFileDialog.OpenFileDialogFlags.AllowMultiple);
            ofd.ShowDialog();
            string[] result = ofd.GetFilenames();

            return(result);
        }
Beispiel #6
0
 // Выбрать dwg-файл для добавления
 private void BtSelectDwgFile_OnClick(object sender, RoutedEventArgs e)
 {
     try
     {
         var ofd = new Autodesk.AutoCAD.Windows.OpenFileDialog(ModPlusAPI.Language.GetItem(LangItem, "msg59"), _dwgBaseFolder, "dwg", "name",
                                                               Autodesk.AutoCAD.Windows.OpenFileDialog.OpenFileDialogFlags.NoFtpSites |
                                                               Autodesk.AutoCAD.Windows.OpenFileDialog.OpenFileDialogFlags.NoShellExtensions |
                                                               Autodesk.AutoCAD.Windows.OpenFileDialog.OpenFileDialogFlags.NoUrls |
                                                               Autodesk.AutoCAD.Windows.OpenFileDialog.OpenFileDialogFlags.DefaultIsFolder |
                                                               Autodesk.AutoCAD.Windows.OpenFileDialog.OpenFileDialogFlags.ForceDefaultFolder |
                                                               Autodesk.AutoCAD.Windows.OpenFileDialog.OpenFileDialogFlags.DoNotTransferRemoteFiles);
         var needLoop = true;
         while (needLoop)
         {
             var ofdresult = ofd.ShowDialog();
             if (ofdresult == System.Windows.Forms.DialogResult.OK)
             {
                 var selectedFile = ofd.Filename;
                 if (selectedFile.Contains(_dwgBaseFolder))
                 {
                     if (!DwgBaseHelpers.HasProxyEntities(selectedFile))
                     {
                         TbSourceFile.Text =
                             DwgBaseHelpers.TrimStart(selectedFile, _dwgBaseFolder).TrimStart('\\');
                         BtAccept.IsEnabled = true;
                         needLoop           = false;
                     }
                     else
                     {
                         ModPlusAPI.Windows.MessageBox.Show(ModPlusAPI.Language.GetItem(LangItem, "msg60"));
                     }
                 }
                 else
                 {
                     ModPlusAPI.Windows.MessageBox.Show(
                         $"{ModPlusAPI.Language.GetItem(LangItem, "msg49")} {_dwgBaseFolder}");
                 }
             }
             else if (ofdresult == System.Windows.Forms.DialogResult.Cancel)
             {
                 return;
             }
             else
             {
                 needLoop = false;
             }
         }
     }
     catch (Exception exception)
     {
         ExceptionBox.Show(exception);
     }
     finally
     {
         Focus();
     }
 }
Beispiel #7
0
        private static string SelectFile()
        {
            var d = new OpenFileDialog("Выбор файла", "", "dwg", "Очистка листов", OpenFileDialog.OpenFileDialogFlags.NoFtpSites);

            if (d.ShowDialog() == DialogResult.OK)
            {
                return(d.Filename);
            }

            throw new OperationCanceledException();
        }
Beispiel #8
0
        private void button1_Add_Click(object sender, EventArgs e)
        {
            Autodesk.AutoCAD.Windows.OpenFileDialog Dia =
                new Autodesk.AutoCAD.Windows.OpenFileDialog
                    ("Select drawings to Add.", "", "dwg", "", Autodesk.AutoCAD.Windows.OpenFileDialog.OpenFileDialogFlags.AllowMultiple);
            if (Dia.ShowDialog() != DialogResult.OK)
            {
                return;
            }
            AttFiles = Dia.GetFilenames();

            Attach();
        }
Beispiel #9
0
        private void Form1_Load(object sender, EventArgs e)
        {
            Autodesk.AutoCAD.Windows.OpenFileDialog Dia =
                new Autodesk.AutoCAD.Windows.OpenFileDialog("Select drawings to manage xref.", "", "dwg", "", Autodesk.AutoCAD.Windows.OpenFileDialog.OpenFileDialogFlags.AllowMultiple);

            if (Dia.ShowDialog() != DialogResult.OK)
            {
                return;
            }
            Files = Dia.GetFilenames();

            ListFiles();
        }
Beispiel #10
0
        public void CreateHvacTable() // This method can have any name
        {
            string documents = Path.GetDirectoryName(Active.Document.Name);

            Environment.SetEnvironmentVariable("MYDOCUMENTS", documents);

            var ofd = new OpenFileDialog("Select a file using an OpenFileDialog", documents,
                                         "xlsx; *",
                                         "File Date Test T22",
                                         OpenFileDialog.OpenFileDialogFlags.DefaultIsFolder |
                                         OpenFileDialog.OpenFileDialogFlags.ForceDefaultFolder // .AllowMultiple
                                         );
            DialogResult sdResult = ofd.ShowDialog();

            if (sdResult != System.Windows.Forms.DialogResult.OK)
            {
                return;
            }

            string filename = ofd.Filename;

            List <HvacTable> hvacTables = CreateHvacTableListFromFile(filename);

            Type type = typeof(HvacTable);

            int tableCols = type.GetProperties().Length;

            CreateLayer();

            MyMessageFilter filter = new MyMessageFilter();

            System.Windows.Forms.Application.AddMessageFilter(filter);

            foreach (var hvacTable in hvacTables)
            {
                // Check for user input events
                System.Windows.Forms.Application.DoEvents();
                if (filter.bCanceled == true)
                {
                    Active.Editor.WriteMessage("\nLoop cancelled.");
                    break;
                }

                AddTable(hvacTable, tableCols);
            }

            System.Windows.Forms.Application.RemoveMessageFilter(filter);
        }
        public static void XrefDwg()
        {
            var doc = AcApp.DocumentManager.MdiActiveDocument;

            if (doc == null)
            {
                return;
            }

            var ed = doc.Editor;

            var jobNumber = Path.GetFileNameWithoutExtension(doc.Name);

            if (jobNumber.Length > 9)
            {
                jobNumber = jobNumber.Remove(9);
            }
            if (!JobNumber.TryParse(jobNumber))
            {
                ed.WriteMessage("Job number could not be determined. Use the regular X-Ref command instead." + Environment.NewLine);
                return;
            }
            string path = JobNumber.GetPath(jobNumber);

            if (!Directory.Exists(path))
            {
                ed.WriteMessage("The job folder could not be located, please verify that the job number is correct." + Environment.NewLine);
                return;
            }

            Autodesk.AutoCAD.Windows.OpenFileDialog ofd = new Autodesk.AutoCAD.Windows.OpenFileDialog(
                "Please select a file to x-ref",
                path,
                "dwg",
                "DwgFileToLink",
                Autodesk.AutoCAD.Windows.OpenFileDialog.OpenFileDialogFlags.DefaultIsFolder
                );
            DialogResult pr = ofd.ShowDialog();

            if (pr == DialogResult.OK && !string.IsNullOrEmpty(ofd.Filename))
            {
                AttachXRef(ofd.Filename);
            }


            doc.Dispose();
        }
        public static void ImportSpreadPoints(Document document, bool insertId, bool insertCode)
        {
            var mapScale = MapScaleUtils.GetApplicationMapScale();

            if (mapScale == null || mapScale.Value.EqualsWithTolerance(0.0))
            {
                bool success = SetMapScale(document);
                if (!success)
                {
                    return;
                }
                mapScale = MapScaleUtils.GetApplicationMapScale();
            }

            // Open file dialog to select dat file
            // http://through-the-interface.typepad.com/through_the_interface/2007/08/using-autocads-.html
            var fileDialog = new OpenFileDialog("导入展点文件", defaultName: null,
                                                extension: "dat;*", dialogName: "SelectFile",
                                                flags: OpenFileDialog.OpenFileDialogFlags.DoNotTransferRemoteFiles);
            var dialogResult = fileDialog.ShowDialog();

            if (dialogResult != DialogResult.OK)
            {
                return;
            }

            // Create settings.
            var settings = new SpreadPointSettings()
            {
                InsertId   = insertId,
                InsertCode = insertCode,
                Scale      = mapScale.Value / 1000.0
            };

            var spreadPoints = SpreadPointUtils.ReadSpreadPointsFromFile(fileDialog.Filename);
            var ids          = SpreadPointUtils.InsertSpreadPoints(document, spreadPoints, settings);

            if (!ids.Any())
            {
                return;
            }

            Extents3d extents = GeometryUtils.SafeGetGeometricExtents(ids);

            EditorUtils.ZoomToWin(document.Editor, extents, 1.2);
        }
        private static void CreateTheRasterFile(string luchtFotoFile, string dictName, ref RasterImageDef imageDef,
                                                ref ObjectId imageDefId, Transaction trans, DBDictionary imageDict)
        {
            var openFileDialog = new OpenFileDialog("Open an Image file", luchtFotoFile, "tif", "Image File",
                                                    OpenFileDialog.OpenFileDialogFlags.NoUrls);

            if (openFileDialog.ShowDialog() != DialogResult.OK)
            {
                return;
            }
            imageDef = new RasterImageDef {
                SourceFileName = openFileDialog.Filename
            };
            imageDef.Load();
            imageDict.UpgradeOpen();
            imageDefId = imageDict.SetAt(dictName, imageDef);
            trans.AddNewlyCreatedDBObject(imageDef, true);
        }
 public void Dll加载到内存并卸载()
 {
     if (Environment.UserName != "sheng.nan" && Environment.UserName != "peng.shen" && Environment.UserName != "yaofan.liu")
     {
         Autodesk.AutoCAD.ApplicationServices.Application.ShowAlertDialog("你无权使用该工具!"); return;
     }
     Autodesk.AutoCAD.Windows.OpenFileDialog ofd = new Autodesk.AutoCAD.Windows.OpenFileDialog("Dll加载到内存并卸载", "Dll加载到内存并卸载", "dll", "Dll加载到内存并卸载", Autodesk.AutoCAD.Windows.OpenFileDialog.OpenFileDialogFlags.AllowMultiple);
     if (ofd.ShowDialog() == System.Windows.Forms.DialogResult.OK)
     {
         foreach (var item in ofd.GetFilenames())
         {
             var assBytes = System.IO.File.ReadAllBytes(item);
             var ass      = Assembly.Load(assBytes);
         }
     }
     else
     {
         Autodesk.AutoCAD.ApplicationServices.Application.ShowAlertDialog("请选择一个或者多个dll文件!");
     }
 }
Beispiel #15
0
 /// <summary>
 /// 第一步打开文件
 /// </summary>
 /// <param name="sender"></param>
 /// <param name="e"></param>
 private void button1_Click(object sender, EventArgs e)
 {
     this.listBox1.Items.Clear();
     this.dwgfileNames = new List <string>();
     Autodesk.AutoCAD.Windows.OpenFileDialog ofd = new Autodesk.AutoCAD.Windows.OpenFileDialog("选择零件图", null, "dwg;", "ok", Autodesk.AutoCAD.Windows.OpenFileDialog.OpenFileDialogFlags.AllowMultiple);
     if (ofd.ShowDialog() == DialogResult.OK)
     {
         foreach (var item in ofd.GetFilenames())
         {
             this.dwgfileNames.Add(item);
         }
         if (this.dwgfileNames.Count > 0)
         {
             foreach (var item in this.dwgfileNames)
             {
                 this.listBox1.Items.Add(item);
             }
         }
     }
 }
        public static void XrefDwgFromAnother()
        {
            var doc = AcApp.DocumentManager.MdiActiveDocument;

            if (doc == null)
            {
                return;
            }

            var ed = doc.Editor;

            GetJobNumber form1 = new GetJobNumber();
            var          f1r   = AcApp.ShowModalDialog(form1);

            if (f1r == DialogResult.Cancel)
            {
                ed.WriteMessage("No job number could be determined. Exiting." + Environment.NewLine);
                return;
            }

            ed.WriteMessage($"Going to job number {form1.Value}." + Environment.NewLine);

            Autodesk.AutoCAD.Windows.OpenFileDialog ofd = new Autodesk.AutoCAD.Windows.OpenFileDialog(
                "Please select a file to x-ref",
                JobNumber.GetPath(form1.Value),
                "dwg",
                "DwgFileToLink",
                Autodesk.AutoCAD.Windows.OpenFileDialog.OpenFileDialogFlags.DefaultIsFolder
                );

            var pr = ofd.ShowDialog();

            if (pr == DialogResult.OK && !string.IsNullOrEmpty(ofd.Filename))
            {
                AttachXRef(ofd.Filename);
            }

            form1.Dispose();
            doc.Dispose();
        }
Beispiel #17
0
        void Form1_Load(object sender, EventArgs e)
        {
            Autodesk.AutoCAD.Windows.OpenFileDialog Dia =
                new Autodesk.AutoCAD.Windows.OpenFileDialog
                (
                    "Select drawings to manage xref.",
                    "",
                    "dwg",
                    "",
                    Autodesk.AutoCAD.Windows.OpenFileDialog.OpenFileDialogFlags.AllowMultiple
                );

            if (Dia.ShowDialog() != DialogResult.OK)
            {
                return;
            }
            Files = Dia.GetFilenames();
            MyStringCompare1 msc1 = new MyStringCompare1();

            Array.Sort(Files, msc1);
            ListFiles(Files);
        }
Beispiel #18
0
        private void BtCopyDwgFile_OnClick(object sender, RoutedEventArgs e)
        {
            try
            {
                var selectedFile = string.Empty;
                var selectedPath = string.Empty;
                var copiedFile   = string.Empty;

                // Сначала нужно выбрать файл, проверив версию его
                var ofd = new Autodesk.AutoCAD.Windows.OpenFileDialog(ModPlusAPI.Language.GetItem(LangItem, "msg59"), _dwgBaseFolder, "dwg", "name",
                                                                      Autodesk.AutoCAD.Windows.OpenFileDialog.OpenFileDialogFlags.NoFtpSites |
                                                                      Autodesk.AutoCAD.Windows.OpenFileDialog.OpenFileDialogFlags.NoShellExtensions |
                                                                      Autodesk.AutoCAD.Windows.OpenFileDialog.OpenFileDialogFlags.NoUrls |
                                                                      Autodesk.AutoCAD.Windows.OpenFileDialog.OpenFileDialogFlags.DefaultIsFolder |
                                                                      Autodesk.AutoCAD.Windows.OpenFileDialog.OpenFileDialogFlags.ForceDefaultFolder |
                                                                      Autodesk.AutoCAD.Windows.OpenFileDialog.OpenFileDialogFlags.DoNotTransferRemoteFiles);
                var needLoop = true;
                while (needLoop)
                {
                    var ofdresult = ofd.ShowDialog();
                    if (ofdresult == System.Windows.Forms.DialogResult.OK)
                    {
                        selectedFile = ofd.Filename;

                        if (!DwgBaseHelpers.HasProxyEntities(selectedFile))
                        {
                            needLoop = false;
                        }
                        else
                        {
                            ModPlusAPI.Windows.MessageBox.Show(ModPlusAPI.Language.GetItem(LangItem, "msg60"));
                        }
                    }
                    else if (ofdresult == System.Windows.Forms.DialogResult.Cancel)
                    {
                        return;
                    }
                    else
                    {
                        needLoop = false;
                    }
                }

                // Теперь нужно указать папку для расположения файла
                var fbd = new System.Windows.Forms.FolderBrowserDialog
                {
                    Description         = ModPlusAPI.Language.GetItem(LangItem, "msg61"),
                    SelectedPath        = _dwgBaseFolder,
                    ShowNewFolderButton = true
                };
                needLoop = true;
                while (needLoop)
                {
                    var fbdResult = fbd.ShowDialog();
                    if (fbdResult == System.Windows.Forms.DialogResult.OK)
                    {
                        selectedPath = fbd.SelectedPath;
                        if (selectedPath.Contains(_dwgBaseFolder))
                        {
                            if (!selectedPath.Equals(_dwgBaseFolder))
                            {
                                var fi = new FileInfo(selectedFile);
                                copiedFile = Path.Combine(selectedPath, fi.Name);
                                if (File.Exists(copiedFile))
                                {
                                    needLoop =
                                        !ModPlusAPI.Windows.MessageBox.ShowYesNo(
                                            $"{ModPlusAPI.Language.GetItem(LangItem, "msg62")} {fi.Name}{Environment.NewLine}{ModPlusAPI.Language.GetItem(LangItem, "msg63")}", MessageBoxIcon.Question);
                                }
                                else
                                {
                                    needLoop = false;
                                }
                            }
                            else
                            {
                                ModPlusAPI.Windows.MessageBox.Show(
                                    $"{ModPlusAPI.Language.GetItem(LangItem, "msg64")} {_dwgBaseFolder}{Environment.NewLine}{ModPlusAPI.Language.GetItem(LangItem, "msg52")}");
                            }
                        }
                        else
                        {
                            ModPlusAPI.Windows.MessageBox.Show(
                                $"{ModPlusAPI.Language.GetItem(LangItem, "msg65")} {_dwgBaseFolder}");
                        }
                    }
                    else if (fbdResult == System.Windows.Forms.DialogResult.Cancel)
                    {
                        return;
                    }
                    else
                    {
                        needLoop = true;
                    }
                }

                // then copy file
                if (!string.IsNullOrEmpty(selectedFile) & !string.IsNullOrEmpty(selectedPath))
                {
                    if (File.Exists(selectedFile))
                    {
                        File.Copy(selectedFile, copiedFile, true);
                        if (File.Exists(copiedFile))
                        {
                            TbSourceFile.Text  = DwgBaseHelpers.TrimStart(copiedFile, _dwgBaseFolder).TrimStart('\\');
                            BtAccept.IsEnabled = true;
                        }
                    }
                }
            }
            catch (Exception exception)
            {
                ExceptionBox.Show(exception);
            }
            finally
            {
                Focus();
            }
        }
Beispiel #19
0
        private void button1_Attach_Click(object sender, EventArgs e)
        {
            Autodesk.AutoCAD.Windows.OpenFileDialog DiaAttach =
                new Autodesk.AutoCAD.Windows.OpenFileDialog
                (
                    "Select drawings to attach.",
                    "",
                    "dwg",
                    "",
                    Autodesk.AutoCAD.Windows.OpenFileDialog.OpenFileDialogFlags.AllowMultiple
                );

            if (DiaAttach.ShowDialog() != DialogResult.OK)
            {
                return;
            }
            AttFiles = DiaAttach.GetFilenames();

            //foreach (ListViewItem lvi in DwgListview.SelectedItems)
            //{
            using (DocumentLock DocLock = DocCol.MdiActiveDocument.LockDocument())
            {
                string DwgName = DwgPathName;

                Database     Db;
                Document     OpenDoc  = null;
                DocumentLock tempLock = null;
                OpenDoc = GetDocumentFrom(DocCol, DwgName);
                bool DocInEditor = (OpenDoc != null);
                if (DocInEditor)
                {
                    Db       = OpenDoc.Database;
                    tempLock = OpenDoc.LockDocument();
                }
                else
                {
                    Db = new Database(true, false);
                }

                using (Transaction acTrans = Db.TransactionManager.StartTransaction())
                {
                    try
                    {
                        if (!DocInEditor)
                        {
                            Db.ReadDwgFile(DwgName, System.IO.FileShare.ReadWrite, true, null);
                        }
                        bool saverequired = false;

                        foreach (string file in AttFiles)
                        {
                            ObjectId acXrefId = Db.AttachXref(file, Path.GetFileName(file));

                            // If a valid reference is created then continue
                            if (!acXrefId.IsNull)
                            {
                                // Attach the DWG reference to the current space
                                Point3d insPt = new Point3d(0, 0, 0);
                                using (BlockReference acBlkRef = new BlockReference(insPt, acXrefId))
                                {
                                    BlockTableRecord acBlkTblRec;
                                    acBlkTblRec = acTrans.GetObject(Db.CurrentSpaceId, OpenMode.ForWrite) as BlockTableRecord;

                                    acBlkTblRec.AppendEntity(acBlkRef);
                                    acTrans.AddNewlyCreatedDBObject(acBlkRef, true);
                                    saverequired = true;
                                }
                            }
                        }
                        if (saverequired)
                        {
                            Db.SaveAs(DwgName, DwgVersion.Current);
                            ListFile(DwgName);
                        }
                    }

                    catch (Autodesk.AutoCAD.Runtime.Exception AcadEx)
                    {
                        MessageBox.Show(AcadEx.Message + "\n\n" + AcadEx.StackTrace + "\n\n" + DwgName, "AutoCAD error.");
                    }
                    catch (System.Exception SysEx)
                    {
                        MessageBox.Show(SysEx.Message, "System error.");
                    }
                    acTrans.Commit();
                }

                if (DocInEditor)
                {
                    tempLock.Dispose();
                }
                else
                {
                    Db.Dispose();
                }
            }
            //}
            ListXrefs();
        }