Message 1 of 22
SendCommand with error "Unhandled Access violation Reading 0xffffffffff ......
Not applicable
01-08-2018
10:58 PM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
I have thousands of dwg file , i wan't open it ,then create a closed line , then get " maptrim" command , then save it . I operate one by one.
I run my code , i get the error "Unhandled Access violation Reading Oxffffffff Exception at e9e1460bh" when I get about the fifith file
i use the AutoCAD Map 2015+ .net + com
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Autodesk.AutoCAD.ApplicationServices;
using Autodesk.AutoCAD.EditorInput;
using Autodesk.AutoCAD.Runtime;
using Autodesk.AutoCAD.DatabaseServices;
using Autodesk.AutoCAD.Geometry;
using Autodesk.Gis.Map.Platform.Utils;
using AutoCAD;
AcadApplication app = Application.AcadApplication as AcadApplication; if (!System.IO.File.Exists(@"C:\template500.dwg")) { Util.PrintLn("\n template is not exsit : C:\\template500.dwg"); return "err"; } Document DOC = Application.DocumentManager.Open(@"C:\template500.dwg", false); List<string> LstFiles = new List<string>(); List<string> LstCode = GetTuFuNumber.GetTuFuNum(MapCode); for (int i = 0; i < LstCode.Count; i++) { if (System.IO.File.Exists(Path + "\\" + LstCode[i] + ".dwg")) { LstFiles.Add(Path + "\\" + LstCode[i] + ".dwg"); } } string s = ""; for (int k = 0; k < LstFiles.Count; k++) { s += LstFiles[k] + ","; } //********load the file and connected file Database destDb = DOC.Database; using (DocumentLock docLock1 = DOC.LockDocument()) { for (int i = 0; i < LstFiles.Count; i++) { Database sourceDb = new Database(false, true); sourceDb.ReadDwgFile(LstFiles[i], System.IO.FileShare.Read, false, null); var SourceObjectIds = new ObjectIdCollection(); Autodesk.AutoCAD.DatabaseServices.TransactionManager SourceTm = sourceDb.TransactionManager; using (Transaction trans = destDb.TransactionManager.StartTransaction()) { var blockTable = (BlockTable)trans.GetObject(destDb.BlockTableId, OpenMode.ForRead); using (Transaction extTrans = sourceDb.TransactionManager.StartTransaction()) { dynamic extBlockTable = (BlockTable)extTrans.GetObject(sourceDb.BlockTableId, OpenMode.ForRead); dynamic extModelSpace = (BlockTableRecord)extTrans.GetObject(extBlockTable[BlockTableRecord.ModelSpace], OpenMode.ForRead); foreach (ObjectId id in extModelSpace) { SourceObjectIds.Add(id); } } sourceDb.CloseInput(true); dynamic idmapping = new IdMapping(); // destDb.WblockCloneObjects(SourceObjectIds, destDb.BlockTableId, idmapping, DuplicateRecordCloning.Replace, false); destDb.WblockCloneObjects(SourceObjectIds, blockTable[BlockTableRecord.ModelSpace], idmapping, DuplicateRecordCloning.Replace, false); trans.Commit(); } } } CWriteLog.Msg(targetPath, "finish load file "); Util.PrintLn("create polyline......."); app.ActiveDocument.SendCommand("filedia 0 \n"); Polyline line = getLine(MapCode); //**** add the polyline to modespace using (DOC.LockDocument()) { ObjectId entityID; using (var tr = DOC.TransactionManager.StartTransaction()) { var modelspace = (BlockTableRecord)tr.GetObject(SymbolUtilityServices.GetBlockModelSpaceId(DOC.Database), OpenMode.ForWrite); // Circle circ = new Circle(Point3d.Origin, Vector3d.ZAxis, 100.0); entityID = modelspace.AppendEntity(line); tr.AddNewlyCreatedDBObject(line, true); tr.Commit(); } //**************begion to maptrim Util.PrintLn("begion to maptrim "); CWriteLog.Msg(targetPath, "begin to maptrim "); app.ActiveDocument.SendCommand("_.MAPTRIM\nS\nlast\nN\nN\nO\nY\nN\nR\nY\n\n"); CWriteLog.Msg(targetPath, " finish maptrim "); Util.PrintLn("finish maptrim "); CWriteLog.Msg(targetPath, "delete polyline "); DeleleEnity(entityID); CWriteLog.Msg(targetPath, "save ......."); string saveFolder = targetPath + "\\" + "outPut"; if (!System.IO.Directory.Exists(saveFolder)) { System.IO.Directory.CreateDirectory(saveFolder); } string filename = saveFolder + "\\" + MapCode + ".dwg"; ; app.ActiveDocument.SendCommand("_.SAVEAS\n2004\n" + filename + "\nY\n\n");
everytime I get the error at "
app.ActiveDocument.SendCommand("_.MAPTRIM\nS\nlast\nN\nN\nO\nY\nN\nR\nY\n\n");"
