Hey all,
I've been searching for a few weeks now, but unfortunately haven't been able to find an answer to my question. I'm attempting to hatch an area and detect islands (and not hatch them -- the island will always be MTEXT). I saw
http://www.theswamp.org/index.php?topic=38156.0#lastPost, but it always throws an Exception for me, as has every other similar piece of code I've found. I'm able to get the ObjectId of the MTEXT and the PLINE, but when I try to append the loop to multiple IDs, as follows:
foreach (ObjectId id in ids) //ids is an ObjectIdCollection
{
if (id != ObjectId.Null)
{
acHatch
.AppendLoop(HatchLoopTypes
.Outermost,
new ObjectIdCollection
() { id
}); }
}
I get an "InvalidInput" Exception on the second run of the loop. Here's the code that currently works, except that it hatches through text (coll only ever has 1 ObjectId):
private void AddHatch(Transaction tr, BlockTableRecord acBlkTblRec, MaxHatch hatchCommand, ObjectIdCollection coll)
{
try
{
Hatch acHatch
= new Hatch
(); acHatch.SetDatabaseDefaults();
acHatch.SetHatchPattern(HatchPatternType.PreDefined, hatchCommand.HatchCode);
acHatch.HatchStyle = HatchStyle.Outer;
acHatch.ColorIndex = hatchCommand.HatchColor;
acHatch.PatternAngle = hatchCommand.HatchAngle;
acHatch.PatternScale = hatchCommand.HatchScale;
//have to call SetHatchPattern again due to AutoCAD bug (http://forums.autodesk.com/t5/net/hatch-pattern-scale-problem/td-p/2057211), confirmed on http://adndevblog.typepad.com/autocad/2012/07/hatch-using-the-autocad-net-api.html
acHatch.SetHatchPattern(HatchPatternType.PreDefined, hatchCommand.HatchCode);
acBlkTblRec.AppendEntity(acHatch);
tr.AddNewlyCreatedDBObject(acHatch, true);
acHatch.Associative = true;
acHatch.AppendLoop(HatchLoopTypes.Outermost, coll);
acHatch.EvaluateHatch(true);
}
catch (System.Exception ex)
{
HandleError("AddHatch", ex.Message, false);
}
}
Any ideas?