如何显示文字
请问,在程序里如何写,才能让一段文字显示在下面图片的那个小框里面呢?或者是在CAD下弹出个对话框,输入一段文本后,我怎么把问题提取到图片中的那个小框中呢?请给点方面的事例,十分感谢. 拾取两个角点,求出中心点,然后添加文字,用中心对齐方式。 那用程序怎么才能把文字写到CAD上呢?能不能给点参考啊? AcDbText 我也有这个问题。不知道怎么用AcDbText (); 那位大虾能赐教AcDbText ()的使用问题,
谢谢!! 源码没头文件,及入口函数,这些自己定义吧,
void text()<BR>{
<BR> AcDbBlockTable* pBlockTable;<BR> acdbHostApplicationServices()->workingDatabase()<BR> ->getSymbolTable(pBlockTable,AcDb::kForRead);<BR> AcDbBlockTableRecord* pBlockTableRecord;<BR> pBlockTable->getAt(ACDB_MODEL_SPACE,pBlockTableRecord,<BR> AcDb::kForWrite);<BR> pBlockTable->close();
double ptt=<BR> {<BR> {0,0,0},<BR> {420,0,0},<BR> {420,297,0},<BR> {0,297,0},<BR> <BR> };
<BR> AcGePoint3d pt(ptt+100,ptt+100,ptt);<BR> AcDbText* pText=new AcDbText;<BR> pText->setHorizontalMode(AcDb::kTextRight);<BR> pText->setAlignmentPoint(pt);<BR> pText->setTextString("100");<BR> pText->setTextStyle(AcDbObjectId::kNull);<BR> pText->setHeight(30);<BR> pText->setRotation(0);
AcDbObjectId pTextId;<BR> pBlockTableRecord->appendAcDbEntity(pTextId,pText);<BR> pBlockTableRecord->close();<BR> pText->close();
} 没头文件及入口函数,自己定义。
AcDbDatabase *pDb = new AcDbDatabase;<BR> AcDbBlockTable *pBlockTable;<BR> pDb->getSymbolTable(pBlockTable, AcDb::kForRead);<BR> AcDbBlockTableRecord *pBlockTableRecord;<BR> pBlockTable->getAt(ACDB_MODEL_SPACE, pBlockTableRecord, AcDb::kForWrite);<BR> pBlockTable->close();
<BR> AcGePoint3d textPosition(120.0, 80.0, 0.0);<BR> AcGePoint3d atextPosition(130.0, 80.0, 0.0);<BR> char textString = "Auto Create Drawing";<BR> double textHeight = 5.5296;<BR> double textWidthFactor = 0.8000;<BR> double textThickness = 0.0;<BR> double textRotation = 0.0;<BR> <BR> AcDbText *pText=new AcDbText(textPosition, textString, AcDbObjectId::kNull, textHeight, textRotation);<BR> pText->setHorizontalMode(AcDb::kTextMid);//<BR> pText->setAlignmentPoint(atextPosition); //
AcDbObjectId textId;<BR> pBlockTableRecord->appendAcDbEntity(textId, pText); <BR> pBlockTableRecord->close();<BR> pText->close();
pDb->saveAs("测试文件.dwg");<BR> delete pDb;
请问大家如何才能使"测试文件.dwg"中的文字能够正确设置?一打开文件,<FONT color=#ff0000>文字现在仍然是左对齐,只不过有中间对齐点,并且属性框中也这么显示。</FONT>搞不定了,恳请大家帮帮。 本帖最后由 作者 于 2005-7-2 18:26:16 编辑 <br /><br /> <FONT face=宋体><FONT size=2>谢谢XD空间的binbin和王咣生版主,问题搞定了。<BR><BR>(没头文件及入口函数,自己定义。)<BR>功能:实现在后台数据库中正确添加文字,并且设置文字属性。关键是把后台数据库设置当前,最后设置回去。<BR></FONT><FONT color=red>AcDbDatabase *pOldDb = acdbHostApplicationServices()->workingDatabase();</FONT></FONT><FONT face=宋体><FONT size=2> <BR>AcDbDatabase *pDb = new AcDbDatabase;<BR></FONT><FONT color=red>acdbHostApplicationServices()->setWorkingDatabase(pDb);</FONT></FONT><FONT face=宋体><FONT size=2> <BR><BR>AcDbBlockTable *pBlockTable;<BR><FONT color=#ff0000>acdbHostApplicationServices()->workingDatabase()-></FONT>getSymbolTable(pBlockTable, AcDb::kForRead);<BR>AcDbBlockTableRecord *pBlockTableRecord;<BR>pBlockTable->getAt(ACDB_MODEL_SPACE, pBlockTableRecord, AcDb::kForWrite);<BR>pBlockTable->close();<BR><BR><BR>AcGePoint3d textPosition(120.0, 80.0, 0.0);<BR>AcGePoint3d atextPosition(130.0, 80.0, 0.0);<BR>char textString = "Auto Create Drawing";<BR>double textHeight = 5.5296;<BR>double textWidthFactor = 0.8000;<BR>double textRotation = 0.0;<BR><BR>AcDbText *pText=new AcDbText(textPosition, textString, AcDbObjectId::kNull, textHeight, textRotation);<BR>pText->setHorizontalMode(AcDb::kTextMid);//<BR>pText->setAlignmentPoint(atextPosition); //<BR><BR>AcDbObjectId textId;<BR>pBlockTableRecord->appendAcDbEntity(textId, pText); <BR>pBlockTableRecord->close();<BR>pText->close();<BR><BR>pDb->saveAs("测试文件.dwg");<BR></FONT><FONT color=red>acdbHostApplicationServices()->setWorkingDatabase(pOldDb); </FONT><BR><FONT size=2>delete pDb;</FONT></FONT>
<FONT color=#ff0000>请问各位大侠,如何可以动态确定文字长度?因为希望可以把超出范围的文字,通过设置大小,或者比例因子来缩放回去。</FONT> 我用了9楼的代码,我想9楼的代码的作用应该是在一个打开的DWG文件中,在设定的位置加上文字"Auto Create Drawing".最后是保存到"测试文件.dwg"这个文件中吧.
<P>我运行的结果是:原来的那个DWG文件没有加上"Auto Create Drawing",而"文件名.dwg"这个文件中只显示"Auto Create Drawing",却没有其他任何图形或者文字.所以不知道问题出在哪里?</P>
页:
[1]
2