public void TraceBoundaryAndHatch()
{
Document doc = Application.DocumentManager.MdiActiveDocument;
Database db = doc.Database;
Editor ed = doc.Editor;
bool ContinueHatch = true;
using (DocumentLock acLckDoc = doc.LockDocument())
{
Autodesk.AutoCAD.Internal.Utils.SetFocusToDwgView();
while (ContinueHatch)
{
PromptPointResult ppr = ed.GetPoint("\nSelect internal point: ");
if (ppr.Status != PromptStatus.OK) ContinueHatch = false;
if (ContinueHatch)
{
DBObjectCollection objs = ed.TraceBoundary(ppr.Value, true);
if (objs.Count == 0) return;
using (Transaction tr = doc.TransactionManager.StartTransaction())
{
BlockTable blockTable = tr.GetObject(db.BlockTableId, OpenMode.ForRead) as BlockTable;
BlockTableRecord MSrecord = tr.GetObject(blockTable[BlockTableRecord.ModelSpace], OpenMode.ForWrite) as BlockTableRecord;
using (Hatch hat
= new Hatch
()) {
MSrecord.AppendEntity(hat);
tr.AddNewlyCreatedDBObject(hat, true);
hat.HatchStyle = HatchStyle.Outer;
hat.SetDatabaseDefaults();
hat.Color = color;
hat.SetHatchPattern(HatchPatternType.PreDefined, "SOLID");
hat.DowngradeOpen();
hat.Associative = true;
foreach (DBObject obj in objs)
{
Curve c = obj as Curve;
if (c != null)
{
ObjectId curveId = MSrecord.AppendEntity(c);
tr.AddNewlyCreatedDBObject(c, true);
hat
.AppendLoop(HatchLoopTypes
.Default,
new ObjectIdCollection
() { curveId
}); }
}
}
tr.Commit();
}
}
}
}
}