Table of Contents

Class DxfHatch

Namespace
GeometryHelper.Dxf
Assembly
GeometryHelper.dll

A HATCH of a DXF file, as AutoCAD's Hatch: an area closed by loops in the plane of its Normal at its Elevation, filled solid, with a pattern of lines or with a gradient of colours.

public sealed class DxfHatch : DxfEntity
Inheritance
DxfHatch
Inherited Members

Remarks

A square 30 by 20 with a circle of radius 5 inside it, filled with ANSI31 in the Normal style, has two loops and Area 600 less 78.54, 521.46; read from a file AutoCAD wrote, its pattern holds the one line of ANSI31 (GetPatternDefinitionAt(int)), at 45 degrees and 3.175 apart, where the same made in code holds none, as the next paragraph says. The loops are given in the world as the library's shapes (GetLoopAt(int)); the file holds them in the system of the normal, as AutoCAD's GetLoopAt gives them.

Each property is read from and written to the HATCH's own groups, every group a change is not about keeping its text, and a property given the value it has changes nothing. A change to the loops of an associative HATCH (Associative) takes its association away with the handles of the objects it followed, as AutoCAD's does: its loops are its own from then on. A copy (Clone()) follows nothing; one copied with every object it follows by WblockCloneObjects(IEnumerable<DxfEntity>, DxfBlockTableRecord) follows their copies. The lines a pattern draws are worked out by AutoCAD from the pattern and the loops (EvaluateHatch), and are not in the file; Explode() works them out as ezdxf draws them, and GetHatchLinesData() gives them as lines in the plane. A pattern of AutoCAD's own pattern file the HATCH does not hold the lines of is not known to the library: new DxfHatch() given ANSI31 by SetHatchPattern(DxfHatchPatternType, string) holds no lines of it (NumberOfPatternDefinitions 0), its name and type written for AutoCAD to take the lines from its own file; unless the drawing's PatternSearchPath finds it in the caller's own pattern files, which give it its lines as AutoCAD gives them: ANSI31 of acadiso.pat, the one line at 45 degrees 3.175 apart.

A file older than R2000 has no HATCH: AppendEntity(DxfEntity) refuses one there, and a gradient needs R2004 (AC1018). A HATCH copied into a drawing of another version is written as that version writes it, as AutoCAD's SAVEAS writes it: each spline edge's count of fit points (97) as InsertLoopAt(int, DxfHatchLoop) says, and its gradient taken out in a drawing before R2004, the HATCH left filled solid.

Constructors

DxfHatch()

Initializes a HATCH of no loops, filled solid, on the floor, as AutoCAD's new Hatch(), on layer 0 in no file; give it its pattern with SetHatchPattern(DxfHatchPatternType, string) and its loops with AppendLoop(DxfHatchLoop).

Properties

Area

Gets the area the HATCH fills, as AutoCAD's Area: that of each loop, worked out exactly on its lines, arcs, ellipses and splines (a spline by Gauss's rule, sixteen points to each span of its knots), added or taken off by how deep the loop lies among the others and the HatchStyle: in the normal style every other one, from the outermost in; in the outer style the outermost less those just inside them; ignoring islands, the outermost alone. A square 30 by 20 round a circle of radius 5 fills 521.46 in the normal style.

Associative

Gets or sets whether the HATCH follows the objects its loops were made of (group 71), as AutoCAD's Associative: their handles are in its loops (groups 330), and AutoCAD makes its loops anew when they change.

BackgroundColor

Gets or sets the colour behind the pattern, as AutoCAD's BackgroundColor: from the extended data of the application HATCHBACKGROUNDCOLOR (1071), as AutoCAD and ezdxf write it; none where the HATCH has none.

Elevation

Gets or sets how far the plane of the HATCH stands from the origin along its normal, as AutoCAD's Elevation: the z of its point of elevation (group 30); nought where the record gives none.

GeometricExtents

Gets the box the loops of the HATCH fill, as AutoCAD's GeometricExtents: the least and greatest x, y and z of their lines, arcs, ellipses and splines in the world, as GetLoopAt(int) gives them; a square 30 by 20 round a circle gives the square's.

