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

A pattern is an area filled with solid lines and broken lines that can be rotated relative to the x-axis and replicated with an offset relative to a base point inside a hatch boundary. The OdDbHatch object has the patternType(), getPattern(), setPattern(), patternName(), setPatternAngle(), patternAngle(), setPatternDouble(), patternDouble(), setPatternScale(), patternScale(), setPatternSpace(), and patternSpace() methods to work with patterns.

Pattern type

A pattern can be one of the following pattern types:

  • User defined — Pattern is the number of plain lines with their angles, scales, etc.
  • Predefined — Predefined pattern, which is taken from the default .pat file.
  • Custom defined — Pattern from another .pat file.

To find the pattern type of a hatch, use the patternType() method, which returns the type of the pattern as an integer value defined by the HatchPatternType enumeration:


enum HatchPatternType {
  kUserDefined = 0, // Defines the pattern that is user defined.
  kPreDefined = 1, // Defines the pattern that is predefined in the default PAT file.
  kCustomDefined = 2 // Defines the pattern that is located in another PAT file.
};

For example:


OdString str;
OdInt8 nHatchType = pHatch->patternType();
switch(nHatchType)
{
  case 0:
    str = "user defined";
    break;
  case 1:
    str = "predefined";
    break;
  case 2:
    str = "custom defined";
    break;
}
odPrintConsoleString(L"\npHatch is %s", str.c_str());

Setting and getting the pattern

To get the pattern, use the getPattern() method, which returns the pattern of a hatch as an OdHatchPattern object. For example:


OdHatchPattern pHatchPattern = pHatch->getPattern();

To set the pattern of a hatch, use the setPattern() method, which requires two parameters: pattern type as one of the values from the HatchPatternType enumeration and the pattern name as an OdString value. When the pattern type is set to HatchPatternType::kPreDefined, the following values are admissible.

If the pattern type is set to HatchPatternType::kUserDefined, PatternName can be only the fixed name "_USER". For example:


pHatch->setPattern(OdDbHatch::kPreDefined, OD_T("ANGLE"));

Pattern name

To get the pattern name, use the patternName() method, which returns the pattern name as an OdString value. When the hatch type is gradient, the PatternName property returns the fixed name "SOLID". For example:


OdString str = pHatch->patternName();
odPrintConsoleString(L"\nName of pHatch pattern is %s", str.c_str());

Pattern angle

Pattern angle specifies the angle in radians as a double value in the range -2PI to +2PI on which the pattern rotates around the origin of a hatch entity. A positive value rotates the pattern counterclockwise. A negative value rotates the pattern clockwise. If an absolute angle value is greater than 2PI, it is converted to 2PI.

To get the pattern angle, use the patternAngle() method, which returns the pattern angle as a double value. For example:


double dAngle = pHatch->patternAngle();
odPrintConsoleString(L"\nAngle of pHatch pattern is %f radians", dAngle);

To set a new pattern angle, use the setPatternAngle() method, which requires one double parameter to indicate the new angle. For example:


pHatch->setPatternAngle(0.5);

Pattern scale and pattern space

Pattern scale and pattern space specify the scale factor that influences the length of dashes and distance between them in the pattern as a positive non-zero Double value. If the scale value is less than 1.0, dashes shrink and are placed closer together.

To set a new pattern scale, use the setPatternScale() method, which requires one double parameter to indicate the new scale. For example:


pHatch->setPatternScale(0.5);

To get the pattern scale, use the patternScale() method, which returns the pattern scale as a double value. For example:


double dScale = pHatch->patternScale();
odPrintConsoleString(L"\nPattern scale is %f", dScale);

To set a new pattern space, use the setPatternSpace() method, which requires one double parameter to indicate the new space. For example:


pHatch->setPatternSpace(2);

To get the pattern space, use the patternScale() method, which returns the pattern space as a double value. For example:


double dSpace = pHatch->patternSpace();
odPrintConsoleString(L"\nPattern space is %f", dSpace);

When you set the pattern scale to a value, the pattern space property is set to the same value; and vice versa, when you set the pattern space property to a value, the pattern scale property is set to the same value.

Pattern doubling

The PatternDouble flag specifies whether the user-defined pattern is double-hatched. The flag is a boolean value, and it is set to true if the pattern is double-hatched or it is set to false if the pattern is single-hatched.

To get the PatternDouble flag, use the patternDouble() method, which returns the pattern PatternDouble flag as a boolean value. For example:


if (pHatch->patternDouble())
  odPrintConsoleString(L"\nPattern is double-hatched");
else odPrintConsoleString(L"\nPattern single-hatched");

To set or unset the PatternDouble flag, use the setPatternDouble() method, which requires one boolean parameter to indicate double-hatching. For example:


pHatch->setPatternDouble(true);

Origin point

The origin point is used to determine from which point hatch strokes are calculated. To get the origin point of the hatch, use the originPoint() method, which requires no parameters and returns the origin point as an OdGePoint2d object.

For example:


OdGePoint2d orPoint = pHatch->originPoint();
odPrintConsoleString(L"\nOrigin x= %f y= %f", orPoint.x, orPoint.y);

To set a new origin point, use the setOriginPoint() method, which requires one OdGePoint2d parameter as the new origin point. For example:


OdGePoint2d newOrPoint;
newOrPoint.x = 1.0;
newOrPoint.y = 1.0;
pHatch->setOriginPoint(newOrPoint);

See Also

Overview of Hatches

Working with Loops of Hatches

Working with General 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.