[每日一码] ARX - Ordinate Dimension Text 在旋转UCS下不正确的解决方案
void ASDKtestOrd(){
ads采用point pt1;
if( RTNORM != acedGetPoint(NULL,L"\n Select point for ord dim", pt1) )
{return;}
AcGePoint3d ptx1(pt1,pt1,pt1);
AcGePoint3d pT2;
AcGeMatrix3d mx;
AcDbDatabase *pDb = acdbHostApplicationServices()->workingDatabase();
if ( !acdbUcsMatrix(mx, pDb) )
{
return;
}
//pT2 is the point for the leader
pT2 = ptx1;
pT2 = ptx1-3.0; //leader point dropped down 3 unitsbelow
pT2 = ptx1;
AcDbOrdinateDimension *pDim = new AcDbOrdinateDimension(Adesk::kTrue,ptx1,pT2,NULL,NULL);
//Xaxis
AcGeVector3d mXPrev = AcGeVector3d::kXAxis;
//get the old HorizontalRotation
double mOldHorzRot = pDim->horizontalRotation();
AcGeMatrix3d mMat; //matrix to build the ECS
//get the old Xaxis and transform it to current plane
mMat.setToPlaneToWorld(pDim->normal()); //ECS
mXPrev.transformBy(mMat); //get the ECS xaxis in the world coordinates
mXPrev.transformBy(mx); //tranform the current xaxis to new plane defined by mx.
//transform the dimension entity by the given transformation matrix
pDim->transformBy(mx);
//get the xAxis after transformation of the dimension entity
mMat.setToWorldToPlane(pDim->normal());
mXPrev.transformBy(mMat); //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);
AcDbBlockTable *pBlockTableD;
acdbHostApplicationServices()->workingDatabase()
->getSymbolTable(pBlockTableD, AcDb::kForRead);
AcDbBlockTableRecord *pBlockTableRecordD;
pBlockTableD->getAt(ACDB采用MODEL采用SPACE, pBlockTableRecordD, AcDb::kForWrite);
pBlockTableD->close();
AcDbObjectId dimIdD;
pBlockTableRecordD->appendAcDbEntity(dimIdD, pDim);
pBlockTableRecordD->close();
pDim->close();
}
页:
[1]