public static void LoopOnVentelles()
        {
            OpenFileDialog filesDialog = new OpenFileDialog();
            DialogResult   result      = filesDialog.ShowDialog();

            if (result == DialogResult.OK)
            {
                string folderName = Path.GetDirectoryName(filesDialog.FileNames[0]);
                _templateFolder = folderName + @"\Files\";

                DocumentCollection acDocMgr = Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager;

                foreach (string fileName in filesDialog.FileNames)
                {
                    Document sourceDoc = acDocMgr.Open(fileName, false);
                    //Active the document
                    if (acDocMgr.MdiActiveDocument != sourceDoc)
                    {
                        acDocMgr.MdiActiveDocument = sourceDoc;
                    }

                    OpenDocument(sourceDoc, acDocMgr, folderName);

                    sourceDoc.CloseAndDiscard();
                }
            }
        }
Esempio n. 2
0
        getDoc(string nameFull, bool isOpen = false, bool activate = false)
        {
            Document           acDoc    = null;
            DocumentCollection acadDocs = BaseObjs._acadDocs;

            if (isOpen)
            {
                foreach (Document doc in BaseObjs._acadDocs)
                {
                    if (doc.Name == nameFull)
                    {
                        acDoc = doc;
                        if (activate)
                        {
                            acadDocs.MdiActiveDocument = acDoc;
                        }
                        break;
                    }
                }
            }
            else
            {
                try
                {
                    acDoc = acadDocs.Open(nameFull, false);
                }
                catch (System.Exception ex)
                {
                    BaseObjs.writeDebug(ex.Message + " FileManager.cs: line: 288");
                }
            }
            return(acDoc);
        }
Esempio n. 3
0
        public static void NewOpen()
        {
            /// 简图路径
            string fileName = Environment.GetEnvironmentVariable("fileName");

            DocumentCollection acDocMgr = cadApplication.DocumentManager;

            string newfileName = fileName.Replace(dwgExtesion, orgDwgextesion);

            if (File.Exists(newfileName))
            {
                acDocMgr.Open(newfileName);
            }
            else
            {
                acDocMgr.Open(fileName);
            }
        }
Esempio n. 4
0
        public Document OpenDrawing()
        {
            string             filePath = SelectDrawing();
            DocumentCollection acDocMgr = AcAp.DocumentManager;

            acDocMgr.Open(filePath, false);
            Document doc = acDocMgr.MdiActiveDocument;

            return(doc);
        }
Esempio n. 5
0
        // open an existing drawing
        public void open_cad_file()
        {
            String             strFileName = "D:\\ACSharp\\ACSharp\\BRepo\\TestingFile.dwg";
            DocumentCollection docCol      = Application.DocumentManager;

            if (File.Exists(strFileName))
            {
                docCol.Open(strFileName, false);
            }
            else
            {
                docCol.MdiActiveDocument.Editor.WriteMessage("File " + strFileName + " does not exit.");
            }
        }
Esempio n. 6
0
        public void OpenDrawing()
        {
            DocumentCollection acDocMgr = Application.DocumentManager;

            if (File.Exists(this.FileName))
            {
                acDocMgr.Open(this.FileName, false);
            }
            else
            {
                acDocMgr.MdiActiveDocument.Editor.WriteMessage("File " + this.FileName +
                                                               " does not exist.");
            }
        }
Esempio n. 7
0
        public static void OpenDrawing()
        {
            string strFileName = "D:\\MyPlane\\CaseStudy\\autoCAD\\guobao.dwg";  //打开拥有一些图形的图形文档

            DocumentCollection acDocMgr = Application.DocumentManager;

            if (File.Exists(strFileName))
            {
                acDocMgr.Open(strFileName, false);
            }
            else
            {
                acDocMgr.MdiActiveDocument.Editor.WriteMessage("File" + strFileName + "dose not exist");
            }
        }
