ARX修改⽂本对齐⽅式
void changeTextInnerAlign()
{
//使⽤以下代码可以更换⽂本对齐⽅式,⽽不改变⽂字位置:
ads_name name,ent;
AcDbEntity *pObj;
AcDbObjectId ObjId;
long length=0;
acutPrintf(_T("\n选择需要对齐的⽂本实体:"));
if(acedSSGet(NULL,NULL,NULL,NULL,name)!=RTNORM) return;
acedSSLength(name,&length);
ArxDbgUiPrKeyWordDef prAlignType(_T("修改后的对齐⽅式[左对齐(L)/⽔平居中(M)/右对齐(R)]"),        _T("L M R"), _T("L"));text align center
if (() != ArxDbgUiPrBase::kOk)
return  ;
CString Justify;
if (prAlignType.isKeyWordPicked(_T("L")))
Justify = "左对齐";
else if (prAlignType.isKeyWordPicked(_T("M")))
Justify = "⽔平居中";
else if (prAlignType.isKeyWordPicked(_T("R")))
Justify = "右对齐";
else
{
ASSERT(0);
return ;
}
int i; for( i=0;i<length;i++)
{
acedSSName(name,i,ent);
acdbGetObjectId(ObjId,ent);
acdbOpenObject(pObj,ObjId,AcDb::kForWrite,Adesk::kFalse);
AcDbExtents extents1, extents2;
if(pObj->isKindOf(AcDbText::desc()))//普通⽂本
{
AcDbText *pText=AcDbText::cast(pObj);
pText->getGeomExtents(extents1);
if(Justify==_T("左对齐")) pText->setHorizontalMode(AcDb::kTextLeft);
else if(Justify==_T("右对齐")) pText->setHorizontalMode(AcDb::kTextRight);
else if(Justify==_T("⽔平居中")) pText->setHorizontalMode(AcDb::kTextCenter);
else pText->setHorizontalMode(AcDb::kTextLeft);
pText->setVerticalMode(AcDb::kTextBase);
}
else if(pObj->isKindOf(AcDbMText::desc()))//多⾏⽂本
{
AcDbMText *pMText=AcDbMText::cast(pObj);
pMText->getGeomExtents(extents1);
if(Justify==_T("左对齐"))
{
if(pMText->attachment()==AcDbMText::kTopCenter ||
pMText->attachment()==AcDbMText::kTopRight)
pMText->setAttachment(AcDbMText::kTopLeft);
else if(pMText->attachment()==AcDbMText::kMiddleCenter ||                    pMText->attachment()==AcDbMText::kMiddleRight)
pMText->setAttachment(AcDbMText::kMiddleLeft);
else if(pMText->attachment()==AcDbMText::kBottomCenter ||                    pMText->attachment()==AcDbMText::kBottomRight)
pMText->setAttachment(AcDbMText::kBottomLeft);
}
else if(Justify==_T("⽔平居中"))
{
if(pMText->attachment()==AcDbMText::kTopLeft ||
pMText->attachment()==AcDbMText::kTopRight)
pMText->setAttachment(AcDbMText::kTopCenter);
else if(pMText->attachment()==AcDbMText::kMiddleLeft ||
pMText->attachment()==AcDbMText::kMiddleRight)
pMText->setAttachment(AcDbMText::kMiddleCenter);
else if(pMText->attachment()==AcDbMText::kBottomLeft ||
pMText->attachment()==AcDbMText::kBottomRight)
pMText->setAttachment(AcDbMText::kBottomCenter);
}
else if(Justify==_T("右对齐"))
{
if(pMText->attachment()==AcDbMText::kTopLeft ||
pMText->attachment()==AcDbMText::kTopCenter)
pMText->setAttachment(AcDbMText::kTopRight);
else if(pMText->attachment()==AcDbMText::kMiddleLeft ||
pMText->attachment()==AcDbMText::kMiddleCenter)
pMText->setAttachment(AcDbMText::kMiddleRight);
else if(pMText->attachment()==AcDbMText::kBottomLeft ||
pMText->attachment()==AcDbMText::kBottomCenter)
pMText->setAttachment(AcDbMText::kBottomRight);
}
}
pObj->close();
AcDbEntity *pEnt = NULL;
acdbOpenObject(pEnt, ObjId, AcDb::kForWrite);
if (pEnt == NULL)
return;
pEnt->getGeomExtents(extents2);
AcGeVector3d vec = extents1.minPoint() - extents2.minPoint();
pEnt->transformBy(AcGeMatrix3d::translation(vec));
pEnt->close();
}
}

版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系QQ:729038198,我们将在24小时内删除。