GradientAngle

Gets or sets the angle of the gradient (group 460), as AutoCAD's GradientAngle: in radians, nought where the record gives none.

GradientName

Gets the name of the gradient (group 470), as AutoCAD's GradientName: LINEAR, SPHERICAL; empty where the HATCH has no gradient data.

GradientOneColorMode

Gets or sets whether the gradient runs from one colour to its tint (group 452 of 1), as AutoCAD's GradientOneColorMode, rather than between two colours; false where the record gives none.

GradientShift

Gets or sets how far the gradient is shifted from its middle (group 461), as AutoCAD's GradientShift: nought for a gradient centred, 1 for one shifted all the way; nought where the record gives none.

GradientType

Gets where the gradient comes from, as AutoCAD's GradientType: one of AutoCAD's nine by its name (group 470), UserDefinedGradient for any other name.

HatchObjectType

Gets or sets whether the HATCH is filled with a pattern or a gradient (group 450), as AutoCAD's HatchObjectType; HatchObject where the record gives none.

HatchStyle

Gets or sets which areas the loops close are filled (group 75), as AutoCAD's HatchStyle; Normal where the record gives none.

IsGradient

Gets whether the HATCH is filled with a gradient (group 450 of 1), as AutoCAD's IsGradient.

IsHatch

Gets whether the HATCH is filled with a pattern, solid fill among them, not a gradient, as AutoCAD's IsHatch.

IsSolidFill

Gets whether the HATCH is filled solid (group 70 of 1), as AutoCAD's IsSolidFill: a gradient is filled solid too.

Normal

Gets or sets the normal of the plane of the HATCH (groups 210, 220, 230), as AutoCAD's Normal: of unit length, (0, 0, 1) where the record gives none.

NumSeedPoints

Gets how many seed points the HATCH has (group 98), as ObjectARX's numSeedPoints: the points inside its areas AutoCAD found the loops from.

NumberOfHatchLines

Gets how many lines the pattern draws, as AutoCAD's NumberOfHatchLines: each dash and dot of each pattern line cut by the loops, as Explode() draws them; nought for a solid fill and a gradient. A square 30 by 20 filled with a pattern made by the user of lines at 45 degrees 3.175 apart, as ANSI31's, draws 11; the same round a circle of radius 5 about its middle in the normal style draws 14. They are worked out when first asked for and kept while the HATCH is not changed, so that asking for them line by line takes no longer than asking for all of them; kept, they take 32 bytes a line, 32 MB for a million, for as long as the HATCH's object is held.

NumberOfLoops

Gets how many loops the HATCH has, as AutoCAD's NumberOfLoops: the paths after its group 91.

NumberOfPatternDefinitions

Gets how many lines the pattern has (group 78), as AutoCAD's NumberOfPatternDefinitions: nought for a solid fill.

PatternAngle

Gets or sets the angle of the pattern (group 52, in degrees), as AutoCAD's PatternAngle: in radians, nought where the record gives none.

PatternDouble

Gets or sets whether the lines of a pattern made by the user are crossed by as many again square to them (group 77), as AutoCAD's PatternDouble; false where the record gives none.

PatternName

Gets the name of the pattern (group 2), as AutoCAD's PatternName: SOLID for a solid fill, ANSI31, _USER for one made by the user; SOLID where the record gives none. It is set by SetHatchPattern(DxfHatchPatternType, string).

PatternScale

Gets or sets the scale of a pattern of a pattern file (group 41), as AutoCAD's PatternScale: 2 draws ANSI31's lines twice as far apart; 1 where the record gives none, and for a pattern made by the user, whose group 41 is its spacing (PatternSpace).

PatternSpace

Gets or sets the spacing of the lines of a pattern made by the user (group 41), as AutoCAD's PatternSpace; 1 where the record gives none, and for a pattern of a pattern file, whose group 41 is its scale.

PatternType

Gets where the pattern comes from (group 76), as AutoCAD's PatternType; PreDefined where the record gives none. It is set by SetHatchPattern(DxfHatchPatternType, string).

ShadeTintValue

