コード例 #1
0
        public void Core_DocumentCollection_Add()
        {
            Document doc1 = new Document(
                "1",
                null,
                null,
                new Dictionary <string, string>()
            {
                { "DOCID", "1" },
                { "VOLUME", "test" }
            },
                null);
            Document doc2 = new Document(
                "2",
                doc1,
                null,
                new Dictionary <string, string>()
            {
                { "DOCID", "2" },
                { "VOLUME", "test" }
            },
                null);
            Document doc3 = new Document(
                "1",
                null,
                new HashSet <Document>()
            {
                doc2
            },
                new Dictionary <string, string>()
            {
                { "DOCID", "1" },
                { "VOLUME", "testOverlay" }
            },
                null);
            DocumentCollection docs = new DocumentCollection();

            docs.Add(doc1);
            Assert.AreEqual(0, docs.ParentCount);
            Assert.AreEqual(0, docs.ChildCount);
            docs.Add(doc2);
            Assert.AreEqual(0, docs.ParentCount);
            Assert.AreEqual(1, docs.ChildCount);
            int parents = docs.ParentCount;

            docs.Add(doc3);
            parents = docs.ParentCount;
            int p = docs.Count(d => d.Parent != null);

            Assert.AreEqual(1, docs.ParentCount);
            Assert.AreEqual(1, docs.ChildCount);
            Assert.AreEqual(2, docs.Count);
            Assert.AreEqual("testOverlay", docs[0].Metadata["VOLUME"]);
        }
コード例 #2
0
        public static void OpenNewDrawing(string strTemplatePath)
        {
            DocumentCollection acDocMgr = Application.DocumentManager;
            Document           acDoc    = acDocMgr.Add(strTemplatePath);

            acDocMgr.MdiActiveDocument = acDoc;
        }
コード例 #3
0
        public void SetProperty_OnRemovedSubDocument_IsNotDirty()
        {
            // Arrange

            var originalDocument = (SubDocument)DocumentProxyManager.Default.CreateProxy(typeof(SubDocument));

            var collection = new DocumentCollection <SubDocument>()
            {
                originalDocument
            };

            collection.RemoveAt(0);
            collection.Add((SubDocument)DocumentProxyManager.Default.CreateProxy(typeof(SubDocument)));

            collection.ClearStatus();

            // Act

            originalDocument.IntegerProperty = 1;

            var result = collection.IsDirty;

            // Assert

            Assert.IsFalse(result);
        }
コード例 #4
0
        public void Test()
        {
            DocumentCollection acDocColl = Application.DocumentManager;

            Editor acEd = Application.DocumentManager.MdiActiveDocument.Editor;

            Window wind = Application.MainWindow;

            AcadApplication acadApplication = Application.AcadApplication as AcadApplication;

            AcadMenuBar acadMenuBa = Application.MenuBar as AcadMenuBar;

            ContextMenuExtension acCtxMenuExten = new ContextMenuExtension();


            /*Document acNewDoc = acDocColl.Add("acac.dwg");
            *  Document acNewDoc2 = acDocColl.Add("aca.dwg");*/

            /* foreach (Document acDoc in acDocColl)
             * {
             *
             *   acEd.WriteMessage($"\n{acDoc.Name}");
             *
             * }*/



            /*wind.WindowState = Window.State.Minimized;
             *
             * wind.Text = "学习学习再学习";
             * wind.SetLocation(new System.Drawing.Point(200, 200));
             * wind.SetSize(new System.Drawing.Size(500, 500));*/

            /*Application.ShowAlertDialog($"{acadApplication.Width},{acadApplication.Height}");*/


            /*foreach ( AcadPopupMenu pm in acadMenuBa)
             * {
             *
             *  acEd.WriteMessage($"\n{pm.Name}");
             *
             * }*/

            /*AcadPopupMenu pm = acadMenuBa.Item(0);
             *  pm.AddMenuItem(0, "画直线", "Line");*/

            acCtxMenuExten.Title = "自定义菜单";
            MenuItem acNewMenuItem = new MenuItem("创建新文档");

            acNewMenuItem.Click += (o, e) => {
                Document acNewDoc = acDocColl.Add("acac.dwg");
            };

            acCtxMenuExten.MenuItems.Add(acNewMenuItem);
            /*Application.AddDefaultContextMenuExtension(acCtxMenuExten);*/

            /*Application.AddObjectContextMenuExtension(RXObject.GetClass(typeof(Line)), acCtxMenuExten);*/
        }
