Hello,
I am using the RealDWG2015 sdk. I am using it to export into dwg my own representation.
The code is something like:
using (Database db = new Database(true, true)) { using (Transaction tr = db.TransactionManager.StartOpenCloseTransaction()) { // Open the block table. BlockTable bt = (BlockTable)tr.GetObject(db.BlockTableId, OpenMode.ForRead); // Find the model space block and open it for write. ObjectId modelSpace = bt[BlockTableRecord.ModelSpace]; BlockTableRecord table = (BlockTableRecord)tr.GetObject(modelSpace, OpenMode.ForWrite); Traverse(table, tr, db); // HERE I start creating entities tr.Commit(); } db.SaveAs(path, DwgVersion.Newest); }
In the traverse method at some point I create a SubDMesh and add it to the database. Everything works, but if instead of the SubDMesh database I want to create a Solid3D, I am doing:
Solid3d solid = mesh.ConvertToSolid(true, true);
However I always get "eInvalidContext" when calling that method. Is there any reason for this?
Also, What I doing exactly is exporting my solids which are geometries compused of triangles with share vertices, what would be the best entity in this case? solid3D?
Thank you!
Solved! Go to Solution.
Solved by Balaji_Ram. Go to Solution.
You may need to provide more code detail of what you use in your traverse method, maybe it is a complex mesh and cannot be converted into a solid, wrapped into try-catch blocks. HTH
Hello LE3 again,
thank you for your interest in this question. The code is simple, is just this:
SubDMesh mesh = new SubDMesh();
Point3dCollection vertarray = new Point3dCollection();
Int32Collection facearray = new Int32Collection();
// adding points
for (int i = 0; i < allMyPoints.Count; i++)
{
var p = allMyPoints[i];
vertarray.Add(new Point3d(p.X, p.Y, p.Z));
}
// adding triangles
for (int i = 0; i < allMyTriangles.Count; i++)
{
int v1 = allMyTriangles[i * 3];
int v2 = allMyTriangles[i * 3 + 1];
int v3 = allMyTriangles[i * 3 + 2];
facearray.Add(3); // because is a triangle
facearray.Add(v1);
facearray.Add(v2);
facearray.Add(v3);
}
mesh.SetDatabaseDefaults();
mesh.SetSubDMesh(vertarray, facearray, 0);
// following throws eInvalidContext exception
Solid3d solid = mesh.ConvertToSolid(true, true);
At the end what I want is to create a dwg file that shows solids when opening it. I know that with "Face" class it works, but Face class represent just a a single triangle (or quad) without sharing vertices among other faces. SubDMesh class do what I want but when I open the generated dwg file I do not see it as a solid (but lines).
Thank you!
Hello Camilo,
Can you verify if the mesh is not self-intersecting and closed ?
That is the usual cause of this exception.
I would suggest creating the SubDMesh using the same information in AutoCAD and
converting it to a solid using the "CONVTOSOLID" command.
That should provide some hints on what could be wrong with the mesh.
Also try creating a simple box mesh using your code and see if that succeeds in converting it to a solid.
Regards,
Balaji