Message 1 of 5

Not applicable
07-12-2016
02:55 AM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
Hi,
I have a door in a dwg file and using AutoCAD I would like to export all it's vertices. For now it exports just the extrude geometry. I would use an export tool but it's essential I get the layer name as well as the points in the same object.
The type of objects I retrieve are either: Solid3d, ExtrudedSurface, Line. But I am only interested in Solid3d.
The code is below.
Regards,
Ioan
[CommandMethod("EXPORTVERTICES")] public static void ThreeDocumentToFile() { var doc = Application.DocumentManager.MdiActiveDocument; // If we didn't find a document, return if (doc == null) return; // We could probably get away without locking the document // - as we only need to read - but it's good practice to // do it anyway using (var dl = doc.LockDocument()) { var db = doc.Database; var ed = doc.Editor; // Capture our Extents3d objects in a list var sols = new List<DataMe>(); using (var tr = doc.TransactionManager.StartTransaction()) { // Start by getting the modelspace var ms = (BlockTableRecord)tr.GetObject( SymbolUtilityServices.GetBlockModelSpaceId(db), OpenMode.ForRead ); // Get each Solid3d in modelspace and add its extents // to the list foreach (var id in ms) { var obj = tr.GetObject(id, OpenMode.ForRead); var sol = obj as Solid3d; DataMe dataMe = new DataMe(); if (sol != null) { dataMe.extents = sol.GeometricExtents; dataMe.layer = sol.Layer; } var pl = obj as Polyline; if (pl != null) { Point3dCollection lst = new Point3dCollection(); int pts = pl.NumberOfVertices; //ed.WriteMessage("\nNumber of params : " + (pts + 1).ToString()); for (int i = 0; i < (pts); i++) { lst.Add(pl.GetPointAtParameter(i)); } foreach (Point3d p in lst) { //ed.WriteMessage("\nPoint :" + p.ToString()); dataMe.points.Add(p); } } sols.Add(dataMe); } tr.Commit(); } string output = GetSolidsString(sols); SaveFileDialog saveFileDialog1 = new SaveFileDialog("Save to json", "door.json", "json", "Save", SaveFileDialog.SaveFileDialogFlags.AllowAnyExtension); if (saveFileDialog1.ShowDialog() == System.Windows.Forms.DialogResult.OK) { System.IO.File.WriteAllText(saveFileDialog1.Filename, output); } } }
Solved! Go to Solution.