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