Esempio n. 8
0
        private void WebBrowser_Navigating(object sender, WebBrowserNavigatingEventArgs e)
        {
            //URL을 검사해서, 다운로드를 위한 URL인지 확인하는 작업
            if (e.Url.Segments[e.Url.Segments.Length - 1].EndsWith(".dwg"))
            {
                e.Cancel = true;

                string    filename = e.Url.Segments[e.Url.Segments.Length - 1];
                string    file     = filepath + "\\" + filename;
                WebClient client   = new WebClient();

                DocumentCollection acDocMgr = Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager;

                //var SameDocument = from Document document in acDocMgr where filename.EndsWith(document.Name) select document;
                bool isOpened = false;
                foreach (Document doc in acDocMgr)
                {
                    if (file.Equals(doc.Name))
                    {
                        isOpened = true;
                        break;
                    }
                }

                if (isOpened == false)
                {
                    if (File.Exists(file))
                    {
                        DialogResult dialogResult = MessageBox.Show("File " + filename + " already exist. Do you want to override it?", "Download", MessageBoxButtons.YesNo);
                        if (dialogResult == DialogResult.Yes)
                        {
                            client.DownloadFile(e.Url, file);
                        }
                    }
                    else
                    {
                        client.DownloadFile(e.Url, file);
                    }

                    acDocMgr.Open(file, false);
                }
                else
                {
                    MessageBox.Show("File " + filename + " already opened. Can not download file!");
                }
            }
        }
        public void OpenDwg()
        {
            Editor ed = Application.DocumentManager.MdiActiveDocument.Editor;
            //获取文档管理器对象以打开Dwg文件
            DocumentCollection docs = Application.DocumentManager;
            //设置打开文件对话框的有关选项
            PromptOpenFileOptions opt = new PromptOpenFileOptions("\n请输入文件名:");

            opt.Filter      = "图形(*.dwg)|*.dwg|图形(*.dxf)|*.dxf";
            opt.FilterIndex = 0;
            //根据打开文件对话框中用户的选择,获取文件名
            string filename = ed.GetFileNameForOpen(opt).StringResult;
            //打开所选择的Dwg文件
            Document doc = docs.Open(filename, true);

            //设置当前的活动文档为新打开的Dwg文件
            Application.DocumentManager.MdiActiveDocument = doc;
        }
