Now this may seem like a very trivial post, but this was actually a significant problem for my team when preparing the material for the Autodesk Component Technologies presentation we delivered at last year's DevDays tour.
Basically the "type" (or really "sub-type") of a Solid3d (an AcDb3DSolid in ObjectARX) is not exposed through ObjectARX and therefore neither is it exposed through the managed interface. It is possible to get at the information from C++ using the Brep API, but this is currently not available from .NET (and yes, we are aware that many of you would like to see this point addressed, although I can't commit to when it will happen).
But there is some good news: the property is exposed through COM, so we can simply get a COM interface for our solid and query the data through that. Thanks again for Fenton Webb, a member of DevTech Americas, for the tip of using COM rather than worrying about the Brep API.
Here's some C# code demonstrating the technique:
using Autodesk.AutoCAD.Runtime;
using Autodesk.AutoCAD.ApplicationServices;
using Autodesk.AutoCAD.DatabaseServices;
using Autodesk.AutoCAD.EditorInput;
using Autodesk.AutoCAD.Interop.Common;
namespace SolidTest
{
public class Cmds
{
[CommandMethod("GST")]
static public void GetSolidType()
{
Document doc =
Application.DocumentManager.MdiActiveDocument;
Editor ed = doc.Editor;
Database db = doc.Database;
PromptEntityResult per =
ed.GetEntity("\nSelect a 3D solid: ");
if (per.Status == PromptStatus.OK)
{
Transaction tr =
db.TransactionManager.StartTransaction();
using (tr)
{
DBObject obj =
tr.GetObject(per.ObjectId, OpenMode.ForRead);
Solid3d sol = obj as Solid3d;
if (sol != null)
{
Acad3DSolid oSol =
(Acad3DSolid)sol.AcadObject;
ed.WriteMessage(
"\nSolid is of type \"{0}\"",
oSol.SolidType
);
}
tr.Commit();
}
}
}
}
}
And here's what we see when we run the GST command, selecting a number of Solid3d objects, one by one:
Command: GST
Select a 3D solid:
Solid is of type "Box"
Command: GST
Select a 3D solid:
Solid is of type "Sphere"
Command: GST
Select a 3D solid:
Solid is of type "Wedge"
Command: GST
Select a 3D solid:
Solid is of type "Cylinder"
Command: GST
Select a 3D solid:
Solid is of type "Cone"
Command: GST
Select a 3D solid:
Solid is of type "Torus"