[每日一码] 设置对齐标注的倾角为相对UCS X轴的绝对转角
void setDimTxtOblique(){
AcGePoint3d pt1, pt2;
double baseAng, oblAng;
AcGePoint3d ptDim;
AcGeMatrix3d m;
Acad::ErrorStatus es;
int ret;
AcDbDatabase *pDb =
acdbHostApplicationServices()->workingDatabase();
// get start and end points
if(acedGetPoint(NULL, L"\nFirst point: ",
asDblArray(pt1))!= RTNORM)
return;
if( acedGetPoint(asDblArray(pt1), L"\nSecond point: ",
asDblArray(pt2) ) != RTNORM)
return;
// get text position
AcGePoint3d ptMid( 0.5*(pt1.x + pt2.x), 0.5*(pt1.y + pt2.y),
0.5*(pt1.z + pt2.z));
if(acedGetPoint(asDblArray(ptMid), L"\nDim Line position:",
asDblArray(ptDim) ) != RTNORM)
return;
// get the oblique angle from users
// please note it's relative to the X axis of current UCS
ret = acedGetAngle(NULL, L"Oblique angle: <0.0>", &oblAng);
if( ret == RTNONE ) oblAng = 0.0;
else if ( ret != RTNORM ) return;
// calculate the dimension baseline angle
baseAng = acutAngle(asDblArray(pt1), asDblArray(pt2));
// create aligned dimension
AcDbAlignedDimension* pDim = new AcDbAlignedDimension;
es = pDim->setXLine1Point(pt1); assert(es==Acad::eOk);
es = pDim->setXLine2Point(pt2); assert(es==Acad::eOk);
// get transform matrix
if( !acdbUcsMatrix(m, pDb) ) return;
// set line points and text position as default
es=pDim->setDimLinePoint(ptDim); assert(es==Acad::eOk);
es=pDim->useDefaultTextPosition(); assert(es==Acad::eOk);
es=pDim->setOblique(oblAng-baseAng); assert(es==Acad::eOk);
// set default database and transform it to WCS
pDim->setDatabaseDefaults();
es = pDim->transformBy(m); assert(es==Acad::eOk);
// append it to AutoCAD database
AcDbBlockTableRecord *pBlkRec;
AcDbObjectId objID;
es = acdbOpenObject(pBlkRec, pDb->currentSpaceId(),
AcDb::kForWrite);
assert(es==Acad::eOk);
es =pBlkRec->appendAcDbEntity (objID, pDim) ;
assert(es==Acad::eOk);
// close it
pDim->close();
pBlkRec->close();
return;
}
页:
[1]