コード例 #5
0
ファイル: Class1.cs プロジェクト: 15831944/CaseStudy
        public static void NewDrawing()
        {
            string strTemplatePath = "acad.dwt"; //新建一个图形文档

            DocumentCollection acDocMgr = Application.DocumentManager;
            Document           acDoc    = acDocMgr.Add(strTemplatePath);

            acDocMgr.MdiActiveDocument = acDoc;
        }
コード例 #6
0
        private static void AddDocument(DocumentCollection documents, CsvData data)
        {
            DocumentObject document = new DocumentObject(data.DocumentId)
            {
                MatterID = data.MatterId, FileName = data.FileName
            };

            documents.Add(document);
        }
コード例 #7
0
ファイル: DocumentOp.cs プロジェクト: 442803117/DotNetAutoCAD
        public static void NewDrawing()
        {
            // 指定使用的样板,如果这个样板没找到,
            // 就使用默认设置
            string             strTemplatePath = "acad.dwt";
            DocumentCollection acDocMgr        = Application.DocumentManager;
            Document           acDoc           = acDocMgr.Add(strTemplatePath);

            acDocMgr.MdiActiveDocument = acDoc;
        }
コード例 #8
0
        public void CopyObjectsBetweenDatabases(ObjectIdCollection acObjIdColl, string dwgFilename)
        {
            //ObjectIdCollection acObjIdColl = new ObjectIdCollection();
            // Get the current document and database
            Document acDoc   = Application.DocumentManager.MdiActiveDocument;
            Database acCurDb = acDoc.Database;

            // Change the file and path to match a drawing template on your workstation
            string sLocalRoot    = Application.GetSystemVariable("LOCALROOTPREFIX") as string;
            string sTemplatePath = sLocalRoot + "Template\\acadiso.dwt";
            // Create a new drawing to copy the objects to
            DocumentCollection acDocMgr   = Application.DocumentManager;
            Document           acNewDoc   = acDocMgr.Add(sTemplatePath);
            Database           acDbNewDoc = acNewDoc.Database;


            acDocMgr.MdiActiveDocument = acNewDoc;
            // Lock the new document
            using (DocumentLock acLckDoc = acNewDoc.LockDocument())
            {
                // Start a transaction in the new database
                using (Transaction acTrans = acDbNewDoc.TransactionManager.StartTransaction())
                {
                    // Open the Block table for read
                    BlockTable acBlkTblNewDoc;
                    acBlkTblNewDoc = acTrans.GetObject(acDbNewDoc.BlockTableId,
                                                       OpenMode.ForRead) as BlockTable;
                    // Open the Block table record Model space for read
                    BlockTableRecord acBlkTblRecNewDoc;
                    acBlkTblRecNewDoc = acTrans.GetObject(acBlkTblNewDoc[BlockTableRecord.ModelSpace],
                                                          OpenMode.ForRead) as BlockTableRecord;
                    //acTrans.TransactionManager.QueueForGraphicsFlush();
                    // Clone the objects to the new database
                    IdMapping acIdMap = new IdMapping();
                    acCurDb.WblockCloneObjects(acObjIdColl, acBlkTblRecNewDoc.ObjectId, acIdMap,
                                               DuplicateRecordCloning.Ignore, false);
                    // Save the copied objects to the database
                    acTrans.Commit();
                }
                // Unlock the document
            }
            // Set the new document current

            dynamic acadApp = Autodesk.AutoCAD.ApplicationServices.Application.AcadApplication;

            acadApp.ZoomExtents();
            //Active.Document.SendStringToExecute("_.zoom _all ", true, true, false);

            acDbNewDoc.SaveAs(dwgFilename, DwgVersion.Current);
            acDocMgr.MdiActiveDocument = acNewDoc;
            //acNewDoc.CloseAndDiscard();

            acDocMgr.MdiActiveDocument = acDoc;
        }
