uusky 发表于 2005-9-6 17:56:00

关于进行文本标注

<P><FONT face=宋体>新建图层“选址标注”;当鼠标点击屏幕位置(鼠标事件的响应?)时在点击位置标注内容:“建设项目选址意见书”</FONT></P>
<P><FONT face=宋体>哪位高手帮忙 回个话&nbsp; 做不了我可就完蛋了</FONT></P>
<P>现在已经完成了新建图层:</P>
<P>void createNewLayer(const CString LayerName, const int color)<BR>{&nbsp; AcDbLayerTable *pLayerTbl;<BR>&nbsp;&nbsp;&nbsp; acdbHostApplicationServices()-&gt;workingDatabase()<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; -&gt;getSymbolTable(pLayerTbl, AcDb::kForWrite);<BR>&nbsp;//获得当前层表以便写入<BR>&nbsp;&nbsp;&nbsp; if (!pLayerTbl-&gt;has(LayerName)) {<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; AcDbLayerTableRecord *pLayerTblRcd<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; = new AcDbLayerTableRecord;<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; pLayerTblRcd-&gt;setName(LayerName);<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; pLayerTblRcd-&gt;setIsFrozen(0);// layer to THAWED解冻图层<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; pLayerTblRcd-&gt;setIsOff(0);&nbsp;&nbsp; // layer to ON&nbsp; 打开图层<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; pLayerTblRcd-&gt;setVPDFLT(0);&nbsp; // viewport default视口默认值<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; pLayerTblRcd-&gt;setIsLocked(0);// un-locked&nbsp;&nbsp; 解锁图层</P>
<P>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; AcCmColor color1;<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; color1.setColorIndex(color); // set color to color<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; pLayerTblRcd-&gt;setColor(color1);</P>
<P><BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; AcDbLinetypeTable *pLinetypeTbl;<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; AcDbObjectId ltId;<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; acdbHostApplicationServices()-&gt;workingDatabase()<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; -&gt;getSymbolTable(pLinetypeTbl, AcDb::kForRead);<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; if ((pLinetypeTbl-&gt;getAt("CONTINUOUS", ltId))<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; != Acad::eOk)<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; {<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; acutPrintf("\nUnable to find CONTINUOUS"<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; " linetype. Using DASHED");<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; pLinetypeTbl-&gt;getAt("CONTINUOUS", ltId);<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; }<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; pLinetypeTbl-&gt;close();//设置线型</P>
<P>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; pLayerTblRcd-&gt;setLinetypeObjectId(ltId);</P>
<P><BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; pLayerTbl-&gt;add(pLayerTblRcd);&nbsp;//将层表记录添加到层表中!<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; pLayerTblRcd-&gt;close();//关闭层表记录<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; pLayerTbl-&gt;close();//关闭层表<BR>&nbsp;&nbsp;&nbsp; } else {<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; pLayerTbl-&gt;close();<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; acutPrintf("\n图层已经存在!");<BR>&nbsp;&nbsp;&nbsp; }<BR>&nbsp;/*<BR>&nbsp;AcDb::LineWeight lw;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; //设置层的线宽<BR>&nbsp;lw = AcDb::kLnWt080;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; //value:80<BR>&nbsp;pLayerTableRecord-&gt;setLineWeight(lw);<BR>&nbsp;*/</P>
<P>}</P>
<P><FONT face=宋体><?xml:namespace prefix = o ns = "urn:schemas-microsoft-com:office:office" /><o:p></o:p></FONT>&nbsp;</P>

uusky 发表于 2005-9-7 14:09:00

<P>朋友给了段带码很管用,但是遇到两个问题:</P>
<P>1。文章是中文的时候出现乱码?</P>
<P>2。不知道如何设坐标点(下面的代码是坐标点已知的),使得在鼠标点击屏幕位置(鼠标事件的响应?)时的点击位置标注内容?</P>
<P>void addtext(&nbsp;&nbsp; char textString)<BR>{<BR>&nbsp;<BR>&nbsp;AcDbBlockTable *pBlockTablew;<BR>&nbsp;acdbHostApplicationServices()-&gt;workingDatabase()-&gt;getSymbolTable(pBlockTablew, AcDb::kForRead);<BR>&nbsp;AcDbBlockTableRecord *pBlockTableRecordw;<BR>&nbsp;pBlockTablew-&gt;getAt(ACDB_MODEL_SPACE, pBlockTableRecordw, AcDb::kForWrite);<BR>&nbsp;pBlockTablew-&gt;close();</P>
<P><BR>&nbsp;AcGePoint3d textPosition(10.0, 10.0, 0.0);<BR>&nbsp;AcGePoint3d atextPosition(20.0, 10.0, 0.0);<BR>&nbsp;//char textString = "建设项目选址意见书&nbsp;&nbsp;&nbsp; 号红线附图";<BR>&nbsp;double textHeight = 5.5296;<BR>&nbsp;double textWidthFactor = 0.8000;<BR>&nbsp;double textRotation = 0.0;</P>
<P>&nbsp;AcDbText *pText=new AcDbText(textPosition, textString, AcDbObjectId::kNull, textHeight, textRotation);<BR>&nbsp;pText-&gt;setHorizontalMode(AcDb::kTextMid);<BR>&nbsp;pText-&gt;setAlignmentPoint(atextPosition); </P>
<P>&nbsp;AcDbObjectId textId;<BR>&nbsp;pBlockTableRecordw-&gt;appendAcDbEntity(textId, pText); <BR>&nbsp;pBlockTableRecordw-&gt;close();<BR>&nbsp;pText-&gt;close();<BR>}</P>

