Drawings SDK Developer Guide > Working with .dwg Files > Working with Entities > Working with Specific Entitites > Working with Hatches > Working with General Properties of Hatches
Working with General Properties of Hatches

The OdDbHatch object implements the hatch entity and is derived from the OdDbEntity object, inheriting all properties and methods of the standard entities interface on which it expands the properties and methods for working with hatches.

The OdDbHatch object has the hatchObjectType(), setHatchObjectType(), hatchStyle(), setHatchStyle(), associative(), setAssociative(), originPoint(), setOriginPoint(), normal(), setNormal() and getArea() methods to work with general hatch parameters. In the examples below, pDb variable stores a pointer to the database object, bPTR stores a pointer to the block table record, and the pHatch variable stores the reference to a hatch entity.

Hatch object type

There are two types of hatches. Classic hatches can be a pattern of lines or a solid. Another type of hatch is a gradient hatch. To get the hatch object type, use the hatchObjectType() method, which requires no parameters and returns the hatch object type as a value from the OdDbHatch::HatchObjectType enumeration:


enum HatchObjectType {
  kHatchObject = 0, // Defines a classic hatch object that is filled with a pattern formed by dashes.
  kGradientObject = 1 // Defines a gradient hatch object that is filled by a gradient.
};

For example:


if (pHatch->hatchObjectType() == 0)
  odPrintConsoleString(L"\npHatch is hatch object");
else odPrintConsoleString(L"\npHatch is gradient object");

To set the hatch object type, use the setHatchObjectType() method, which requires one parameter — hatch object type. The hatch object type is represented by the OdDbHatch::HatchObjectType enumeration (see above). For example:


pHatch->setHatchObjectType(OdDbHatch::HatchObjectType::kGradientObject);

Hatch style

To get the hatch style, use the hatchStyle() method, which requires no parameters and returns the hatch style as a value from the OdDbHatch::HatchStyle enumeration:


enum HatchStyle {
  kNormal = 0, // Fills the area within the boundary from the outer loop to the inner loop, then switches the hatching on and off between even and uneven inner loops.
  kOuter = 1,  // Fills the area within the boundary only from the outer loop to the first inner loop and skips other inner loops.
  kIgnore = 2  // Fills the area within the boundary through all inner loops and ignores the internal structure of loops.
};

For example:


odPrintConsoleString(L"\nHatch style is %i", pHatch->hatchStyle());

To set the hatch style, use the setHatchStyle() method, which requires one parameter — hatch style. The hatch style is represented by the OdDbHatch::HatchStyle enumeration (see above). For example:


pHatch->setHatchStyle(OdDbHatch::HatchStyle::kNormal);

The result of applying different hatch styles depends on flags of the hatch loops (see Working with Loops of Hatches).

  • "Ignore" style. Only following flags are used:
    • kOutermost;
    • kTextbox;
    • kExternal.
    If a loop has flags "External" or ("External" | "Outermost") and it is not inside a text island, then it switches hatching on/off (hatch line breaks on this loop). Text island is defined by the combination ("Textbox" | "External").
  • "Normal" style. If the loop has "Textbox" in the flags (that is - any flag combination plus "Textbox"), then it defines a text island. If it is not a text island (and not within text island), then hatch line breaks passing this loop.
  • "Outer" style. It is the same as normal, except that it ignores the loops that have neither "Outermost" nor "External" among the flags.

Text islands are never hatched.

Associativity

Hatch associativity determines whether the hatch is associative with entities that form the hatch boundary. To get the associativity property, use the associative() method, which requires no parameters and returns the associativity property as a boolean value. The method returns True if the hatch is associative or false if the hatch is not associative.

For example:


if (pHatch->associative())
  odPrintConsoleString(L"\npHatch is associative");
else odPrintConsoleString(L"\npHatch is not associative");

To set or unset the associative property, use the setAssociative() method, which requires one boolean parameter as the associative flag. For example:


pHatch->setAssociative(true);

Hatch area

To find out the area of a hatch, use the getArea() method, which requires one double parameter to specify the output value of the hatch area. The method returns eOk if the method performed the operations correctly or OdResult error code if an error occurs. The hatch entity must have a loop.

For example:


double area;
pHatch->getArea(area);
odPrintConsoleString(L"\nArea of pHatch %f", area);

Hatch normal

To get the normal of a hatch, use the normal() method, which requires no parameters and returns the hatch normal as an OdGeVector3d object.

For example:


OdGeVector3d normal = pHatch->normal();
odPrintConsoleString(L"\nNormal x= %f y= %f z= %f", normal.x, normal.y, normal.z);

To set a new normal, use the setNormal() method, which requires one OdGeVector3d parameter as a new normal vector. For example:


OdGeVector3d newNormal;
newNormal.x = 1.0;
newNormal.y = 2.0;
newNormal.z = 3.0;
pHatch->setNormal(newNormal);

Elevation of the hatch

Hatch elevation shows the distance from the origin of coordinates to the hatch plane along the normal. To get the hatch elevation, use the elevation() method, which requires no parameters and returns the distance as a double value. A positive value defines the elevation in the direction to the normal. A negative value defines the elevation in the opposite direction to the normal.

For example:


odPrintConsoleString(L"\nElevation of pHatch %f", pHatch->elevation());

To set a new elevation to a hatch, use the setElevation method, which requires one double parameter as a new elevation value. For example:


pHatch3->setElevation(13.5);

See Also

Overview of Hatches

Working with Loops of Hatches

Working with Pattern Properties of Hatches

Working with Gradient Properties of Hatches

Working with User-Defined Patterns of Hatches

Example of Working with Hatches

Copyright © 2002 – 2020. Open Design Alliance. All rights reserved.