Message 1 of 27
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
Hi,
I am trying to open some AutoCAD file from a Location. After that in the newly opened file added a circle as required. Finally, Close the drawing file with save the newly drawing files.
Actually an error message shown that "Drawing is busy (COMException was caught)".
I have search so many link where discussed about the same. Whereas I am confuse which one the concrete solution for this type of coding.
Here is my Code please help!!
[CommandMethod("OPSV",CommandFlags.Session)] public static void OpenSaveDwgFiles() { Document doc = Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument; Database db = doc.Database; try { var path = @"C:\TestBack\"; string dwgFlpath = string.Empty; DirectoryInfo d = new DirectoryInfo(path); FileInfo[] Files = d.GetFiles("*.dwg"); //string str = ""; foreach (FileInfo file in Files) { DocumentCollection docMgr = Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager; var fileName = Path.GetFileName(file.FullName); dwgFlpath = path+fileName; DocumentCollectionExtension.Open(docMgr, dwgFlpath,false); using (DocumentLock LckDoc = doc.LockDocument()) { using (Transaction tr = db.TransactionManager.StartTransaction()) { BlockTable bt = tr.GetObject(db.BlockTableId, OpenMode.ForRead) as BlockTable; BlockTableRecord btr = tr.GetObject(bt[BlockTableRecord.ModelSpace], OpenMode.ForWrite) as BlockTableRecord; using (Circle crcl = new Circle()) { crcl.Center = new Point3d(1, 1, 0); crcl.Radius = 2; btr.AppendEntity(crcl); tr.AddNewlyCreatedDBObject(crcl, true); } tr.Commit(); } } //doc.CloseAndDiscard(); doc.CloseAndSave(dwgFlpath.Substring(0,dwgFlpath.Length-4)); } } catch (System.Exception ex) { Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument.Editor.WriteMessage(ex.ToString()); } }
Thanks
Solved! Go to Solution.