Gets or sets how the colour of a gradient of one colour is tinted (group 462), as AutoCAD's ShadeTintValue: from nought, dark, to 1, light; nought where the record gives none. Set on a gradient of two colours in one-colour mode (GradientOneColorMode), it also makes the second colour the tint of the first, as AutoCAD 2021 does each time it is set, the same value again too: red at 0 and green at 1, the tint set to 0.3, read back as red and (153, 0, 0), a true colour at the value the second colour had. The colours of a gradient of two colours in two-colour mode, and a gradient of one colour only, are not touched.

Methods

AppendLoop(DxfHatchLoop)

Adds a loop after the others, as AutoCAD's AppendLoop of a HatchLoop: written as InsertLoopAt(int, DxfHatchLoop) writes one.

AppendLoop(DxfHatchLoopTypes, IReadOnlyList<GeoPoint2>, IReadOnlyList<double>)

Adds a loop of a polyline after the others, as AutoCAD's AppendLoop of vertices and bulges: in the system of the normal, as given, closed, its type with Polyline. A HATCH that was associative is so no longer, as InsertLoopAt(int, DxfHatchLoop) says.

AppendSeedPoint(GeoPoint2)

Adds a seed point after the others, in the system of the normal, as ObjectARX's appendSeedPoint; its count written anew.

EvaluateGradientColorAt(float)

Gets the colour of the gradient at a value along it, as AutoCAD 2021's EvaluateGradientColorAt gives it (1 101 channels of 12 gradients, in steps of 1/100 and 1/32, were read from it and agree): the red, green and blue of its colours (GetGradientColors()) taken in proportion between the two whose values the value lies between, each cut down to a whole number (not rounded); before the first colour the first, past the last the last. Blue (0, 0, 255) at 0 to a pale yellow (255, 255, 153) at 1, AutoCAD's new gradient, is (127, 127, 204) at 0.5. A gradient of one colour that holds only that colour (GradientOneColorMode) runs from it to its shade or tint by the ShadeTintValue, placed at the end of the gradient away from the colour (at 1, or at 0 where the colour stands past the middle): the colour's hue and saturation at the lightness the value is, so that red at 0.25 runs to (128, 0, 0) and (100, 150, 50) at 0.75 to (191, 223, 159); a grey of 128 goes to black at 0 and white at 1. A gradient that holds two colours runs between them in either mode; the second colour of one of one colour is made by setting the tint (ShadeTintValue), as AutoCAD makes it. The colours are read from the HATCH each time and nothing is changed.

EvaluateHatch(bool)

Works out the lines of the pattern, as AutoCAD's EvaluateHatch works them out: those Explode() draws, as GetHatchLinesData() gives them, kept for the queries of the lines while the HATCH is not changed. A solid fill and a gradient have none. The library counts the lines it lays, so the estimate AutoCAD can be asked to make of their number first, low or not, changes nothing here.

Explode()

Gets the lines a HATCH filled with a pattern breaks into, as AutoCAD's EXPLODE breaks one: the dashes of each line of its pattern (GetPatternDefinitionAt(int)), as the HATCH holds them, cut by its loops, each a LINE with the HATCH's look, a dot of the pattern a LINE of no length, as ezdxf's hatch_entity draws them. The lines of a pattern line run from its base point and every offset from it; each is cut where it crosses the loops, its stretches inside them kept by the even-odd rule, and its dashes laid from the line's own base point. The loops it is cut by are those the HatchStyle fills: every loop in the normal style; in the outer style those flagged external or outermost (1 or 16 of their type), and ignoring islands those flagged external, as AutoCAD 2021 and ezdxf take them, so that a square in the outer style round a circle of radius 7 and one of radius 3 in it, both flagged outermost, is hatched inside the smaller circle too, as AutoCAD's Explode hatches it; where no loop is so flagged, by how deep each lies among the others as Area counts it, the outermost and those just inside them in the outer style, the outermost alone ignoring islands. Lines, arcs, ellipses and splines of a loop are cut where they are crossed, an arc and an ellipse exactly, a spline to the bit within each sixteenth of a span of its knots; a dot that falls on a loop where its line crosses it is kept, but a line of the pattern that runs along a straight edge of a loop gives nothing along it, as AutoCAD gives nothing there: a square 30 by 20 filled with DOTS from its corner, the dots 1.5875 apart, gives 228 dots, none on its bottom edge. A square 30 by 20 filled with ANSI31, the one line at 45 degrees 3.175 apart, gives 11 LINEs; the same round a circle of radius 5 about its middle in the normal style gives 14, the three lines that cross the circle broken in two. The parts run pattern line by pattern line, then by the index of the line from the base point, the least first, then along the line, each from its start along the angle of its pattern line.

