by Fenton Webb
After sweating over some Hatch creation code, I thought I better share with you guys how I solved it.
Here’s what I wanted Hatched:
The way I made it work was, to first get all of the boundary geometry as Polylines using the Editor.TraceBoundary function.
This gave me an array of 3 Polylines, shown in red e.g.
Next, I add the polylines to the Database (temporarily) so that the Hatch object can process them (outside of any Transaction) – sorry VB ![]()
dim loopObjectIds = new ObjectIdCollection() Dim db As Database = Application.DocumentManager.MdiActiveDocument.Database ' add the loop objects to the dwg For Each polyline As Polyline In loopObjects Using curSpace As BlockTableRecord = db.CurrentSpaceId.Open(OpenMode.ForWrite) loopObjectIds.Add(curSpace.AppendEntity(polyline)) ' make sure to close the polyline polyline.Close() End Using Next
Now append each polyline obtained by the trace as a separate loop e.g.
For Each objectId In loopObjectIds
Dim ids = New ObjectIdCollection()
ids.Add(objectId)
acHatch.AppendLoop(HatchLoopTypes.Outermost, ids)
Next
acHatch.EvaluateHatch(True)
That’s it!!
Also, here are the different results obtained by setting the Hatch.HatchStyle to:
HatchStyle.Ignore results in this:
HatchStyle.Outer results in this:
HatchStyle.Normal
results in this:
<p>For the record, I could have used the appendLoop function which takes a Curve2dCollection, however I didn’t on this occasion because I didn’t know that we have equivalent .NET functions to these C++ versions…</p> <p><strong>acdbConvertAcDbCurveToGelibCurve <br />acdbConvertGelibCurveToAcDbCurve <br />acdbAssignGelibCurveToAcDbCurve</strong></p> <p>in .NET</p> <p><strong>CreateFromGeCurve</strong></p> <p><strong>SetFromGeCurve</strong>






Leave a Reply