I have a function which creates ordinate dimensions. When the UCS is rotated around the Z Axis the value for the text is incorrect and appears to be the value of the X or Y value this point would have in WCS.
The solution to this behavior is to invoke AcDbDimension::setHorizontalRotation() . The value of DXF group code 51 is queried via AcDbDimension::horizontalRotation(), and is what is established by the angle of the UCS X axis at the time of acquisition. The X/Y ordinate flag on AcDbOrdinateDimension is set to indicate whether the text is aligned with, or perpendicular to, the horizontal rotation (the UCS X axis in effect) or the vertical direction (the UCS Y axis in effect).
When you rotate around the WCS Z axis to get your UCS, the underlying OCS is exactly the WCS. The value stored is the negative of the horizontal rotation angle in the OCS. Invoking AcDbEntity::transformBy on a dimension intentionally does not alter this setting, although it moves all the dimensioned points, extension line and text position points.
So, to reorient the text, get the angle between your UCS x axis and the OCS X axis (which is 1,0,0 when the UCS Z axis is parallel to the WCS Z axis; or else you use the arbitrary axis algorithm to arrive at your OCS X axis, given the UCS Z axis or object normal vector), and pass the negative of this angle to setHorizontalRotation() and your text will be oriented in the direction of that UCS X or Y axis, depending on the setting of the X/Y ordinate flag.
Here is an example that creates an ordinate dimension correctly regardless of the UCS rotation:
if(RTNORM != acedGetPoint(
NULL, L"\n Select point for ordinate dimension", pt1))
AcDbDatabase *pDb = acdbHostApplicationServices()->workingDatabase();
if (!acdbUcsMatrix(mx, pDb))
// pT2 is the point for the leader
pT2 = ptx1;
pT2 = ptx1 - 3.0;
pT2 = ptx1;
AcDbOrdinateDimension *pDim =
AcGeVector3d mXPrev = AcGeVector3d::kXAxis;
// get the old HorizontalRotation
double mOldHorzRot = pDim->horizontalRotation();
// matrix to build the ECS
// get the old Xaxis and transform it to current plane
mXPrev.transformBy(mMat); //get the ECS xaxis in the world coordinates
mXPrev.transformBy(mx); //transform current xaxis to plane defined by mx
// transform the dimension entity by the given transformation matrix
// get the xAxis after transformation of the dimension entity
// transform the old axis to the current ECS.
// get the angle of the old xaxis with respect to the current xaxis
double mNewHorzRot = - atan2(mXPrev.y, mXPrev.x);
pDim->setHorizontalRotation(mOldHorzRot + mNewHorzRot);
pBlockTable->getAt(ACDB_MODEL_SPACE, pBlockTableRecord, AcDb::kForWrite);