GetAssociatedObjects()

Gets the objects the loops follow, as AutoCAD's GetAssociatedObjectIds gives their ids: the entities of the handles of every loop (groups 330), each once, in the order the loops name them; a handle the drawing has no entity of is passed over. None for a HATCH in no drawing.

GetAssociatedObjectsAt(int)

Gets the objects one loop follows, as AutoCAD's GetAssociatedObjectIdsAt gives their ids, as GetAssociatedObjects() gives them.

GetGradientColors()

Gets the colours of the gradient (groups 463, 63 and 421), as AutoCAD's GetGradientColors: each a colour of the index where the record writes one (63), else the true colour of its red, green and blue (421), with its value; none where the HATCH has no gradient data.

GetHatchLineDataAt(int)

Gets a line the pattern draws, as AutoCAD's GetHatchLineDataAt: in the plane of the HATCH, in the system of its normal as its loops are held, from where it starts to where it ends; a dot from a point to itself. It is the line of the index Explode() gives, in its plane, to the bit: pattern line by pattern line, then by the index of the line from the base point, the least first, then along the line.

GetHatchLinesData()

Gets every line the pattern draws, as AutoCAD's GetHatchLinesData: in the plane of the HATCH, in the system of its normal, in the order and to the bit of GetHatchLineDataAt(int); none for a solid fill and a gradient. A square 30 by 20 filled with a pattern made by the user of lines at 45 degrees 3.175 apart gives 11 lines, each from one side of the square to another.

GetLoopAt(int)

Gets a loop, as AutoCAD's GetLoopAt: what it is and its shape in the world, as DxfHatchLoop says. A loop of a polyline is a GeoPolygonArc3 of its vertices and bulges, a polyline of two vertices joined by an arc given a vertex at the middle of the arc, as DxfReader gives a LWPOLYLINE so; a loop of edges is its lines (GeoLine3), arcs (GeoArc3, a GeoCircle3 for a whole turn), ellipses (GeoEllipse3 for a whole one, the GeoSpline3 that is exactly the part of one) and splines (GeoSpline3), each running the way the loop runs; an arc edge whose two angles (50 and 51) are the same is a whole circle.

GetPatternDefinitionAt(int)

Gets a line of the pattern, as AutoCAD's GetPatternDefinitionAt: as the HATCH holds it, scaled and turned with the pattern, in the system of its normal.

GetPlane()

Gets the plane of the HATCH, as AutoCAD's GetPlane: that of its Normal at its Elevation, through the point of elevation (groups 10, 20, 30) in the world, where its loops lie.

GetSeedPointAt(int)

Gets a seed point (groups 10 and 20 after the 98), in the system of the normal, as ObjectARX's getSeedPointAt.

InsertLoopAt(int, DxfHatchLoop)

Puts a loop in before the loop of an index, as AutoCAD's InsertLoopAt: one read from a HATCH of the same normal and elevation written as it was read; any other from its shapes, taken into the system of the normal, a polyline as a loop of a polyline, the edges as a loop of edges, the arcs and ellipses that run clockwise about the normal flagged so, each edge to start where the one before it ends, within Default. A loop read is written with the count of fit points of each spline edge (97) as the file's version has it: from R2010 a spline edge with none writes 97 0, before it none. A HATCH that was associative is so no longer, as AutoCAD's is not once its loops are changed: its group 71 nought and the handles of the objects its loops followed taken out.

LoopTypeAt(int)

Gets what a loop is (its group 92), as AutoCAD's LoopTypeAt.

RemoveAssociatedObjects()

