zenggq 发表于 2005-9-2 14:21:00

贴个尺寸标注的例子

<P>#include &lt;migrtion.h &gt;</P>
<P>#include &lt;dbents.h&gt;</P>
<P>void blade2d();</P>
<P>{</P>
<P>&nbsp;AcDbLine *pLn1;<BR>&nbsp;AcDbObjectId lineId1;<BR>&nbsp;AcDbObjectId dimId1,dimId2;<BR>&nbsp;AcGePoint3d cp,cp1,cp2,dp1,dp2,dp3;<BR>&nbsp;AcDbEntity *pEnt;<BR>&nbsp;AcDbAlignedDimension *pDimAli1;&nbsp;</P>
<P>&nbsp;cp1.x=cp2.x=cp1.y=0;<BR>&nbsp;cp2.y=120;<BR>&nbsp;cp1.z=cp2.z=cp.z=0;</P>
<P>&nbsp;pLn1=new AcDbLine(cp1,cp2);<BR><BR>&nbsp;lineId1=AddEntityToDbs(1,pLn1);&nbsp; //AddEntityToDbs为自定义的函数,作用是将直线</P>
<P>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;// 加到块表记录中去<BR>&nbsp;&nbsp;pLn1-&gt;close();<BR></P>
<P>&nbsp;acdbOpenObject(pEnt,lineId1,AcDb::kForRead);<BR>//设置尺寸标注样式<BR>&nbsp;AcDbObjectId dimStyleId=defineDimStyle();<BR>//将该尺寸标注样式设置为当前使用的标注样式<BR>&nbsp;acdbCurDwg()-&gt;setDimstyle(dimStyleId);<BR>&nbsp;<BR>//尺寸标注(先竖后横)<BR>&nbsp;pLn1=AcDbLine::cast(pEnt);<BR>&nbsp;dp1=pLn1-&gt;startPoint();<BR>&nbsp;dp2=pLn1-&gt;endPoint();<BR>&nbsp;dp3.x=dp2.x-8;<BR>&nbsp;dp3.y=dp2.y;<BR>&nbsp;dp3.z=0;<BR>&nbsp;pLn1-&gt;close();<BR>&nbsp;pEnt-&gt;close();<BR>&nbsp;pDimAli1=new AcDbAlignedDimension(dp1,dp2,dp3,NULL,dimStyleId);<BR>//或者直接用下面的代码也可以<BR>//&nbsp;dp3.set(-8,0,0);<BR>//&nbsp;pDimAli1=new AcDbAlignedDimension(ulp,llp,dp3,NULL,AcDbObjectId::kNull);<BR>&nbsp;dimId1=AddEntityToDbs(2,pDimAli1);<BR>&nbsp;pDimAli1-&gt;close();</P>
<P>}</P>
<P><BR>AcDbObjectId CShowGraphDlg::defineDimStyle()<BR>{<BR>&nbsp;AcDbDimStyleTable *pDimStyleTbl;<BR>&nbsp;AcDbObjectId dimStyleId;</P>
<P>&nbsp;acdbCurDwg()-&gt;getDimStyleTable(pDimStyleTbl,AcDb::kForRead);&nbsp;<BR>//等价于acdbHostApplicationServices()-&gt;workingDatabase()-&gt;getDimStyleTable(pDimStyleTbl,AcDb::kForWrite);<BR>&nbsp;AcDbDimStyleTableRecord *pDimStyleTblRcd;<BR>//当存在着NewDim标注样式时,我们不必再进行修改设置,只要得到其ID即可,不存在才进行设置修改工作<BR>//另外这样也绕过了对当前标注样式进行修改无效的问题<BR>&nbsp;if(Acad::eOk!=pDimStyleTbl-&gt;getAt("NewDim",dimStyleId,AcDb::kForWrite))<BR>&nbsp;{<BR>&nbsp;&nbsp;pDimStyleTbl-&gt;upgradeOpen();<BR>&nbsp;&nbsp;pDimStyleTblRcd=new AcDbDimStyleTableRecord;<BR>//设置尺寸标注样式表记录名<BR>&nbsp;&nbsp;pDimStyleTblRcd-&gt;setName("NewDim");<BR>//调用设置尺寸变量函数<BR>&nbsp;&nbsp;setDimVar(pDimStyleTblRcd);<BR>//添加新的尺寸标注样式表记录<BR>&nbsp;&nbsp;pDimStyleTbl-&gt;add(dimStyleId,pDimStyleTblRcd);<BR>&nbsp;&nbsp;pDimStyleTblRcd-&gt;close();<BR>&nbsp;}<BR>&nbsp;pDimStyleTbl-&gt;close();<BR>&nbsp;return dimStyleId;<BR>}</P>
<P>void CShowGraphDlg::setDimVar(AcDbDimStyleTableRecord *pDimStyleTblRcd)<BR>{<BR>&nbsp;pDimStyleTblRcd-&gt;setDimasz(3);&nbsp;&nbsp;//箭头长度为3<BR>&nbsp;pDimStyleTblRcd-&gt;setDimexe(3);&nbsp;&nbsp;//尺寸界线在标注线上方延伸量为3<BR>&nbsp;pDimStyleTblRcd-&gt;setDimexo(0);&nbsp;&nbsp;//尺寸界线起点偏移量为0<BR>//&nbsp;pDimStyleTblRcd-&gt;setDimdli(6);&nbsp;&nbsp;//标注线间距为6<BR>&nbsp;pDimStyleTblRcd-&gt;setDimdsep(0);&nbsp;&nbsp;//采用逗点作小数分隔符<BR>&nbsp;pDimStyleTblRcd-&gt;setDimtad(1);&nbsp;&nbsp;//文字位于标注线上方<BR>&nbsp;pDimStyleTblRcd-&gt;setDimtih(0);&nbsp;&nbsp;//尺寸界线内侧的文字水平放置<BR>&nbsp;pDimStyleTblRcd-&gt;setDimtoh(0);&nbsp;&nbsp;//尺寸界线外侧的文字水平放置<BR>&nbsp;pDimStyleTblRcd-&gt;setDimtxt(4);&nbsp;&nbsp;//文字尺寸高度为4<BR>&nbsp;pDimStyleTblRcd-&gt;setDimgap(1);&nbsp;&nbsp;//标注线与文字间距为1<BR>&nbsp;pDimStyleTblRcd-&gt;setDimdec(1);&nbsp;&nbsp;//小数位数<BR>&nbsp;pDimStyleTblRcd-&gt;setDimtix(1);&nbsp;&nbsp;//将文字放置于尺寸界线内侧<BR>&nbsp;pDimStyleTblRcd-&gt;setDimtofl(1);&nbsp;&nbsp;//强制在尺寸界线内侧画标注线<BR>//调用取得文字样式ID号的函数<BR>&nbsp;AcDbObjectId styleId=getTextStyleId();<BR>&nbsp;pDimStyleTblRcd-&gt;setDimtxsty(styleId);&nbsp;&nbsp;//设置文字样式<BR>}</P>
<P>AcDbObjectId CShowGraphDlg::getTextStyleId()<BR>{<BR>&nbsp;AcDbObjectId styleId;<BR>&nbsp;AcDbTextStyleTable *pTextStyleTbl;</P>
<P>&nbsp;acdbCurDwg()-&gt;getTextStyleTable(pTextStyleTbl,AcDb::kForWrite);&nbsp;<BR>&nbsp;if(Acad::eOk!=pTextStyleTbl-&gt;getAt("DimTextStyle",styleId))<BR>&nbsp;{<BR>&nbsp;&nbsp;AcDbTextStyleTableRecord *pTextStyleTblRcd=new AcDbTextStyleTableRecord;<BR>//设置字体样式表记录名<BR>&nbsp;&nbsp;pTextStyleTblRcd-&gt;setName("DimTextStyle");<BR>//设置字体文件名<BR>&nbsp;&nbsp;pTextStyleTblRcd-&gt;setFileName("samplex");<BR>//设置字体宽度比例为0.7<BR>&nbsp;&nbsp;pTextStyleTblRcd-&gt;setXScale(0.7);<BR>//添加字体样式表记录<BR>&nbsp;&nbsp;pTextStyleTbl-&gt;add(styleId,pTextStyleTblRcd);<BR>&nbsp;&nbsp;pTextStyleTblRcd-&gt;close();<BR>&nbsp;}<BR>&nbsp;pTextStyleTbl-&gt;close();<BR>&nbsp;return styleId;<BR>}</P>
<P>呵呵,很多代码也是参考的他人的</P>
<P>偶是小菜,有什么错误之处,还请大侠别取笑偶!</P>

uusky 发表于 2005-9-7 10:30:00

<P>问下:error C2653: 'CShowGraphDlg' : is not a class or namespace name</P>
<P>这个错误怎么改!</P>

zyxc1981 发表于 2005-9-19 15:07:00

~~

uusky 发表于 2005-9-20 15:12:00

<P>方便的话把调试程序给我一份可一吗?谢谢</P>
<P>xlgis@hotmail.com</P>

lyhnjuct 发表于 2006-2-17 09:58:00

错误多多.

hourui800720 发表于 2011-7-30 16:44:42

内容简介内容简介

hourui800720 发表于 2011-7-30 17:07:34

有深度,有内涵,我不会
页: [1]
查看完整版本: 贴个尺寸标注的例子