private void Button1_Click(object sender, EventArgs e) { this.Hide(); OpenFileDialog openFileDialog = new OpenFileDialog(); openFileDialog.DefaultExt = "DWG"; openFileDialog.Multiselect = true; openFileDialog.Title = "选择DWG文件"; openFileDialog.Filter = "AutoCAD文件(*.Dwg)|*.DWG|DXF文件(*.DXF)|*.DXF"; openFileDialog.DefaultExt = "*.dwg"; openFileDialog.InitialDirectory = this.TextBox1.Text; if (openFileDialog.ShowDialog() == DialogResult.OK) { string[] fileNames = openFileDialog.FileNames; short num = 0; short num2 = checked ((short)Information.UBound(fileNames, 1)); short num3 = num; for (;;) { short num4 = num3; short num5 = num2; if (num4 > num5) { break; } DocumentCollectionExtension.Open(Application.DocumentManager, fileNames[(int)num3], false); num3 += 1; } this.Close(); } }
public void JGTK() { string text = Class33.Class31_0.Info.DirectoryPath + "\\DWG\\结构图库.dwg"; DocumentCollection documentManager = Application.DocumentManager; Document mdiActiveDocument = DocumentCollectionExtension.Open(Application.DocumentManager, text, false); documentManager.MdiActiveDocument = mdiActiveDocument; }
public static void OpenFile(string F) { DocumentCollection documentManager = Application.DocumentManager; Document document = DocumentCollectionExtension.Open(Application.DocumentManager, F, false); Database database = document.Database; documentManager.MdiActiveDocument = document; }
private static void LibraryAction(Editor ed) { if (MessageHandler.LibraryToAppActions.Count > 0) { string action = MessageHandler.LibraryToAppActions.Dequeue(); //MessageBox.Show(action); Dictionary <string, string> actionD = JsonConvert.DeserializeObject <Dictionary <string, string> >(action); if (actionD["option"] == "OPEN") { List <string> files = Directory.GetFiles(actionD["hyperlink"]).ToList(); string dwg = ""; foreach (string file in files) { if (file.Contains(".dwg")) { dwg = file; } } if (dwg != "") { DocumentCollection docMgr = Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager; DocumentCollectionExtension.Open(docMgr, dwg, false); } } else if (actionD["option"] == "LOAD") { List <string> files = Directory.GetFiles(actionD["hyperlink"]).ToList(); string dwg = ""; foreach (string file in files) { if (file.Contains(".dwg")) { dwg = file; } } if (dwg != "") { Database sourceDb = new Database(false, true); Document doc = Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument; Database cDB = doc.Database; sourceDb.ReadDwgFile(dwg, FileOpenMode.OpenForReadAndAllShare, true, ""); //Read the DWG into a side database String fileName = Path.GetFileNameWithoutExtension(dwg); cDB.Insert(fileName, sourceDb, false); Autodesk.AutoCAD.DatabaseServices.TransactionManager tm = cDB.TransactionManager; try { ObjectIdCollection blockIds = new ObjectIdCollection(); using (Transaction myT = tm.StartTransaction()) { // Open the block table BlockTable bt = (BlockTable)tm.GetObject(cDB.BlockTableId, OpenMode.ForRead, false); BlockTableRecord btr = myT.GetObject(bt[fileName], OpenMode.ForRead) as BlockTableRecord; BlockReference br = new BlockReference(Point3d.Origin, btr.ObjectId); if (BlockMovingRotating.Jig(br)) { BlockTableRecord modelspace = myT.GetObject(bt[BlockTableRecord.ModelSpace], OpenMode.ForWrite) as BlockTableRecord; modelspace.AppendEntity(br); myT.AddNewlyCreatedDBObject(br, true); myT.Commit(); } else { myT.Abort(); } btr.Dispose(); } } catch (System.Exception ex) { MessageBox.Show(ex.Message); } } } else if (actionD["option"] == "VIEW") { MessageBox.Show("VIEW"); } // do your AutoCAD tasks here //MessageBox.Show("Text received from the Library window: " + actionD); // reply something back //MessageHandler.AppToLibraryActions.Enqueue("A message from the AutoCAD plugin - " + DateTime.Now.ToString()); } }
transferObjects(List <ObjectId> idPolys3d, string dwgTemplate, string type, string namePntFile = null) { List <polyInfo> pInfo = new List <polyInfo>(); List <string> layers = new List <string>(); foreach (ObjectId idPoly3d in idPolys3d) { string nameLayer = idPoly3d.getLayer(); polyInfo p = new polyInfo(p.pnts3d = idPoly3d.getCoordinates3d(), p.layer = nameLayer); layers.Add(nameLayer); if (!layers.Contains(nameLayer)) { Layer.manageLayers(nameLayer); } } Document acadDocX = BaseObjs._acadDoc; Document acadDocT = null; string pathX = Path.GetDirectoryName(acadDocX.Database.Filename); string nameX = Path.GetFileName(acadDocX.Database.Filename); string nameT = string.Format("{0}{1}{2}{3}.dwg", pathX, @"\", nameX.Substring(0, 4), type); if (File.Exists(nameT)) { List <string> names = new List <string>(); //check to see if user has it open foreach (Document doc in BaseObjs._acadDocs) { names.Add(Path.GetFileName(doc.Name)); } if (names.Contains(Path.GetFileName(nameT))) { foreach (Document doc in BaseObjs._acadDocs) { if (doc.Name == Path.GetFileName(nameT)) { acadDocT = doc; BaseObjs._acadDocs.MdiActiveDocument = acadDocT; break; } } } else { string nameDWL = string.Format("{0}{1}{2}.dwl", pathX, @"\", Path.GetFileNameWithoutExtension(nameX)); if (File.Exists(nameDWL)) { StreamReader sr = new StreamReader(nameDWL); string user = sr.ReadLine(); sr.Close(); string message = string.Format("{0} has {1}open. Select OK to Proceed when the file is available", user, nameT); var result = MessageBox.Show(message, string.Format("{0} is open.", nameT), MessageBoxButtons.YesNo); if (result == DialogResult.Yes) { acadDocT = DocumentCollectionExtension.Open(BaseObjs._acadDocs, nameT, false); } else { return; } } else { acadDocT = DocumentCollectionExtension.Open(BaseObjs._acadDocs, nameT, false); } } } else { acadDocT = DocumentCollectionExtension.Add(BaseObjs._acadDocs, dwgTemplate); acadDocT.save(); //BaseObjs.sendCommand(System.Convert.ToString(27)); //BaseObjs.sendCommand("filedia\r0\r"); //BaseObjs.sendCommand(string.Format("saveas\r2013\r{0}\r", nameT)); //BaseObjs.sendCommand("filedia\r1\r"); } if (type == "TOPO") { if (idPolys3d.Count > 0) { foreach (polyInfo p in pInfo) { p.pnts3d.addPoly3d(p.layer); } } if (namePntFile != null) { transferPoints("Import", namePntFile, BaseObjsCom.aeccSurvDoc); } } else if (type == "CONT") { if (idPolys3d.Count > 0) { foreach (polyInfo p in pInfo) { p.pnts3d.addPoly3d(p.layer); } } if (namePntFile != null) { transferPoints("Import", namePntFile, BaseObjsCom.aeccSurvDoc); } } }
getDrawing(string pathDwg) { Document acadDoc; bool fileExists = FileSystem.FileExists(pathDwg); DialogResult pr; var names = BaseObjs._acadDocsList; if (fileExists) { if (names.Contains(Path.GetFileName(pathDwg))) { foreach (Document doc in BaseObjs._acadDocs) { if (doc.Name == Path.GetFileName(pathDwg)) { BaseObjs._acadDocs.MdiActiveDocument = doc; break; } } } else { pr = MessageBox.Show(string.Format("{0} {1} .dwg exists - Open Y/N?: ", JN, TOP), "", MessageBoxButtons.YesNo); if (pr == DialogResult.Yes) { acadDoc = DocumentCollectionExtension.Open(BaseObjs._acadDocs, pathDwg, false); } else { return; } } } else { acadDoc = DocumentCollectionExtension.Add(BaseObjs._acadDocs, TemplateTOP); acadDoc.saveAsDoc(pathDwg); Application.DocumentManager.MdiActiveDocument = acadDoc; } myUtility.CreateSurveyProject(JN); bool exists; using (BaseObjs._acadDoc.LockDocument()) { ObjectId idDictPPF2 = Dict.getNamedDictionary("PPF2", out exists); if (exists) { Dict.deleteXRec(idDictPPF2, "strTOP"); } TypedValue[] tvs = new TypedValue[4]; tvs.SetValue(new TypedValue(1000, JN), 0); tvs.SetValue(new TypedValue(1000, TOP), 1); tvs.SetValue(new TypedValue(1000, TXTFILE), 2); tvs.SetValue(new TypedValue(1000, string.Format("{0}{1}{2}_mod.txt", Path.GetDirectoryName(TXTFILE), @"\", Path.GetFileNameWithoutExtension(TXTFILE))), 3); ResultBuffer rb = new ResultBuffer(tvs); Dict.addXRec(idDictPPF2, "strTOP", rb); } }
private void cmdSetup_Click(object sender, RoutedEventArgs e) { FolderBrowserDialog fbd = new FolderBrowserDialog(); fbd.Description = "Browse to Project Folder"; fbd.ShowDialog(); string strPath = fbd.SelectedPath; int intPosX = 1, intPos = 0; if (strPath == "") { System.Windows.MessageBox.Show("No Folder Selected"); return; } else { while (intPosX != 0) { intPos = intPosX + 1; intPosX = (short)(strPath.IndexOf("\\", intPos - 1) + 1); } } string strJN = strPath.Substring(intPos - 1); strPath = string.Format("{0}\\{1}EW.dwg", strPath, strJN); if (FileSystem.FileExists(strPath)) { MessageBoxResult varResponse = System.Windows.MessageBox.Show(string.Format("File {0} exists! Make Backup??", strPath), "File Exists!", MessageBoxButton.YesNoCancel); if (varResponse == MessageBoxResult.Yes) { FileInfo fileInfo; fileInfo = FileSystem.GetFileInfo(strPath); string strDateCreated = (fileInfo.LastAccessTime).ToString(); intPos = (short)(strDateCreated.IndexOf(" ") + 1); strDateCreated = strDateCreated.Substring(0, intPos - 1); strDateCreated = strDateCreated.Replace("/", "_"); intPos = strPath.IndexOf("."); FileSystem.CopyFile(strPath, string.Format("{0}_{1}.dwg", strPath.Substring(0, intPos - 1), strDateCreated)); FileSystem.DeleteFile(strPath); } else if (varResponse == MessageBoxResult.No) { FileSystem.DeleteFile(strPath); } else if (varResponse == MessageBoxResult.Cancel) { return; } } using (BaseObjs._acadDoc.LockDocument()) { Document objDwgEW = DocumentCollectionExtension.Add(BaseObjs._acadDocs, @"R:\TSET\Template\CIVIL3D2015\EW.dwt"); BaseObjs._acadDoc.Database.SaveAs(strPath, true, DwgVersion.Current, BaseObjs._acadDoc.Database.SecurityParameters); } using (BaseObjs._acadDoc.LockDocument()) { xRef.doMXR(); } Point3d pnt3dUR = BaseObjs._acadDoc.Database.Extmax; SelectionSet objSSet = EW_Utility1.buildSSetTable(); ObjectId[] ids = objSSet.GetObjectIds(); if (ids == null || ids.Length == 0) { return; } Table tbl = null; using (BaseObjs._acadDoc.LockDocument()) { ObjectId id = ids[0]; try { using (Transaction tr = BaseObjs.startTransactionDb()) { tbl = (Table)tr.GetObject(id, OpenMode.ForWrite); Extents3d ext3d = (Extents3d)tbl.Bounds; tbl.TransformBy(Matrix3d.Displacement(new Vector3d(pnt3dUR.X, pnt3dUR.Y, 0))); objSSet = Base_Tools45.Select.buildSSet(typeof(Polyline), ext3d.MinPoint, ext3d.MaxPoint); ids = objSSet.GetObjectIds(); ObjectIdCollection idsm = new ObjectIdCollection(); foreach (ObjectId idm in ids) { idsm.Add(idm); } idsm.moveObjs(Point3d.Origin, pnt3dUR); tr.Commit(); } } catch (System.Exception ex) { BaseObjs.writeDebug(string.Format("{0} frmEarthwork.cs: line: 137", ex.Message)); } Layer.manageLayers("0"); string strDwgName = BaseObjs.docName; intPos = strDwgName.IndexOf(".") + 1; strDwgName = strDwgName.Substring(0, intPos - 1); BlockReference blkRef; blkRef = xRef.getXRefBlockReference("CNTL"); if (blkRef != null) { string strBlkName = blkRef.Name; BaseObjs._acadDoc.SendStringToExecute(string.Format("-LA\rF\r{0}*\r\r", strBlkName), true, false, false); BaseObjs._acadDoc.SendStringToExecute(string.Format("-LA\rT\r{0}|CURB\r\r", strBlkName), true, false, false); BaseObjs._acadDoc.SendStringToExecute(string.Format("-LA\rT\r{0}|GB\r\r", strBlkName), true, false, false); BaseObjs._acadDoc.SendStringToExecute(string.Format("-LA\rT\r{0}|BLDG\r\r", strBlkName), true, false, false); BaseObjs._acadDoc.SendStringToExecute(string.Format("-LA\rT\r{0}|FL\r\r", strBlkName), true, false, false); BaseObjs._acadDoc.SendStringToExecute(string.Format("-LA\rT\r{0}|FS\r\r", strBlkName), true, false, false); BaseObjs._acadDoc.SendStringToExecute(string.Format("-LA\rT\r{0}|GUTTER\r\r", strBlkName), true, false, false); BaseObjs._acadDoc.SendStringToExecute(string.Format("-LA\rT\r{0}|WALL\r\r", strBlkName), true, false, false); } blkRef = xRef.getXRefBlockReference("BNDRY"); if (blkRef != null) { string strBlkName = blkRef.Name; BaseObjs._acadDoc.SendStringToExecute(string.Format("-LA\rF\r{0}*\r\r", strBlkName), true, false, false); BaseObjs._acadDoc.SendStringToExecute(string.Format("-LA\rT\r{0}|PL\r\r", strBlkName), true, false, false); } View.ZoomExtents(); } System.Windows.Forms.MessageBox.Show("User needs to create data shortcut for Surfaces: CPNT-ON and EXIST"); }
static public void transferObjs(string option) { string defExt = ".dwg"; string title = string.Format("Transfer {0}", option); string filter = "All Drawings (*.dwg)|*.dwg"; string dir = Path.GetDirectoryName(BaseObjs.docFullName); string[] files = FileManager.getFiles(defExt, title, filter, dir); if (files == null || files.Length == 0) { return; } Document docTar = BaseObjs._acadDoc; Database dbTar = docTar.Database; Document docSrc = null; Database dbSrc = null; string nameFile = files[0]; string nameUser = ""; int status = FileManager.getFileStatus(nameFile, out nameUser); switch (status) { case (int)filestatus.isOpenLocalReadOnly: case (int)filestatus.isOpenLocal: //connect to db and make transfer foreach (Document doc in BaseObjs._acadDocs) { if (doc.Name == nameFile) { docSrc = doc; dbSrc = docSrc.Database; } } break; case (int)filestatus.isAvailable: //open and make transfer docSrc = DocumentCollectionExtension.Open(BaseObjs._acadDocs, nameFile, true); dbSrc = docSrc.Database; break; case (int)filestatus.isLocked: //open readonly docSrc = DocumentCollectionExtension.Open(BaseObjs._acadDocs, nameFile, true); dbSrc = docSrc.Database; break; } Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument = docSrc; TypedValue[] tvs = null; switch (option) { case "AREAS": tvs = new TypedValue[5] { new TypedValue((int)DxfCode.Start, RXClass.GetClass(typeof(Polyline)).DxfName), new TypedValue((int)DxfCode.Operator, "<OR"), new TypedValue((int)DxfCode.LayerName, "_XX-*"), new TypedValue((int)DxfCode.LayerName, "YY-*"), new TypedValue((int)DxfCode.Operator, "OR>") }; SelectionSet ss = Select.buildSSet(tvs); ObjectId[] ids = ss.GetObjectIds(); FileManager.transferObjects(ids, dbSrc, dbTar); break; case "TABLE": transferTableData(docSrc, docTar, dbSrc, dbTar); break; } Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument = docTar; switch (status) { case (int)filestatus.isAvailable: case (int)filestatus.isLocked: BaseObjs._closeDoc(docSrc, false); break; default: break; } }
private void method_3(object sender, EventArgs e) { int num; int num4; object obj; try { IL_01: ProjectData.ClearProjectError(); num = -2; IL_09: int num2 = 2; this.Hide(); IL_11: num2 = 3; ListView.SelectedListViewItemCollection selectedItems = this.ListView1.SelectedItems; IL_20: num2 = 4; IEnumerator enumerator = selectedItems.GetEnumerator(); while (enumerator.MoveNext()) { ListViewItem listViewItem = (ListViewItem)enumerator.Current; IL_41: num2 = 5; string text = listViewItem.SubItems[2].Text; IL_55: num2 = 6; DocumentCollectionExtension.Open(Application.DocumentManager, text, false); IL_64: num2 = 7; if (Information.Err().Number > 0) { IL_75: num2 = 8; this.Show(); } else { IL_7F: num2 = 10; IL_82: num2 = 11; this.Close(); } IL_8B: num2 = 13; } if (enumerator is IDisposable) { (enumerator as IDisposable).Dispose(); } IL_AB: goto IL_13E; IL_B0: int num3 = num4 + 1; num4 = 0; @switch(ICSharpCode.Decompiler.ILAst.ILLabel[], num3); IL_F8: goto IL_133; IL_FA: num4 = num2; if (num <= -2) { goto IL_B0; } @switch(ICSharpCode.Decompiler.ILAst.ILLabel[], num); IL_110 :; } catch when(endfilter(obj is Exception & num != 0 & num4 == 0)) { Exception ex = (Exception)obj2; goto IL_FA; } IL_133: throw ProjectData.CreateProjectError(-2146828237); IL_13E: if (num4 != 0) { ProjectData.ClearProjectError(); } }
private void method_0(object sender, KeyEventArgs e) { int num; int num3; object obj; try { IL_01: ProjectData.ClearProjectError(); num = -2; IL_09: int num2 = 2; if (e.KeyCode != Keys.Return) { goto IL_63; } IL_17: num2 = 3; this.Hide(); IL_1F: num2 = 4; string text = this.TextBox1.Text; IL_2D: num2 = 5; DocumentCollectionExtension.Open(Application.DocumentManager, text, false); IL_3C: num2 = 6; if (Information.Err().Number <= 0) { goto IL_57; } IL_4D: num2 = 7; this.Show(); goto IL_63; IL_57: num2 = 9; IL_5A: num2 = 10; this.Close(); IL_63: goto IL_EA; IL_68: goto IL_F4; IL_6D: num3 = num2; if (num <= -2) { goto IL_84; } @switch(ICSharpCode.Decompiler.ILAst.ILLabel[], num); goto IL_C8; IL_84: int num4 = num3 + 1; num3 = 0; @switch(ICSharpCode.Decompiler.ILAst.ILLabel[], num4); IL_C8: goto IL_F4; } catch when(endfilter(obj is Exception & num != 0 & num3 == 0)) { Exception ex = (Exception)obj2; goto IL_6D; } IL_EA: if (num3 != 0) { ProjectData.ClearProjectError(); } return; IL_F4: throw ProjectData.CreateProjectError(-2146828237); }