private void button1_Click(object sender, EventArgs e)
 {
     this.listBox1.Items.Clear();
     acadWnd.OpenFileDialog dlg = new Autodesk.AutoCAD.Windows.OpenFileDialog("选择图纸", null, "dwg;dxf", null, Autodesk.AutoCAD.Windows.OpenFileDialog.OpenFileDialogFlags.AllowMultiple);
     if (dlg.ShowDialog() == DialogResult.OK)
     {
         this.listBox1.Items.AddRange(dlg.GetFilenames().Where(c => MyUtility.FileInUse(c) == false).ToArray());
     }
 }
        private void click_Browse(object sender, EventArgs e)
        {
            Autodesk.AutoCAD.Windows.OpenFileDialog ofd = new Autodesk.AutoCAD.Windows.OpenFileDialog("Select Excel file:", null, "xlsm", "ExcelFiles", Autodesk.AutoCAD.Windows.OpenFileDialog.OpenFileDialogFlags.AllowMultiple | Autodesk.AutoCAD.Windows.OpenFileDialog.OpenFileDialogFlags.DoNotTransferRemoteFiles);
            System.Windows.Forms.DialogResult       dr  = ofd.ShowDialog();

            if (dr == System.Windows.Forms.DialogResult.OK)
            {
                tb_Path.Text = ofd.Filename;
            }
        }
Example #3
0
        public static void BatchConvert()
        {
            Editor ed = Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument.Editor;

            ed.WriteMessage("Please Select Files to Convert\n");

            Autodesk.AutoCAD.Windows.OpenFileDialog ofd = new Autodesk.AutoCAD.Windows.OpenFileDialog(
                "Select AutoCAD files", "", "dwg", "",
                Autodesk.AutoCAD.Windows.OpenFileDialog.OpenFileDialogFlags.AllowMultiple);

            List <string> inputs = new List <string>();

            while (true)
            {
                ed.WriteMessage("Please Select Files to Convert. Select Cancel to Start Converting.\n");
                System.Windows.Forms.DialogResult result = ofd.ShowDialog();
                if (result == System.Windows.Forms.DialogResult.OK)
                {
                    string[] names = ofd.GetFilenames();
                    ed.WriteMessage(string.Join("\n", names.ToArray()) + "\n");

                    inputs.AddRange(names);
                }
                else
                {
                    break;
                }
            }

            // AC1015   AutoCAD 2000, AutoCAD 2000i, AutoCAD 2002
            // AC1018   AutoCAD 2004, AutoCAD 2005, AutoCAD 2006
            // AC1021   AutoCAD 2007, AutoCAD 2008, AutoCAD 2009
            // AC1024   AutoCAD 2010, AutoCAD 2011, AutoCAD 2012
            // AC1027   AutoCAD 2013
            inputs = inputs.Distinct().ToList();
            foreach (var input in inputs)
            {
                string output = "";
                if (!ConvertVersion(input, DwgVersion.AC1021, out output)) // target: AutoCAD 2007
                {
                    ed.WriteMessage("Fail: " + input + "\n");
                }
                else
                {
                    ed.WriteMessage("Output: " + output + "\n");
                }
            }
        }
Example #4
0
 private void FileOpenMenuItem_Click(object sender, EventArgs e)
 {
     // pick the place where o output the image type
     Autodesk.AutoCAD.Windows.OpenFileDialog dialog = new Autodesk.AutoCAD.Windows.OpenFileDialog("Open DWG File", null, "dwg", "OpenDWGFileDialog", Autodesk.AutoCAD.Windows.OpenFileDialog.OpenFileDialogFlags.NoUrls);
     // if all is ok?
     if (DialogResult.OK == dialog.ShowDialog())
     {
         // clear the preview control
         mPreviewCtrl.mpView.EraseAll();
         // create a new database
         dwgs.Add(new Database(false, true));
         // now read it in
         dwgs[dwgs.Count - 1].ReadDwgFile(dialog.Filename, FileOpenMode.OpenForReadAndReadShare, true, "");
         // initialising the drawing control, pass the existing document still as the gs view still refers to it
         InitDrawingControl(AcadApp.DocumentManager.MdiActiveDocument, dwgs[dwgs.Count - 1]);
     }
 }
