lwh-1234 发表于 2005-9-16 11:24:00

请教尺寸标注文本方面的问题!!!

<P>我做了一个自动标注孔尺寸(包括孔径、孔深)的程序,部分代码如下:</P>
<P>&nbsp;double leaderLength=50;<BR>&nbsp;&nbsp;&nbsp;int iDimColor=1; <BR>&nbsp;&nbsp;&nbsp;int iTextColor=1;<BR>&nbsp;&nbsp;&nbsp;AcCmColor color;&nbsp;<BR>&nbsp;&nbsp;&nbsp;char* dimText=="光孔&lt;&gt;";<BR>&nbsp;&nbsp;&nbsp;AcDbDatabase *pcurdb=acdbHostApplicationServices()-&gt;workingDatabase();<BR>&nbsp;&nbsp;&nbsp;AcDbDimStyleTable *pnewdimtable;<BR>&nbsp;&nbsp;&nbsp;pcurdb-&gt;getSymbolTable(pnewdimtable,AcDb::kForWrite);<BR>&nbsp;&nbsp;&nbsp;AcDbDimStyleTableRecord *pnewdimrecord=new AcDbDimStyleTableRecord();<BR>&nbsp;&nbsp;&nbsp;pnewdimrecord-&gt;setDimasz(20);//设置箭头大小<BR>&nbsp;&nbsp;&nbsp;pnewdimrecord-&gt;setDimzin(8);//十进制小数显示时,抑制后续零<BR>&nbsp;&nbsp;&nbsp;pnewdimrecord-&gt;setDimexe(30);//设置尺寸界线超出尺寸线距离为400<BR>&nbsp;&nbsp;&nbsp;pnewdimrecord-&gt;setDimexo(0);//设置尺寸界线的起点偏移量为300<BR>&nbsp;&nbsp;&nbsp;pnewdimrecord-&gt;setDimtxt(30);//设置文字高度<BR>&nbsp;&nbsp;&nbsp;pnewdimrecord-&gt;setDimtad(1);//设置文字位置-垂直为上方,水平默认为居中,不用设置<BR>&nbsp;&nbsp;&nbsp;pnewdimrecord-&gt;setDimgap(10);//设置文字位置-从尺寸线的偏移量<BR>&nbsp;&nbsp;&nbsp;pnewdimrecord-&gt;setDimtih(0);&nbsp; <BR>&nbsp;&nbsp;&nbsp;pnewdimrecord-&gt;setDimtix(1);//设置标注文字始终绘制在尺寸界线之间<BR>&nbsp;&nbsp;&nbsp;pnewdimrecord-&gt;setDimtofl(1);//即使箭头放置于测量点之外,尺寸线也将绘制在测量点之间<BR>&nbsp;&nbsp;&nbsp;pnewdimrecord-&gt;setDimlfac(0.125);<BR>&nbsp;&nbsp;&nbsp;color.setColorIndex(iDimColor); <BR>&nbsp;&nbsp;&nbsp;pnewdimrecord-&gt;setDimclrd(color);&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; //尺寸线颜色 <BR>&nbsp;&nbsp;&nbsp;pnewdimrecord-&gt;setDimclre(color);&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; //尺寸边界线颜色 <BR>&nbsp;&nbsp;&nbsp;color.setColorIndex(iTextColor);&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <BR>&nbsp;&nbsp;&nbsp;pnewdimrecord-&gt;setDimclrt(color);&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; //文字颜色 </P>
<P>&nbsp;&nbsp;&nbsp;AcDbObjectId dimrecordid;<BR>&nbsp;&nbsp;&nbsp;pnewdimtable-&gt;add(dimrecordid,pnewdimrecord);<BR>&nbsp;&nbsp;&nbsp;pnewdimtable-&gt;close();<BR>&nbsp;&nbsp;&nbsp;pnewdimrecord-&gt;close();<BR>&nbsp;<BR>&nbsp;&nbsp;&nbsp;AcGePoint3d Pt1(KD.ZB_X+t-KD.KongJing/2*cos(PI/4.0),KD.ZB_Y+t+KD.KongJing/2*sin(PI/4.0),0); <BR>&nbsp;&nbsp;&nbsp;AcGePoint3d Pt2(KD.ZB_X+t+KD.KongJing/2*cos(PI/4.0),KD.ZB_Y+t-KD.KongJing/2*sin(PI/4.0),0); <BR>&nbsp;&nbsp;&nbsp;&nbsp;<BR>&nbsp;&nbsp;&nbsp;AcDbBlockTable *pBlockTable;//定义块表指针<BR>&nbsp;&nbsp;&nbsp;acdbHostApplicationServices()-&gt;workingDatabase()<BR>&nbsp;&nbsp;&nbsp;-&gt;getSymbolTable(pBlockTable, AcDb::kForRead);<BR>&nbsp;&nbsp;&nbsp;AcDbBlockTableRecord *pBlockTableRecord;<BR>&nbsp;&nbsp;&nbsp;pBlockTable-&gt;getAt(ACDB_MODEL_SPACE, pBlockTableRecord,<BR>&nbsp;&nbsp;&nbsp;AcDb::kForWrite);<BR>&nbsp;&nbsp;&nbsp;pBlockTable-&gt;close();<BR>&nbsp;&nbsp;&nbsp;AcDbDiametricDimension *pDim = new AcDbDiametricDimension(Pt6,Pt7,leaderLength,dimText,dimrecordid);<BR>&nbsp;&nbsp;&nbsp;pDim-&gt;setLeaderLength(20);<BR>&nbsp;&nbsp;&nbsp;AcDbObjectId Id;<BR>&nbsp;&nbsp;&nbsp;pBlockTableRecord-&gt;appendAcDbEntity(Id, pDim);<BR>&nbsp;&nbsp;&nbsp;pBlockTableRecord-&gt;close();<BR>&nbsp;&nbsp;&nbsp;pDim-&gt;close();<BR>&nbsp;&nbsp;}</P>
<P>运行后只标出了孔的直径,形式为“光孔Ф120”。现在我想把孔的深度尺寸也标出来,期望标注形式为“光孔Ф120深a”。孔的深度a可通过读取变量KD.KongShen获得。希望高手指点一下如何实现。</P>