コード例 #9
0
        private void acadNewDoc()
        {
            DocumentCollection acDocMgr = Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager;

            Logging.AcEditorDebugCaller(MethodBase.GetCurrentMethod());

            //Добавить обработчик события - документ создан
            //acDocMgr.DocumentCreated += new DocumentCollectionEventHandler(AcDocMgr_DocumentCreated);
            //Добавить новый документ на основе шаблона
            acDocMgr.Add(s_acTemplateDocumentName);
        }
コード例 #10
0
        public static Document CreateNewDocument()
        {
            // Change the file and path to match a drawing template on your workstation
            string localRoot    = Application.GetSystemVariable("LOCALROOTPREFIX") as string;
            string templatePath = localRoot + "Template\\acad.dwt";

            DocumentCollection acDocMgr = Application.DocumentManager;
            Document           acNewDoc = acDocMgr.Add(templatePath);

            return(acNewDoc);
        }
コード例 #11
0
        public static void NewDrawing()
        {
            // Specify the template to use, if the template is not found
            // the default settings are used.
            string strTemplatePath = "acad.dwt";

            DocumentCollection acDocMgr = Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager;
            Document           acDoc    = acDocMgr.Add(strTemplatePath);

            acDocMgr.MdiActiveDocument = acDoc;
        }
コード例 #12
0
        private Document Create(string path)
        {
            _watcher.EnableRaisingEvents = false;
            //Create a new foundation xref
            DocumentCollection acDocMgr = Application.DocumentManager;
            Document           acDoc    = acDocMgr.Add(null);

            acDoc.Database.SaveAs(path, DwgVersion.Current);
            _watcher.EnableRaisingEvents = true;
            return(acDoc);
        }
コード例 #13
0
        public void NewDraing()
        {
            // 新建一个图形问价
            string strTemplatePath = "acad.dwt";// 以指定模板建立图形对象

            // 获取DocumentManager对象
            DocumentCollection documentCollection
                = Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager;

            // 利用add方法添加图形文件
            documentCollection.Add(strTemplatePath);
        }
コード例 #14
0
        /// <summary>
        /// Creates a new document while within another document based on a
        /// template defined within the parameters
        /// </summary>
        /// <param name="doc">The name of the current document</param>
        /// <param name="template">The string which defines the template's full path and name</param>
        /// <param name="directorytosavein">The directory where the newly made document should be saved</param>
        /// <returns>A new document</returns>
        public static Document CreateNew(this Document doc, string template, string directorytosavein, string dwgname)
        {
            //create a new dwg based on the BR+A template
            DocumentCollection docmgr = Application.DocumentManager;
            Document           newdoc = docmgr.Add(template);

            //switch the active drawing to the newly made drawing
            docmgr.MdiActiveDocument = newdoc;
            newdoc.Database.SaveAs(
                Path.Combine((directorytosavein), ("Setup_" + (Path.GetFileNameWithoutExtension(doc.Name) + "_") + (dwgname) + ".dwg")),
                true,
                DwgVersion.AC1800,
                doc.Database.SecurityParameters);

            return(newdoc);
        }
コード例 #15
0
        public void IsDeserializingAndMakeChanges_IsNotDirty()
        {
            // Arrange

            var collection = new DocumentCollection <SubDocument>()
            {
                IsDeserializing = true
            };


            // Act

            collection.Add(new SubDocument());

            var result = collection.IsDirty;

            // Assert

            Assert.IsFalse(result);
        }
