Creating hatch on different layered geometry
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
Hello forum,
I want to create hatch for the following images. Manually I can create hatch as expected as seen in the following image.
I want to achieve same using api. I have implemented code as below
public void FilterSelectionSet1()
{
Document acDoc = aCAD_App.DocumentManager.MdiActiveDocument;
Database acCurDb = acDoc.Database;
Editor acDocEd = aCAD_App.DocumentManager.MdiActiveDocument.Editor;
Polyline rect = new Polyline();
TypedValue[] acTypValAr = new TypedValue[] { new TypedValue(Convert.ToInt32(DxfCode.Start), "POLYLINE") };
PromptSelectionResult acSSPrompt;
acSSPrompt = acDocEd.SelectAll();
using (Transaction acTrans = acCurDb.TransactionManager.StartTransaction())
{
if (acSSPrompt.Status == PromptStatus.OK)
{
SelectionSet acSSet = acSSPrompt.Value;
BlockTable acBlkTbl;
acBlkTbl = acTrans.GetObject(acCurDb.BlockTableId, OpenMode.ForRead) as BlockTable;
BlockTableRecord acBlkTblRec;
acBlkTblRec = acTrans.GetObject(acBlkTbl[BlockTableRecord.ModelSpace], OpenMode.ForWrite) as BlockTableRecord;
foreach (SelectedObject acSSObj in acSSet)
{
Entity acEnt = acTrans.GetObject(acSSObj.ObjectId, OpenMode.ForWrite) as Entity;
if (acEnt != null)
{
string entLayer = acEnt.Layer;
if (entLayer == "Revit-Profile Location")
{
rect = acEnt as Polyline;
}
}
}
int verticesCount = rect.NumberOfVertices;
for (int i = 0; i < verticesCount; i++)
{
Point2d pt = rect.GetPoint2dAt(i);
}
Hatch acHatch = new Hatch();
acBlkTblRec.AppendEntity(acHatch);
acTrans.AddNewlyCreatedDBObject(acHatch, true);
ObjectIdCollection objectIdCollection = new ObjectIdCollection();
objectIdCollection.Add(rect.ObjectId);
acHatch.SetDatabaseDefaults();
acHatch.SetHatchPattern(HatchPatternType.PreDefined, "ANSI31");
acHatch.Associative = true;
acHatch.AppendLoop(HatchLoopTypes.Outermost, objectIdCollection);
acHatch.PatternScale = 0.5;
acHatch.HatchStyle = HatchStyle.Outer; // tried HatchStyle.normal and ignore also ignore throws exception
acHatch.EvaluateHatch(true);
}
else
{
aCAD_App.ShowAlertDialog("Number of objects selected: 0");
}
acTrans.Commit();
}
}
But I am getting result as,
Please note that, inner geometry that is triangular shaped is on a different layer called "Pdf_Geometry" and outer rectangle is on other layer "Pdf_geom location".
Please help me to achieve the output I want.
Thank you in advance.