Example #5
0
        [CommandMethod("ImportFormQGIS")] //AutoCAD plugin command
        public void ImportFormQGIS()
        {
            Document doc = Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument;
            Database db  = doc.Database;
            Editor   ed  = doc.Editor;

            Autodesk.AutoCAD.Windows.OpenFileDialog ofd = new Autodesk.AutoCAD.Windows.OpenFileDialog(
                "Select DXF file exported from QGIS - v0.1 - Frans Nygaard 2019",
                null,
                "dxf",
                "Select DXF",
                Autodesk.AutoCAD.Windows.OpenFileDialog.OpenFileDialogFlags.DoNotTransferRemoteFiles
                );

            System.Windows.Forms.DialogResult dr = ofd.ShowDialog();

            ed.WriteMessage(ofd.Filename);

            Database     sourceDb = new Database(false, true);
            Transaction  trSource = sourceDb.TransactionManager.StartTransaction(); //Start a transaction with the source's database
            DocumentLock docLock  = doc.LockDocument();

            using (trSource)
                using (docLock)
                {
                    sourceDb.DxfIn(ofd.Filename, ofd.Filename + ".log");

                    // MOVE ALL FILES TO LAYER NAMED AFTER DXF FILENAME


                    ed.WriteMessage(ofd.Filename);
                    trSource.Commit();
                }


            Transaction trDb      = db.TransactionManager.StartTransaction(); //Start a transaction with the document's database
            Matrix3d    transform = Matrix3d.Scaling(1000, Point3d.Origin);

            using (trDb)
            {
                db.Insert(transform, sourceDb, false);
                trDb.Commit();
            }
        }
Example #6
0
        getFile(string title, string nameDefault, string extension, string nameDialog, bool selectMultiple = false)
        {
            List <string> files = new List <string>();

            acWindows.OpenFileDialog.OpenFileDialogFlags flags;
            //if (selectMultiple)
            //{
            //    flags = acWindows.OpenFileDialog.OpenFileDialogFlags.AllowMultiple;
            //}
            //else
            //{
            //    flags = acWindows.OpenFileDialog.OpenFileDialogFlags.DefaultIsFolder;
            //}

            flags = acWindows.OpenFileDialog.OpenFileDialogFlags.AllowMultiple |
                    acWindows.OpenFileDialog.OpenFileDialogFlags.DefaultIsFolder |
                    acWindows.OpenFileDialog.OpenFileDialogFlags.ForceDefaultFolder;

            string[] target;
            acWindows.OpenFileDialog ofd = new acWindows.OpenFileDialog(title,
                                                                        nameDefault,
                                                                        extension,
                                                                        nameDialog,
                                                                        flags);
            DialogResult dr = ofd.ShowDialog();

            if (dr == DialogResult.OK)
            {
                target = ofd.GetFilenames();
                foreach (string file in target)
                {
                    files.Add(file);
                }
                return(files);
            }
            else
            {
                return(null);
            }
        }
Example #7
0
        private void buttonBrowse_Click(object sender, EventArgs e)
        {
            Database db = HostApplicationServices.WorkingDatabase;

            //清空显示块名的下拉列表框中的内容
            this.comboBoxBlockName.Items.Clear();
            //新建一个打开文件对话框,并设置对话框的标题和显示文件类型为dwg或者dxf
            AcadWnd.OpenFileDialog dlg = new AcadWnd.OpenFileDialog("选择图形文件", null, "dwg;dxf", null, AcadWnd.OpenFileDialog.OpenFileDialogFlags.AllowMultiple);
            //如果打开对话框成功
            if (dlg.ShowDialog() == System.Windows.Forms.DialogResult.OK)
            {
                //显示所选择文件的路径
                this.labelPath.Text = "路径:  " + dlg.Filename;
                //导入所选择文件中的块
                BlockImportClass blockImport = new BlockImportClass();
                blockImport.ImportBlocksFromDwg(dlg.Filename);
                //开始事务处理
                using (Transaction trans = db.TransactionManager.StartTransaction())
                {
                    //打开块表
                    BlockTable bt = (BlockTable)trans.GetObject(db.BlockTableId, OpenMode.ForRead);
                    //循环遍历块表中的块表记录
                    foreach (ObjectId blockRecordId in bt)
                    {
                        //打开块表记录对象
                        BlockTableRecord btr = (BlockTableRecord)trans.GetObject(blockRecordId, OpenMode.ForRead);
                        //在下拉列表框中只加入非匿名块和非布局块的名称
                        if (!btr.IsAnonymous && !btr.IsLayout)
                        {
                            this.comboBoxBlockName.Items.Add(btr.Name);
                        }
                    }
                }
                //在下拉列表框中显示字母顺序排在第一个的块名
                if (this.comboBoxBlockName.Items.Count > 0)
                {
                    this.comboBoxBlockName.Text = this.comboBoxBlockName.Items[0].ToString();
                }
            }
        }
