[每日一码] 创建文字样式,写文字,修改样式的代码
static void ChangeStyle() {AcDbObjectId styleId;
// Create a text style
{
AcDbObjectPointer<AcDbTextStyleTable>
pTextStyleTable(acdbCurDwg()->textStyleTableId(), AcDb::kForWrite);
AcDbObjectPointer<AcDbTextStyleTableRecord> pStyle;
pStyle.create();
pStyle->setName(L"MyStyle");
pStyle->setFileName(L"romans.shx");
if (pTextStyleTable->add(styleId, pStyle.object()) != Acad::eOk)
{
pTextStyleTable->getAt(L"MyStyle", styleId);
}
}
acedAlert(L"created text style");
AcDbObjectId idtext;
// Create some text
{
AcDbObjectPointer<AcDbText> pText;
pText.create();
pText->setDatabaseDefaults();
pText->setTextStyle(styleId);
pText->setTextString(L"Some text");
pText->setHeight(10);
AcDbObjectPointer<AcDbBlockTableRecord>
pSpace(acdbCurDwg()->currentSpaceId(), AcDb::kForWrite);
pSpace->appendAcDbEntity(idtext, pText);
}
acTransactionManagerPtr()->flushGraphics();
acedUpdateDisplay();
acedAlert(L"created text");
{
// Change the font file for the text style
AcDbObjectPointer<AcDbTextStyleTableRecord>
pStyle(styleId, AcDb::kForWrite);
pStyle->setFileName(L"romand.shx");
}
{
AcDbObjectPointer<AcDbBlockTableRecord>
pSpace(acdbCurDwg()->currentSpaceId(), AcDb::kForRead);
AcDbBlockTableRecordIterator *pIter = NULL;
pSpace->newIterator(pIter);
AcDbObjectId id;
for (; !pIter->done(); pIter->step())
{
id.setNull();
pIter->getEntityId(id);
if (id.objectClass()->isDerivedFrom(AcDbText::desc()) ||
id.objectClass()->isDerivedFrom(AcDbMText::desc()) ||
id.objectClass()->isDerivedFrom(AcDbDimension::desc()) ||
id.objectClass()->isDerivedFrom(AcDbBlockReference::desc()))
{
AcDbEntityPointer pEnt(id, AcDb::kForWrite);
if (pEnt.openStatus() == Acad::eOk)
pEnt->recordGraphicsModified();
}
}
delete pIter;
}
acTransactionManagerPtr()->flushGraphics();
acedUpdateDisplay();
acedAlert(L"Custom Regen Current Space");
}
页:
[1]