コード例 #16
0
        public static void BlockToTemplate()
        {
            TypedValue[] acTypValAr = new TypedValue[1];
            acTypValAr.SetValue(new TypedValue((int)DxfCode.Start, "INSERT"), 0);
            SelectionFilter acSelFtr = new SelectionFilter(acTypValAr);

            PromptSelectionResult acSSPrompt = Application.DocumentManager.MdiActiveDocument.Editor.GetSelection(acSelFtr);
            Document currentDoc = Application.DocumentManager.MdiActiveDocument;

            if (acSSPrompt.Status == PromptStatus.OK)
            {
                if (acSSPrompt.Value.Count > 1)
                {
                    throw new ArgumentOutOfRangeException("More items than expected");
                }

                using (Transaction trans = Application.DocumentManager.MdiActiveDocument.TransactionManager.StartTransaction())
                {
                    DocumentCollection acDocMgr = Application.DocumentManager;
                    Document           newDoc   = acDocMgr.Add("");
                    using (DocumentLock lockObj = newDoc.LockDocument())
                    {
                        using (Transaction destinationTrans = newDoc.TransactionManager.StartTransaction())
                        {
                            BlockReference        refObj    = (BlockReference)trans.GetObject(acSSPrompt.Value[0].ObjectId, OpenMode.ForWrite);
                            BlockRefDrawingObject reference = new BlockRefDrawingObject(currentDoc, refObj);

                            Database              source          = Application.DocumentManager.MdiActiveDocument.Database;
                            BlockDrawingObject    newInstance     = reference.GetBlock().TransferToDocument(newDoc);
                            TemplateDrawingObject blockDefinition = newInstance.ConvertToTemplate();

                            destinationTrans.Commit();
                        }
                    }

                    Application.DocumentManager.MdiActiveDocument = newDoc;
                }
            }
        }
コード例 #17
0
        public void SetProperty_OnRemovedSubDocument_IsNotDirty()
        {
            // Arrange

            var originalDocument = (SubDocument) DocumentProxyManager.Default.CreateProxy(typeof (SubDocument));

            var collection = new DocumentCollection<SubDocument>
            {
                originalDocument
            };

            collection.RemoveAt(0);
            collection.Add((SubDocument) DocumentProxyManager.Default.CreateProxy(typeof (SubDocument)));

            collection.ClearStatus();

            // Act

            originalDocument.IntegerProperty = 1;

            var result = collection.IsDirty;

            // Assert

            Assert.IsFalse(result);
        }
コード例 #18
0
        public void IsDeserializingAndMakeChanges_IsNotDirty()
        {
            // Arrange

            var collection = new DocumentCollection<SubDocument>
            {
                IsDeserializing = true
            };

            // Act

            collection.Add(new SubDocument());

            var result = collection.IsDirty;

            // Assert

            Assert.IsFalse(result);
        }
