Close

Relief for ODA Team in Ukraine

Learn more
ODA Drawings SDK
Working with General Dimension Methods

This topic describes working with methods that are available for all dimension entities.

Dimension block ID

To find out the object ID of the dimension block (BlockTableRecord) associated with a dimension entity, use the dimBlockId() method which returns the object ID as an object of the OdDbObject ID class.

Note: The object ID of a newly created dimension block has a 0 value initially, and the actual object ID is obtained as soon as the block is recomputed (by the recomputeDimBlock() method or by closing the block object).

For example:


::odrxDynamicLinker()->loadModule(OdRecomputeDimBlockModuleName);
OdDbOrdinateDimensionPtr pDimension = OdDbOrdinateDimension::createObject();
bBTR->appendOdDbEntity(pDimension);
pDimension->setDatabaseDefaults(pDb);
pDimension->recomputeDimBlock(true);
odPrintConsoleString(L"\ndimBlockId %d", pDimension->dimBlockId());

Dimension block position

To get the position of the dimension block associated with a dimension entity, use the dimBlockPosition() method which returns the dimension block position as an object of the OdGePoint3d class.

For example:


OdGePoint3d dimBlkPos = pDimension->dimBlockPosition();
odPrintConsoleString(L"\ndimBlockPos %f %f %f", dimBlkPos.x, dimBlkPos.y, dimBlkPos.z);

To set a new position for a dimension block, use the setDimBlockPosition() method which requires one OdGePoint3d parameter to specify the new position.

For example:


pDimension->setDimBlockPosition(OdGePoint3d(1.0,1.0,1.0));

Dimension style

Each dimension entity is associated with a dimension style that is used to draw the dimension. Dimension styles are stored as a record in the dimension style table represented by the OdDbDimStyleTable class. When a dimension entity is created, it is based on a dimension style that defines its default values. To get the object ID of the dimension style, use the dimensionStyle() method.

For example:


OdDbObjectId dimStyleId = pDimension->dimensionStyle();

To set a new dimension style for a dimension entity, use the setDimensionStyle() method, which requires an OdDbObjectId object to specify the object ID of the dimension style.

For example:


//Create the DimStyle 
OdDbDimStyleTableRecordPtr pDimStyle = OdDbDimStyleTableRecord::createObject();
// Set the name 
pDimStyle->setName(L"DimStyle_1");
// Open the DimStyleTable 
OdDbDimStyleTablePtr pTable = pDb->getDimStyleTableId().safeOpenObject(OdDb::kForWrite);
// Add the DimStyle
OdDbobject ID dimStyleId = pTable->add(pDimStyle);
// Set some properties
pDimStyle->setDimtxsty(pDb->getTextStyleStandardId());
pDimStyle->setDimsah(true);
pDimStyle->setDimblk1(OD_T("_OBLIQUE"));
pDimStyle->setDimblk2(OD_T("_DOT"));
// Set this dimension style to dimension entity
pDimension->setDimensionStyle(dimStyleId);

Dimension normal

A dimension entity is a planar object and the normal defines the orientation of the dimension entity plane in WCS. To get the normal of a dimension, use the normal() method, which requires no parameters and returns the dimension normal as an OdGeVector3d object.

For example:


OdGeVector3d normal = pDimension->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(1.0, 2.0, 3.0);
pDimension->setNormal(newNormal);

Elevation of the dimension

Dimension elevation shows the distance from the origin of coordinates to the dimension plane along the normal. To get the dimension 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 pDimension is %f", pDimension->elevation());

To set a new elevation to a dimension, use the setElevation() method, which requires one double parameter as a new elevation value.

For example:


pDimension->setElevation(13.5);

Scale of the dimension

The dimension scale factor is a positive non-zero double value, which scales the dimension entity and affects text size, text gap, arrowhead size, extension line extension, extension line offset, and other visual elements of a dimension entity. The scale factor does not affect the measured lengths, angles, or coordinates. If the value is less than 1.0, the visual elements and text box are condensed; if greater than 1.0, the visual elements and text box are enlarged. To get the scale factor of a dimension entity, use the dimscale() method, which returns the scale factor as a double value.

For example:


odPrintConsoleString(L"\nScale factor of pDimension is %f", pDimension->dimscale());

To set a new scale factor to a dimension entity, use the setDimscale() method, which requires one double value as a new scale value.

For example:


pDimension->setDimscale(1.5);

Horizontal rotation of the dimension

Horizontal rotation is the rotation angle of a dimension entity in the range from 0 to 2*PI radians. A positive angle value rotates the dimension entity clockwise (to the right) relative to the x-axis when looking down from the z-axis towards the origin. A negative angle rotates the dimension entity counterclockwise (to the left).

The behavior also depends on the dimension class.