Esempio n. 10
0
        [CommandMethod("OpenDrawing", CommandFlags.Session)]// 打开文件
        public void OpenDrawing()
        {
            // 首先找到要打开文件的路径
            string filePath = "C:\\User\\ASUS\\Documents\\autocad实例图形 杨翕然.dwg";

            // 利用Document Collection类的对象打开文件
            DocumentCollection docCollection = Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager;

            // 判断图形是否存在
            if (File.Exists(filePath))
            {
                docCollection.Open(filePath, false);//并不是只“可读”
            }
            else// 如果不存在
            {
                MessageBox.Show("File didn't exist", "can't find file", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }
Esempio n. 11
0
        public static void OpenDwg(string fileName)
        {
            DocumentCollection acDocMgr = ZwSoft.ZwCAD.ApplicationServices.Application.DocumentManager;

            Document acNewDoc   = acDocMgr.Open(fileName, false);   //filepath打开的文件路径,false表示文件可改写
            Database acDbNewDoc = acNewDoc.Database;

            acDocMgr.MdiActiveDocument = acNewDoc;     //将打开的文件设置为当前显示

            /*Editor ed = Application.DocumentManager.MdiActiveDocument.Editor;
             * //获取文档管理器对象以打开Dwg文件
             * DocumentCollection docs = Application.DocumentManager;
             *
             * //打开所选择的Dwg文件
             * Document doc = docs.Open(fileName);
             * //设置当前的活动文档为新打开的Dwg文件
             * Application.DocumentManager.MdiActiveDocument = doc;
             */
        }
Esempio n. 12
0
        public static void OpenDrawing()
        {
            OpenFileDialog openFileDialog = new OpenFileDialog();

            openFileDialog.Filter      = "CAD文件|*.dwg";
            openFileDialog.Multiselect = false;
            if (openFileDialog.ShowDialog() == DialogResult.OK)
            {
                string             strFileName = openFileDialog.FileName;
                DocumentCollection acDocMgr    = Application.DocumentManager;
                if (File.Exists(strFileName))
                {
                    acDocMgr.Open(strFileName, false);
                }
                else
                {
                    acDocMgr.MdiActiveDocument.Editor.WriteMessage("File " + strFileName +
                                                                   " does not exist.");
                }
            }
        }
Esempio n. 13
0
        public void ProcessBlock()
        {
            double   insPnt_X = 0d;
            double   insPnt_Y = 0d;
            Document bDwg     = Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument;

            Autodesk.AutoCAD.DatabaseServices.TransactionManager bTransMan = bDwg.TransactionManager;
            Editor ed   = bDwg.Editor;
            string path = Environment.GetFolderPath(Environment.SpecialFolder.DesktopDirectory);

            string[] familyFiles = Directory.GetFiles(path + "\\fixtures", "*.dwg", SearchOption.TopDirectoryOnly);
            ed.WriteMessage("\nUsing directory {0}", path + "\\fixtures");

            try
            {
                DocumentCollection acDocMgr = Application.DocumentManager;
                foreach (string familyFile in familyFiles)
                {
                    string   equipmentNumber = Path.GetFileNameWithoutExtension(familyFile);
                    Document doc             = acDocMgr.Open(familyFile, false);
                    if (doc != null)
                    {
                        doc.LockDocument();
                        ed.WriteMessage("\nProcessing {0}", equipmentNumber);
                        ExplodeBlockByNameCommand(ed, doc, equipmentNumber);
                        doc.CloseAndSave(familyFile);
                        doc.Dispose();
                    }
                    else
                    {
                        ed.WriteMessage("\nCould not open {0}", equipmentNumber);
                    }

                    using (bDwg.LockDocument())
                        using (Transaction bTrans = bTransMan.StartTransaction())
                        {
                            Database blkDb = new Database(false, true);
                            blkDb.ReadDwgFile(familyFile, System.IO.FileShare.Read, true, ""); //Reading block source file
                            string   name = Path.GetFileNameWithoutExtension(familyFile);
                            ObjectId oid  = bDwg.Database.Insert(name, blkDb, true);

                            using (BlockReference acBlkRef = new BlockReference(new Point3d(insPnt_X, insPnt_Y, 0), oid))
                            {
                                BlockTableRecord acCurSpaceBlkTblRec;
                                acCurSpaceBlkTblRec = bTrans.GetObject(bDwg.Database.CurrentSpaceId, OpenMode.ForWrite) as BlockTableRecord;

                                acCurSpaceBlkTblRec.AppendEntity(acBlkRef);
                                bTrans.AddNewlyCreatedDBObject(acBlkRef, true);
                            }
                            bTrans.Commit();
                        }
                    insPnt_X += 240d;
                    if (insPnt_X > 2400)
                    {
                        insPnt_X  = 0;
                        insPnt_Y += 240d;
                    }
                }
            }
            catch (System.Exception err)
            {
                ed.WriteMessage("\nSomething went wrong in main process.");
                File.AppendAllText(Environment.GetFolderPath(Environment.SpecialFolder.DesktopDirectory) + "\\error_main.log", err.ToString());
            }
            finally
            {
            }
        }
Esempio n. 14
0
        /// <summary>
        /// 修改实体坐标颜色
        /// </summary>
        public static void ChangeEntityColor()
        {
            try
            {
                Editor ed = Application.DocumentManager.MdiActiveDocument.Editor;
                //获取文档管理器对象以打开Dwg文件
                DocumentCollection docs = Application.DocumentManager;

                var fileNameSource = SourcePath;
                //打开所选择的Dwg文件
                Document docSource = docs.Open(fileNameSource, false);
                using (DocumentLock acLckDoc = docSource.LockDocument()) // acNewDoc.LockDocument())
                {
                    using (var trans = docSource.Database.TransactionManager.StartTransaction())
                    {
                        BlockTable bt = (BlockTable)trans.GetObject(docSource.Database.BlockTableId, OpenMode.ForRead);
                        //打开数据库的模型空间块表记录对象
                        BlockTableRecord btr = (BlockTableRecord)trans.GetObject(bt[BlockTableRecord.ModelSpace], OpenMode.ForRead);
                        //循环遍历模型空间中的实体
                        foreach (ObjectId id in btr)
                        {
                            var ent = trans.GetObject(id, OpenMode.ForRead) as Entity;
                            if (dicSource.ContainsKey(ent.Handle))
                            {
                                var ent1 = trans.GetObject(id, OpenMode.ForWrite) as Entity;
                                ent1.Color = GetColor(dicSource[ent.Handle]);
                                ent1.DowngradeOpen();
                            }
                        }
                        trans.Commit();
                    }
                }
                string filename = TargetPath;
                //打开所选择的Dwg文件
                Document doc = docs.Open(filename, false);
                //设置当前的活动文档为新打开的Dwg文件
                Application.DocumentManager.MdiActiveDocument = doc;
                //锁定新文档
                using (DocumentLock acLckDoc = doc.LockDocument()) // acNewDoc.LockDocument())
                {
                    using (var trans = doc.Database.TransactionManager.StartTransaction())
                    {
                        BlockTable bt = (BlockTable)trans.GetObject(doc.Database.BlockTableId, OpenMode.ForRead);
                        //打开数据库的模型空间块表记录对象
                        BlockTableRecord btr = (BlockTableRecord)trans.GetObject(bt[BlockTableRecord.ModelSpace], OpenMode.ForRead);
                        //循环遍历模型空间中的实体
                        foreach (ObjectId id in btr)
                        {
                            var ent = trans.GetObject(id, OpenMode.ForRead) as Entity;
                            if (dic.ContainsKey(ent.Handle))
                            {
                                var ent1 = trans.GetObject(id, OpenMode.ForWrite) as Entity;
                                ent1.Color = GetColor(dic[ent.Handle]);
                                ent1.DowngradeOpen();
                            }
                        }
                        trans.Commit();
                    }
                }
            }
            catch (Autodesk.AutoCAD.Runtime.Exception e)
            {
                MessageBox.Show(@"文档被占用,请关闭文档后重新操作!");
            }
        }