/// <summary>
/// Trying to get section (Solid3d.GetSection) and extrude (Solid3d.Extrude)
/// </summary>
[CommandMethod("TestGetSection")]
public void TestGetSection()
{
// Put your command code here
Document doc = Application.DocumentManager.MdiActiveDocument;
if (doc == null)
return;
Editor ed = doc.Editor;
Database db = doc.Database;
PromptEntityOptions prEnt = new PromptEntityOptions("\nSelect Solid3d: ");
prEnt.SetRejectMessage("It is not a Solid3d");
prEnt.AddAllowedClass(typeof(Solid3d), true);
PromptEntityResult rsEnt = ed.GetEntity(prEnt);
if (rsEnt.Status != PromptStatus.OK)
return;
// Vertical plane with origin point (0,20,0)
Plane plane = new Plane(new Point3d(0, 20, 0), Vector3d.YAxis);
using (Transaction tr = doc.TransactionManager.StartOpenCloseTransaction())
{
try {
BlockTableRecord btr =
tr.GetObject(db.CurrentSpaceId, OpenMode.ForWrite) as BlockTableRecord;
Solid3d sol = tr.GetObject(rsEnt.ObjectId, OpenMode.ForWrite) as Solid3d;
Region reg = sol.GetSection(plane);
DBObjectCollection col = new DBObjectCollection();
reg.Explode(col);
//
// Если расчленяется на Region'ы, то будем выдавливать их поотдельности
//
if (col.Count > 0 && col[0] is Region)
{
foreach (DBObject obj in col)
{
if (obj is Region)
{
btr.AppendEntity(obj as Region);
tr.AddNewlyCreatedDBObject(obj, true);
}
}
} else {
col.Clear();
col.Add(reg);
btr.AppendEntity(reg);
tr.AddNewlyCreatedDBObject(reg, true);
}
Solid3d solColExt = new Solid3d();
foreach (DBObject obj in col) {
Solid3d solExt = new Solid3d();
solExt.Extrude(obj as Region, 1, 0);
btr.AppendEntity(solExt);
tr.AddNewlyCreatedDBObject(solExt, true);
solColExt.BooleanOperation(BooleanOperationType.BoolUnite, solExt);
}
btr.AppendEntity(solColExt);
tr.AddNewlyCreatedDBObject(solColExt, true);
}
finally {
tr.Commit();
}
}
}