For aligned linear and rotated linear dimension entities, the rotation angle defines the slope of the dimension text box clockwise relative to the x-axis.

For arc-length, two-line angular, and three-point angular dimension entities, the rotation angle defines the slope of the dimension text box clockwise relative to the x-axis.

For radial large, radial, and diametric dimension entities, the rotation angle defines the slope of the center mark and dimension text box with the leader line clockwise relative to the x-axis. If the dimension line is placed along the rotation line through the center, the text box is placed along the dimension line and the leader line is not drawn.

For ordinate dimension entities, the rotation angle defines the slope of the extension line clockwise relative to the x-axis for a y-ordinate dimension entity, or relative to the y-axis for an x-ordinate dimension entity.

To get the horizontal rotation angle, use the horizontalRotation() method, which returns the rotation angle as a double value.

For example:


odPrintConsoleString(L"\nHorizontal rotation of pDimension is %f", pDimension->horizontalRotation());

To set a new horizontal rotation angle to a dimension entity, use the setHorizontalRotation() method, which requires one double value as a new angle value.

For example:


pDimension->setHorizontalRotation(0.75);

Note: You can also use the setTextRotation() method to rotate the text counterclockwise relative to the x-axis. The resulting angle is the sum (taking into account their positive/negative signs) of the dimension entity's rotation angle and the text rotation angle.

Dimension text

Dimension text is the text string that replaces or supplements the measured value. If the dimension text is an empty string, which is the default value, the dimension entity represents the measured value. You can combine the value string with your annotation text enclosing the measurement into angle brackets.

To add dimension text to the dimension entity use the setDimensionText method, which requires one OdString value to specify the dimension text.

For example:


pDimension->setDimensionText(L"Length = <>");

The following illustration shows the result:

To get the dimension text, use the dimensiontext() method, which returns the dimension text as an OdString value.

For example:


odPrintConsoleString(L"\nDimension text of pDimension is %s", pDimension->dimensionText().c_str());

Arc symbol type

For arc-length dimensions, an arc symbol can be added or hidden. To do so, use the setArcSymbolType() method, which requires one OdInt16 parameter to specify the arc symbol type and can be one of the next values:

  • 0 — Arc length symbol is placed before the dimension text (default).
  • 1 — Arc length symbol is placed above the dimension text.
  • 2 — Arc length symbol is suppressed (not displayed).

For example:


pDimension->setArcSymbolType(1);

To get the arc symbol type, use the arcSymbolType() method, which returns the arc symbol type as an OdInt16 value.

For example:


odPrintConsoleString(L"\nArc symbol type is %d", pDimension->arcSymbolType());

Formatted measurement

To get the formatted text of a dimension, use the formatMeasurement() method, which requires three parameters: OdString value for returning the formatted text, double value to specify the measurement value, and OdString value to specify dimension text. The resulting string combines the measured value with specified dimension text and the dimension's settings for prefixes, suffixes, units, precision, alternate units, tolerances, and so on.

For example:


OdString formatStr; 
pDimension->formatMeasurement(formatStr,pDimension->measurement(), L"Length <>");
odPrintConsoleString(L"\nFormatMeasurement: %s", formatStr.c_str());

For the dimension measurement in the picture below, the resulting string will be displayed:


FormatMeasurement: \A1;Length 6.0000%%p0.1000 meters [152.40%%p2.54]

Dimension style data

You can copy the dimension style data from this dimension object to a DimStyleTableRecord using the getDimstyleData() method, which requires a pointer to the OdDbDimStyleTableRecord object to specify the DimStyleTableRecord object that will store dimension style data.

For example:


OdDbDimStyleTableRecordPtr pTable = OdDbDimStyleTableRecord::createObject();
pDimension->getDimstyleData(pTable);

To copy the dimension style data, including overrides, from the specified DimStyleTableRecord to the dimension object, use the setDimstyleData() method, which requires one pointer to the OdDbDimStyleTableRecord object to specify the DimStyleTableRecord object that is storing the dimension style data.

For example:


pDimension->setDimstyleData(pTable);

Recomputing dimensions

To recompute the dimension block of the dimension entity, use the recomputeDimBlock() method, which recomputes the dimension block referenced by this dimension entity block to reflect any changes made to the dimension entity since the last time the block table record was updated. This method requires one boolean parameter to specify whether the dimension block should be updated, even if the dimension has not been changed.

For example:


pDimension->recomputeDimBlock(true);

See Also

Working with Dimensions

Working with Common Dimension Entity

Positioning Dimension Text

Formatting Dimension Text

Working with Dimension Lines

Working with Extension Lines

Working with Dimension Fit and Movement

Working with Dimension Tolerances

Working with Dimension Values

Working with Primary Unit Measurements

Working with Alternate Unit Measurements

Marking the Center of Dimensions

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