pglyxq 发表于 2005-9-18 13:34:00

lwh-1234 发表于 2005-9-19 09:37:00

<P>我按照下面方法去做:</P>
<P>CString a="光孔&lt;&gt;"+KD.KongJing;<BR>&nbsp;&nbsp;&nbsp;char* dimText=a;</P>
<P>编译提示:</P>
<P>E:\HMBDesigner\HMBDesignerCommands.cpp(1813) : error C2111: pointer addition requires integral operand<BR>E:\HMBDesigner\HMBDesignerCommands.cpp(1814) : error C2440: 'initializing' : cannot convert from 'class CString' to 'char *'</P>

<P>能不能具体介绍一下在这里利用strcat()函数具体怎末作啊!</P>

pglyxq 发表于 2005-9-20 22:28:00

uusky 发表于 2005-9-22 20:41:00

关注中

lwh-1234 发表于 2005-9-26 09:10:00

<P>谢谢<A name=57978><FONT color=#000066><B>pglyxq</B></FONT></A>的提醒,呵呵,是我忘了它们不是同一类型的了,我做了改动:</P>
<P>char* dimText="光孔&lt;&gt;";<BR>&nbsp;&nbsp;&nbsp;CString str;&nbsp;&nbsp;&nbsp;<BR>&nbsp;&nbsp;&nbsp;str.Format("%5.1f",KD.KongShen/8);//double型转换为字符型<BR>&nbsp;&nbsp;&nbsp;CString dimText=CString("光孔&lt;&gt;")+"深"+str;<BR>&nbsp;&nbsp;&nbsp;(char*)(LPCTSTR)dimText;//字符型转换为char*型</P>
<P>还好问题解决了。</P>

hourui800720 发表于 2011-7-30 16:24:10

我也要解决
页: [1]
查看完整版本: 请教尺寸标注文本方面的问题!!!