Example #8
0
        public void NetLoad()
        {
#if NET20
            OpenFileDialog dlg =
                new OpenFileDialog(
                    "选择.Net程序集",
                    "",
                    "dll",
                    "NetLoadX",
                    OpenFileDialog.OpenFileDialogFlags.AllowMultiple);

            var res = dlg.ShowDialog();
            if (res == System.Windows.Forms.DialogResult.OK)
            {
                foreach (var name in dlg.GetFilenames())
                {
                    Loader loader = new Loader();
                    loader.Add(name.Replace("\\", "/"));
                }
            }
#elif NET45
            Autodesk.AutoCAD.Windows.OpenFileDialog dlg =
                new Autodesk.AutoCAD.Windows.OpenFileDialog(
                    "选择.Net程序集",
                    "",
                    "dll",
                    "NetLoadX",
                    Autodesk.AutoCAD.Windows.OpenFileDialog.OpenFileDialogFlags.AllowMultiple);

            var res = dlg.ShowDialog();
            if (res == System.Windows.Forms.DialogResult.OK)
            {
                foreach (var name in dlg.GetFilenames())
                {
                    Loader loader = new Loader();
                    loader.Add(name.Replace("\\", "/"));
                }
            }
#endif
        }
Example #9
0
        private void click_AddDrawings(object sender, EventArgs e)
        {
            Autodesk.AutoCAD.Windows.OpenFileDialog ofd = new Autodesk.AutoCAD.Windows.OpenFileDialog("Select drawings:", null, "dwg", "AutoCADDrawings", Autodesk.AutoCAD.Windows.OpenFileDialog.OpenFileDialogFlags.AllowMultiple | Autodesk.AutoCAD.Windows.OpenFileDialog.OpenFileDialogFlags.DoNotTransferRemoteFiles);
            System.Windows.Forms.DialogResult       dr  = ofd.ShowDialog();

            if (dr != System.Windows.Forms.DialogResult.OK)
            {
                ed.WriteMessage("Invalid selection.");
                this.Close();
                return;
            }
            else
            {
                btn_Next.Enabled = true;
                dwgFiles         = ofd.GetFilenames();
                foreach (string file in dwgFiles)
                {
                    lv_Files.Items.Add(file);
                }
                lv_Files.AutoResizeColumns(ColumnHeaderAutoResizeStyle.ColumnContent);
            }
        }
        static public void CADTablebyExcelSheet()
        {
            const string dlName = "从Excel导入表格";

            Document doc = Application.DocumentManager.MdiActiveDocument;
            Database db  = doc.Database;
            Editor   ed  = doc.Editor;

            // 文件打开窗口
            OpenFileDialog ofd =
                new OpenFileDialog(
                    "选择需要链接的Excel表格文档!",
                    null,
                    "xls;xlsx",
                    "Excel链接到CAD",
                    OpenFileDialog.OpenFileDialogFlags.DoNotTransferRemoteFiles
                    );

            System.Windows.Forms.DialogResult dr = ofd.ShowDialog();

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

            ed.WriteMessage("\n选择到的文件为\"{0}\".", ofd.Filename);

            PromptPointResult ppr = ed.GetPoint("\n请选择表格插入点: ");

            if (ppr.Status != PromptStatus.OK)
            {
                return;
            }

            // 数据链接管理对象
            DataLinkManager dlm = db.DataLinkManager;

            // 判断数据链接是否已经存在 如果存在移除
            ObjectId dlId = dlm.GetDataLink(dlName);

            if (dlId != ObjectId.Null)
            {
                dlm.RemoveDataLink(dlId);
            }

            // 创建并添加新的数据链接

            DataLink dl = new DataLink();

            dl.DataAdapterId    = "AcExcel";
            dl.Name             = dlName;
            dl.Description      = "Excel fun with Through the Interface";
            dl.ConnectionString = ofd.Filename;
            dl.UpdateOption    |= (int)UpdateOption.AllowSourceUpdate;

            dlId = dlm.AddDataLink(dl);

            // 开启事务处理
            using (Transaction trans = db.TransactionManager.StartTransaction())
            {
                trans.AddNewlyCreatedDBObject(dl, true);

                BlockTable bt = trans.GetObject(db.BlockTableId, OpenMode.ForRead) as BlockTable;


                // 新建表格对象
                Table tb = new Table();
                tb.TableStyle = db.Tablestyle;
                tb.Position   = ppr.Value;
                tb.SetDataLink(0, 0, dlId, true);
                tb.GenerateLayout();

                BlockTableRecord btr = trans.GetObject(db.CurrentSpaceId, OpenMode.ForWrite) as BlockTableRecord;

                btr.AppendEntity(tb);
                trans.AddNewlyCreatedDBObject(tb, true);
                trans.Commit();
            }

            // 强制恢复显示表格
            ed.Regen();
        }