When using the GetSlice method of the Solid3d class and setting the
negativeHalfToo to false I get the following exception, "Operation is not
valid due to the current state of the object.", but if I set it to true It
works as expected. What am I doing wrong?
[CommandMethod("GetMySlice")]
static public void GetMySlice()
{
Database db = HostApplicationServices.WorkingDatabase;
Transaction myT = db.TransactionManager.StartTransaction(); //begin the
transaction
Editor ed =
Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument.Editor;
try
{
//use sphere command and create sphere at 0,0,0 any radius manually
PromptEntityOptions prEnt = new PromptEntityOptions("\nPlease select a Solid
entity: ");
PromptEntityResult prEntRes = ed.GetEntity(prEnt);
if( prEntRes.Status == PromptStatus.OK)
{
Entity selectedEntity = (Entity)myT.GetObject(prEntRes.ObjectId,
OpenMode.ForWrite);
Solid3d MySolid = (Solid3d)selectedEntity;
Plane CutPlane = new Plane(new Point3d(0.0,0.0,0.0),new
Vector3d(0.0,1.0,0.0));
MySolid.GetSlice(CutPlane, false); //OK comment this out and use lines
below, no error checking as just testing
// Solid3d OtherHalf = MySolid.GetSlice(CutPlane, true);
// BlockTable bt = (BlockTable)myT.GetObject(db.BlockTableId,
OpenMode.ForRead, false);
// BlockTableRecord btr =
(BlockTableRecord)myT.GetObject(bt[BlockTableRecord.ModelSpace],
OpenMode.ForWrite, false);
// btr.AppendEntity(OtherHalf);
// myT.AddNewlyCreatedDBObject(OtherHalf, true);
myT.Commit();
}
}
catch ( System.Exception e )
{
ed.WriteMessage("Error: " + e.Message);
}
finally
{
myT.Dispose();
}
}
Laurence