设置文字样式并写入CAD

来源:互联网 发布:unity3d中UI text是 编辑:程序博客网 时间:2024/05/01 20:54

//设置字体样式
AcDbObjectId CMainDlg::createTextStyle(CString fontName,CString bigFontName,CString textStyleName)
{
 Acad::ErrorStatus es;
 AcApDocument *pDoc=acDocManager->curDocument();
 es=acDocManager->lockDocument(pDoc);
 if(es!=Acad::eOk)
 {
  acutPrintf("锁定文档失败");
  return NULL;
 }
 AcDbObjectId textStyleId;
 AcDbTextStyleTable textStyleTable;
 //textStyleTable.getAt("宋体",textStyleId,false);
 AcGiTextStyle *TextStyle=new AcGiTextStyle(fontName,bigFontName,0,0,0,0,Adesk::kFalse,Adesk::kFalse,
           Adesk::kFalse,Adesk::kFalse,Adesk::kFalse,textStyleName); //字体名
 toAcDbTextStyle(*TextStyle,textStyleId);
 acDocManager->unlockDocument(pDoc);
 return textStyleId;
}


//文字写入
void CMainDlg::createText(AcGePoint3d pt,CString strText,double scale,double high/*,CString textCate*/)
{
 Acad::ErrorStatus es;
 AcApDocument *pDoc=acDocManager->curDocument();
 es=acDocManager->lockDocument(pDoc);
 if(es!=Acad::eOk)
  {
  acutPrintf("锁定文档失败");
  return;
  }
 //在这里如果是hztxt.shx为什么还显示不正确只有hztxt.txt才没有问号?
 AcDbObjectId textId= createTextStyle("新宋体","","vm");

 
 AcDbText *ptext=NULL;
 int nLength=strText.GetLength();
 char *ch=new char(nLength);
 ch=strText.GetBuffer(0);

 ptext=new AcDbText(pt,ch,textId,high,0);
 ptext->setWidthFactor(scale);
 ptext->setColorIndex(0);

 AcDbBlockTable *pblocKTable;
 acdbHostApplicationServices()->workingDatabase()->getSymbolTable(pblocKTable,AcDb::kForRead);
 AcDbBlockTableRecord *pblocKTableRecord;
    pblocKTable->getAt(ACDB_MODEL_SPACE,pblocKTableRecord,AcDb::kForWrite);
    pblocKTableRecord->appendAcDbEntity(textId,ptext);
    pblocKTable->close();
    pblocKTableRecord->close();
    ptext->close();
    acDocManager->unlockDocument(pDoc);

}
 

原创粉丝点击