Well, I see this hatch is adjanced and associative,
one possiible way is to perform command twice, I'm pretty
sure there is other way to do the job, but I don't know how yet
[CommandMethod("ehatch")]
public void eraseHatch()
{
Document doc = Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument;
Editor ed = doc.Editor;
Database db = doc.Database;
Point3d p1; Point3d p2;
try
{
using (Transaction tr = db.TransactionManager.StartTransaction())
{
//------------------------------------------------------------------
// Create filter object, this filter can have any types to select, i.e. lines
SelectionFilter filter = new SelectionFilter(new TypedValue[] { new TypedValue(0, "lwpolyline"), new TypedValue(70, 1) });
// Select lines on screen
PromptSelectionResult psr = ed.GetSelection(filter);
// Check if selection is succeed
if (psr.Status != PromptStatus.OK) return;
// if OK then iterate trough selected lines
foreach (SelectedObject selobj in psr.Value)
{
// Cast SelectedObject as DBObject (or as an Entity)
DBObject obj = tr.GetObject(selobj.ObjectId, OpenMode.ForRead) as DBObject;
if (obj != null)
{
// Cast DBObject as Polyline
Polyline pline = obj as Polyline;
p1 = pline.GetPoint3dAt(0);
p2 = pline.GetPoint3dAt(1);
Point3dCollection pts = new Point3dCollection();
pts.Add(p1);
pts.Add(p2);
// select hatch by fence
filter = new SelectionFilter(new TypedValue[] { new TypedValue(0, "hatch") });
psr = ed.SelectFence(pts, filter);
SelectionSet hset = psr.Value;
ObjectId[] ids = hset.GetObjectIds();
ObjectId hid = ids[0];
DBObject hobj = tr.GetObject(hid, OpenMode.ForRead) as DBObject;
Hatch inhatch = hobj as Hatch;
doc.TransactionManager.EnableGraphicsFlush(true);
inhatch.UpgradeOpen();
if (inhatch.Associative)
{
Autodesk.AutoCAD.ApplicationServices.Application.ShowAlertDialog("Perform command \"ehatch\" twice");
pline.UpgradeOpen();
inhatch.Associative = false;
inhatch.RemoveAssociatedObjectIds();
inhatch.EvaluateHatch(true);
inhatch.RecordGraphicsModified(true);
tr.TransactionManager.QueueForGraphicsFlush();
}
ed.Regen();
inhatch.Erase();
}
}
doc.TransactionManager.FlushGraphics();
tr.Commit();
}
}
catch (Autodesk.AutoCAD.Runtime.Exception ex)
{
Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument.Editor.WriteMessage
(ex.Message + "\n" + ex.StackTrace);
}
finally
{
}
}
~'J'~
_____________________________________
C6309D9E0751D165D0934D0621DFF27919