Message 1 of 5
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
I want to save a lot of data in DWG via XRecord but when making the ResultBuffer for it, it is very slow.
Here is a sample code for the ResultBuffer:
public static void SaveSurfaceDataToDictionary(string dictName) { ResultBuffer resultBuffer = new ResultBuffer(); foreach (long objectHandle in Lisp.plineHandleList) //List length = 59260 { resultBuffer.Add(new TypedValue((int)DxfCode.Handle, objectHandle)); } SetXrecord(dictName, "ObjectHandleList", resultBuffer); resultBuffer = new ResultBuffer(); foreach (TriangleNet.Geometry.Vertex v in Lisp.polygonList.Points) //List length = 22766 { resultBuffer.Add(new TypedValue((int)DxfCode.UcsOrg, new Point3d(v.X, v.Y, v.Z))); } SetXrecord(dictName, "PolygonPointsList", resultBuffer); resultBuffer = new ResultBuffer(); List<ISegment> segmentList = Lisp.polygonList.Segments; foreach (Segment segment in segmentList) //List length = 17022 { TriangleNet.Geometry.Vertex v; v = segment.GetVertex(0); resultBuffer.Add(new TypedValue((int)DxfCode.UcsOrg, new Point3d(v.X, v.Y, v.Z))); v = segment.GetVertex(1); resultBuffer.Add(new TypedValue((int)DxfCode.UcsOrg, new Point3d(v.X, v.Y, v.Z))); } SetXrecord(dictName, "PolygonSegmentsList", resultBuffer); }
public static void SetXrecord(string dictName, string key, ResultBuffer resbuf) { Document doc = Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument; Database db = doc.Database; using (Transaction tr = db.TransactionManager.StartTransaction()) { DBDictionary NOD = (DBDictionary)tr.GetObject(db.NamedObjectsDictionaryId, OpenMode.ForRead); DBDictionary dict; if (NOD.Contains(dictName)) { dict = (DBDictionary)tr.GetObject(NOD.GetAt(dictName), OpenMode.ForWrite); } else { dict = new DBDictionary(); NOD.UpgradeOpen(); NOD.SetAt(dictName, dict); tr.AddNewlyCreatedDBObject(dict, true); } Xrecord xRec = new Xrecord(); xRec.Data = resbuf; dict.SetAt(key, xRec); tr.AddNewlyCreatedDBObject(xRec, true); tr.Commit(); } }
The ResultBuffer operation takes 12 seconds. Way to slow.
Any idea or alternative for this?
I want to keep my data in DWG database.
Solved! Go to Solution.