コード例 #19
0
        public static void OpenDocument(Document sourceDoc, DocumentCollection acDocMgr, string folderName)
        {
            Database sourceDB = sourceDoc.Database;

            //Create Export Directory
            string exportName = Path.GetFileNameWithoutExtension(sourceDoc.Name);
            string exportPath = folderName + @"\" + exportName;

            System.IO.DirectoryInfo di     = Directory.CreateDirectory(exportPath);
            System.IO.DirectoryInfo diDWG  = Directory.CreateDirectory(di.FullName + @"\DWG");
            System.IO.DirectoryInfo diDXF  = Directory.CreateDirectory(di.FullName + @"\DXF");
            System.IO.DirectoryInfo diADXF = Directory.CreateDirectory(di.FullName + @"\DXF FACE A");
            System.IO.DirectoryInfo diBDXF = Directory.CreateDirectory(di.FullName + @"\DXF FACE B");
            System.IO.DirectoryInfo diPDF  = Directory.CreateDirectory(di.FullName + @"\PDF");

            int i = 0;

            using (Transaction acTrans = sourceDB.TransactionManager.StartTransaction())
            {
                // This example returns the layer table for the current database
                LayerTable acLyrTbl;
                acLyrTbl = acTrans.GetObject(sourceDB.LayerTableId, OpenMode.ForRead) as LayerTable;

                string dwgFlatTemplate   = _templateFolder + "template_Plan.dwt";
                string dwgBombedTemplate = _templateFolder + "template_Bombed.dwt";
                string dxfTemplate       = _templateFolder + "acad.dwt";

                Document newDoc;
                Document bombedDoc = acDocMgr.Add(dwgBombedTemplate);
                Document planDoc   = acDocMgr.Add(dwgFlatTemplate);
                Document dxfDoc    = acDocMgr.Add(dxfTemplate);

                // Step through the Layer table
                foreach (ObjectId acObjId in acLyrTbl)
                {
                    LayerTableRecord acLyrTblRec;
                    acLyrTblRec = acTrans.GetObject(acObjId, OpenMode.ForRead) as LayerTableRecord;

                    //Active the source document
                    if (acDocMgr.MdiActiveDocument != sourceDoc)
                    {
                        acDocMgr.MdiActiveDocument = sourceDoc;
                    }

                    //Retrive Elements by Layers
                    string             panelName          = acLyrTblRec.Name;
                    ObjectIdCollection collection         = Selection.SelectEntities(sourceDoc, panelName);
                    ObjectIdCollection checkingCollection = Selection.CheckingCollection(sourceDoc, panelName);

                    if (collection.Count != 0)
                    {
                        if (checkingCollection.Count == 0)
                        {
                            newDoc = planDoc;
                        }
                        else
                        {
                            newDoc = bombedDoc;
                        }

                        //Lock the new doc
                        using (DocumentLock Aclock = newDoc.LockDocument())
                        {
                            //Paste the object in it
                            ObjectIdCollection pastedElementsIds = ACADFunction.CopyElements(newDoc, collection, sourceDB, false);

                            //Active the document
                            if (acDocMgr.MdiActiveDocument != newDoc)
                            {
                                acDocMgr.MdiActiveDocument = newDoc;
                            }

                            ACADFunction.ApplyResultLayer(newDoc, panelName);

                            ACADFunction.ReframeLayouts(newDoc, panelName);


                            ////Print it - Deprecated
                            //while (PlotFactory.ProcessPlotState != ProcessPlotState.NotPlotting)
                            //{
                            //    System.Threading.Thread.Sleep(500);
                            //}

                            //if (i < 5)
                            //{

                            //}
                            //Tools.MultiSheetPlot(newDoc, diPDF, panelName);

                            //Purge unused layer
                            ACADFunction.PurgeLayers(newDoc);

                            //Save It
                            Tools.SaveDoc(newDoc, diDWG, panelName);

                            //Remove object for the next run
                            ACADFunction.EraseElements(newDoc, pastedElementsIds);
                        }

                        //Active the source document
                        if (acDocMgr.MdiActiveDocument != sourceDoc)
                        {
                            acDocMgr.MdiActiveDocument = sourceDoc;
                        }

                        //Select the face A polyline
                        ObjectIdCollection cyanPolyline = Selection.SelectCyanLines(sourceDoc, panelName);

                        //Seclect the face B polyline
                        ObjectIdCollection greenPolyline = Selection.SelectGreenLines(sourceDoc, panelName);

                        //Active the dxf document
                        if (acDocMgr.MdiActiveDocument != dxfDoc)
                        {
                            acDocMgr.MdiActiveDocument = dxfDoc;
                        }

                        //Lock the new doc
                        using (DocumentLock Aclock = dxfDoc.LockDocument())
                        {
                            //Paste the object in it
                            ObjectIdCollection pastedpolylinesIds = ACADFunction.CopyElements(dxfDoc, cyanPolyline, sourceDB, true);

                            //Purge unused layer
                            ACADFunction.PurgeLayers(dxfDoc);

                            //Save it
                            if (checkingCollection.Count != 0)
                            {
                                Tools.SaveDoc(dxfDoc, diADXF, panelName + "A");
                            }
                            else
                            {
                                Tools.SaveDoc(dxfDoc, diDXF, panelName);
                            }

                            //remove the elements for the next run
                            ACADFunction.EraseElements(dxfDoc, pastedpolylinesIds);
                        }

                        //Check for panel curvature
                        if (checkingCollection.Count != 0)
                        {
                            //Lock the new doc
                            using (DocumentLock Aclock = dxfDoc.LockDocument())
                            {
                                //Paste the object in it
                                ObjectIdCollection pastedpolylinesIds = ACADFunction.CopyElements(dxfDoc, greenPolyline, sourceDB, true);

                                //Purge unused layer
                                ACADFunction.PurgeLayers(dxfDoc);

                                //Save it
                                Tools.SaveDoc(dxfDoc, diBDXF, panelName + "B");

                                //remove the elements for the next run
                                ACADFunction.EraseElements(dxfDoc, pastedpolylinesIds);
                            }
                        }
                    }

                    i++;

                    string logPath = _templateFolder + @"\" + exportName + @".txt";
                    File.WriteAllLines(logPath, LogFile.LogList.ToArray());
                }
            }
        }