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