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
        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 #3
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 #4
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 #5
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();
        }
 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 #7
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);
             }
         }
     }
 }
Beispiel #8
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 #9
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();
        }