Hi,
Thanks. I tried to find the equivalent code in C#, but I don't know is it true or not.
By the way, it doesn't work:
// hatchMainId: Id of the main Polyline
hat.AppendLoop(HatchLoopTypes.External, hatchMainId);
// hatchIslandIds: Id of the island(s):
hat.AppendLoop(HatchLoopTypes.Default, hatchIslandIds);
My entire code is like this:
Document doc = Application.DocumentManager.MdiActiveDocument;
Editor ed = doc.Editor;
//...
DBObjectCollection objsAll = ed.TraceBoundary(ppr.Value, true);
ObjectIdCollection ids
= new ObjectIdCollection
();
foreach (DBObject obj in objsAll)
{
Entity ent = obj as Entity;
if (ent != null)
{
ids.Add(obj.Id);
}
}
hat.SetDatabaseDefaults();
ObjectId hatId = btr.AppendEntity(hat);
tr.AddNewlyCreatedDBObject(hat, true);
hat.Associative = true;
hat.HatchStyle = HatchStyle.Normal;
// hatchMainId: Id of the main Polyline
hat.AppendLoop(HatchLoopTypes.External, hatchMainId);
// hatchIslandIds: Id of the island(s):
hat.AppendLoop(HatchLoopTypes.Default, hatchIslandIds);
hat.EvaluateHatch(true);
The result was the same as my first code.
A couple of mistakes I found in your code:
1. since you want to add hatchloop with one of the overloaded AppendLoop() with ObjectIdCollection as second input, it means the entity or entities must be database residing (hence you can have their IDs).
in your original post, you use TraceBoundary() to get a DBObjectCollection back, which are NON-DATABASE-RESIDING objects created by TraceBoundary() call. Thus, the ObjectIdCollections your code created from these DBObjects only contains null ObjectIds, thus the island were not created (but I am not sure how you had the external boundary created).
2. from the method name AppendLoop(), it implies it only appends ONE LOOP AT A TIME. If the input ObjectIdCollection has multiple OBjectIds, these entities should only form a SINGLE LOOP. It means you do not add all the island entities' IDs in one AppendLoop() call. You should add one island at a time:
for (var islandId in islandIds)
{
theHatch.AppendLoop(xxxxx.Default, new ObjectIdCollection(new[]{ id}));
}
Because you want to use TraceBoundary() to find boundary and islands, after you get the DBObjectCollection, you would do with one the 2 ways:
1. Add all the DBObjects into the database first, then create the hatch and append them as loop one at a time. But this way, you would have duplicated entities of the existing ones;
2. Find matched db-residing, existing entities for each of the DBObjects and use the existing ones as the hatch's boundary/islands, to avoid geometrical duplicates in database.