Takes the objects the loops follow away, as AutoCAD's RemoveAssociatedObjectIds: the handles of every loop out, each loop's count of them nought, and the HATCH no longer associative, as Associative set false says.

RemoveLoopAt(int)

Takes a loop out, as AutoCAD's RemoveLoopAt. A HATCH that was associative is so no longer, as InsertLoopAt(int, DxfHatchLoop) says.

RemoveSeedPointAt(int)

Takes a seed point out, as ObjectARX's removeSeedPointAt; its count written anew.

SetAssociatedObjects(IReadOnlyList<IReadOnlyList<DxfEntity>>)

Makes the HATCH follow the objects each of its loops was made of, as AutoCAD keeps a HATCH made associative by picking a point or selecting objects: each loop given the handles of its objects after their count (groups 97 and 330), group 71 written 1 (Associative), and the HATCH put among the reactors of each object (102 {ACAD_REACTORS); the objects it followed before let go first. The loops are left as they are: a square hatched from a point inside its four LINEs follows the four, and GetAssociatedObjectsAt(int) gives them. AutoCAD makes the loops anew when such an object changes; the library does not.

SetGradient(DxfGradientPatternType, string)

Fills the HATCH with a gradient, as AutoCAD's SetGradient: filled solid (70 of 1) with the pattern SOLID, its pattern's angle, scale and lines taken out, and its gradient data (450 of 1 on) of the name given; the angle, shift, tint and colours it has kept, or, where it had no gradient data, nought and AutoCAD's colours of a new gradient, blue (0, 0, 255) to a pale yellow (255, 255, 153), as the variables GFCLR1 and GFCLR2 start.

SetGradientColors(DxfGradientColor[])

Gives the gradient its colours, as AutoCAD's SetGradientColors: their count (group 453) and, for each, its value (463), its index where it is a colour of the index (63) and its red, green and blue (421). The colours it has change nothing.

SetHatchPattern(DxfHatchPatternType, string)

Gives the HATCH a pattern, as AutoCAD's SetHatchPattern: its type (group 76) and name (2). SOLID fills it solid (70 of 1) and takes out the pattern's angle, scale and lines and any gradient; any other name fills it with a pattern (70 of 0) at the angle and scale it has, its gradient taken out. A pattern made by the user is given its lines, one family at PatternAngle PatternSpace apart, crossed where it is double, as AutoCAD makes them; a pattern of the name it has keeps its lines; the lines of any other pattern are in AutoCAD's pattern file, not in the drawing, and are left out, for AutoCAD to draw the pattern by its name, the count of its lines (78) written as 0, since AutoCAD refuses a file whose pattern HATCH has no 78. Where the drawing's PatternSearchPath finds the pattern in the caller's own files, the HATCH is given its lines from there as AutoCAD 2021 gives them, turned and scaled with it, its name written in capitals and its type that of the file it is found in, and so is a pattern of the name it has that holds no lines; a HATCH in no drawing is given them when it is added to one: a square 30 by 20 given ANSI31 of acadiso.pat holds the one line at 45 degrees, offset (-2.245, 2.245), and explodes to 11 LINEs.

SetPatternDefinitions(IEnumerable<DxfPatternDefinition>)

Sets the lines of the pattern (group 78, then each line's 53, 43, 44, 45, 46, 79 and 49), each as GetPatternDefinitionAt(int) gives it back: turned and scaled with the pattern, in the system of its normal; for a pattern of the caller's own that no pattern file of the drawing holds. ANSI31 at the scale 1 is the one line at pi / 4 through (0, 0), offset (-2.245, 2.245): a square 30 by 20 given it explodes to 11 LINEs, as AutoCAD draws it. The name, type, angle and scale are kept as they are; a later PatternAngle or PatternScale turns and scales these lines as it does those of a file.

TransformBy(GeoTransform3, bool)

Moves, turns, scales or mirrors the HATCH as TransformBy(GeoTransform3) does, and says whether a mirror reflects the lines of its pattern: AutoCAD's TransformBy follows its system variable MIRRHATCH, 0 by default, which leaves them as they were, and 1, which reflects them with the rest; TransformBy(transform) is the 0 form.