zyxc1981 发表于 2005-9-8 08:29:00

<P>我也想知道,帮你顶</P>

huangyhg 发表于 2005-9-23 21:01:00

<P>1。文章是中文的时候出现乱码?</P>
<P>&gt;设置文本的样式</P>
<P>&nbsp;</P>

huangyhg 发表于 2005-9-23 21:32:00

<P>&nbsp;</P>
<P>&nbsp;</P>
<P>AcDbTextStyleTableRecord* pStyleNew= new AcDbTextStyleTableRecord;</P>
<P>pStyleNew-&gt;setName((LPCTSTR)strName);<BR>&nbsp;pStyleNew-&gt;setFileName("gbenor.shx");<BR>&nbsp;pStyleNew-&gt;setBigFontFileName("gbcbig.shx");//支持中文<BR>&nbsp;pStyleNew-&gt;setXScale(1.0);</P>

uusky 发表于 2005-9-24 09:53:00

<P>谢谢这位朋友的关注&nbsp; 问题都已解决,给出代码如下:</P>
<P>&nbsp;</P>
<P>&nbsp;//准备开始文字注记<BR>&nbsp;AcDbBlockTable *pBlockTablew;<BR>&nbsp;acdbHostApplicationServices()-&gt;workingDatabase()<BR>&nbsp;&nbsp;-&gt;getSymbolTable(pBlockTablew, AcDb::kForRead);<BR>&nbsp;AcDbBlockTableRecord *pBlockTableRecordw;<BR>&nbsp;pBlockTablew-&gt;getAt(ACDB_MODEL_SPACE, <BR>&nbsp;&nbsp;pBlockTableRecordw, AcDb::kForWrite);<BR>&nbsp;AcDbDatabase *pDb = acdbHostApplicationServices()-&gt;workingDatabase ();</P>
<P>Acad::ErrorStatus&nbsp; es; //打开数据库-&gt;块表-&gt;块表记录 <BR>&nbsp;es = pDb-&gt;getBlockTable (pBlockTablew,AcDb::kForRead );<BR>&nbsp;// ERROR HANDLE<BR>&nbsp;es = pBlockTablew-&gt;getAt (ACDB_MODEL_SPACE,pBlockTableRecordw,AcDb::kForWrite );<BR>&nbsp;AcDbTextStyleTable *pTST;<BR>&nbsp;AcDbTextStyleTableRecord *pTSTR;<BR>&nbsp;es = pDb-&gt;getTextStyleTable (pTST,AcDb::kForRead );<BR>&nbsp;//文字样式表-〉文字样式表记录-〉打开记录读取<BR>&nbsp;AcDbObjectId idTextStyle;<BR>&nbsp;es = pTST-&gt;getAt("Standard",idTextStyle);<BR>&nbsp;es = pTST-&gt;getAt("Standard",pTSTR,AcDb::kForWrite );<BR>&nbsp;pTSTR-&gt;setFileName("HZTXT");//**** <BR>&nbsp;if(es != Acad::eOk){ <BR>&nbsp;&nbsp;acutPrintf("fail to get the standard text style\n");<BR>&nbsp;}<BR>&nbsp;//////////////////////////////////<BR>&nbsp;pBlockTablew-&gt;close();//关闭块表<BR>&nbsp;<BR>&nbsp;&nbsp;&nbsp; ads_point point;<BR>&nbsp;int ret;&nbsp; <BR>&nbsp;ret = acedGetPoint(NULL,"\n输入文本标注中心点的坐标:",point);<BR>&nbsp;ret= acedCommand(RTSTR, "boundary",RTPOINT ,point, RTSTR, "",0) ;<BR>&nbsp;acutPrintf("\n你选的点坐标为 x = %.3f y = %.3f",point,point);<BR>&nbsp;AcGePoint3d textPosition(point, point, 0.0);<BR>&nbsp;AcGePoint3d atextPosition(point, point, 0.0);<BR>&nbsp;<BR>&nbsp;double textHeight = 10;<BR>&nbsp;double textWidthFactor = 0.8000;<BR>&nbsp;double textRotation = 0.0;<BR>&nbsp;<BR>&nbsp;AcDbText *pText=new AcDbText(textPosition, textString, AcDbObjectId::kNull, textHeight, textRotation);<BR>&nbsp;pText-&gt;setHorizontalMode(AcDb::kTextMid);<BR>&nbsp;pText-&gt;setAlignmentPoint(atextPosition);<BR>&nbsp;pText-&gt;setColorIndex (1); <BR>&nbsp;<BR>&nbsp;pText-&gt;setTextStyle (idTextStyle);<BR>&nbsp;<BR>&nbsp;AcDbObjectId idTxt = AcDbObjectId::kNull ;<BR>&nbsp;pBlockTableRecordw-&gt;appendAcDbEntity(idTxt,pText);<BR>&nbsp;<BR>&nbsp;pTST-&gt;close();//文字样式表<BR>&nbsp;pTSTR-&gt;close();//文字样式表记录<BR>&nbsp;//////////////////////////////////////////////////////////////////////<BR>&nbsp;<BR>&nbsp;AcDbObjectId textId;<BR>&nbsp;pBlockTableRecordw-&gt;appendAcDbEntity(textId, pText); //*<BR>&nbsp;pBlockTableRecordw-&gt;close();<BR>&nbsp;pText-&gt;close();</P>

hourui800720 发表于 2011-7-30 16:19:25

我的问题依旧

hourui800720 发表于 2011-7-30 16:19:57

我的问题依旧
页: [1]
查看完整版本: 关于进行文本标注