ObjectARX
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

How to set text alignment to center?

1 REPLY 1
SOLVED
Reply
Message 1 of 2
zhengyunyang2019
272 Views, 1 Reply

How to set text alignment to center?

 

 

HRESULT BMText::CreateText(AcDbDatabase * pDb,const TextPro textPro, AcDbObjectId & oTextId)
{
	AcDbText *pText = new AcDbText(textPro.ac3dTextPos,BIM::Tools::toWstring(textPro.sText).c_str(), textPro.acIdStyle, textPro.dHeight, textPro.dRotation);

	pText->setWidthFactor(0.75);
	pText->setJustification( AcDbText::kTextAlignmentCenter);

	AcDbBlockTable *pBlockTable; 
	acdbHostApplicationServices()->workingDatabase() ->getBlockTable(pBlockTable, AcDb::kForRead); 
	AcDbBlockTableRecord *pBlockTableRecord; 
	pBlockTable->getAt(ACDB_MODEL_SPACE, pBlockTableRecord, AcDb::kForWrite); 
	pBlockTableRecord->appendAcDbEntity(oTextId, pText); 
	pBlockTable->close(); 
	pBlockTableRecord->close();
	pText->close();
	return E_FAIL;
}

 

 

I'm encountering an issue in my code where, after executing pText->setJustification(AcDbText::kTextAlignmentCenter);, the text position becomes offset by a certain distance. If I don't use this line of code, the text appears correctly at the expected coordinates.

 

I am using CAD version 2016

1 REPLY 1
Message 2 of 2

pText->setHorizontalMode(AcDb::TextHorzMode::kTextMid);
pText->setAlignmentPoint(ptInsert);
pText->setJustification(AcDbText::kTextAlignmentMiddleCenter );

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

Forma Design Contest


AutoCAD Beta