天气与日历 切换到窄版

 找回密码
 立即注册
中国膜结构网
十大进口膜材评选 十大国产膜材评选 十大膜结构设计评选 十大膜结构公司评选
查看: 68|回复: 0

ObjectARX_尺寸标注

[复制链接]

该用户从未签到

主题

0

回帖

2912

积分

管理员

积分
2912
发表于 2024-6-22 09:46:18 | 显示全部楼层 |阅读模式
[code]尺寸标注:转角标注、对齐标注、角度标注、半径标注、直径标注和坐标标注。

需要头文件#include " dbdim.h "

(1)对齐标注:AcDbAlignedDimension类

构造函数定义为:

AcDbAlignedDimension( const AcGePoint3d& xLine1Point, const AcGePoint3d& xLine2Point, const AcGePoint3d& dimLinePoint, const ACHAR * dimText = NULL, AcDbObjectId dimStyle = AcDbObjectId::kNull);
第一个参数:xLine1Point:第一条尺寸边界线的起点;第二个参数:xLine2Point:第二条尺寸边界线的起点:第三个参数:dimLinePoint:通过尺寸线的一点;第四个参数:dimText :标注文字;第五个参数:dimStyle :样式。

AcDbObjectId CCreateEnt::CreateDimAligned(const AcGePoint3d& pt1,const AcGePoint3d& pt2, const AcGePoint3d& ptLine,const AcGeVector3d& vecOffset,const char* dimText)
{
AcDbAlignedDimension *pDim = new AcDbAlignedDimension(pt1, pt2,ptLine, dimText,AcDbObjectId::kNull);
AcDbObjectId dimensionId = CCreateEnt::PostToModelSpace(pDim);

// 打开已经创建的标注,对文字的位置进行修改
AcDbEntity *pEnt = NULL;
Acad::ErrorStatus es = acdbOpenAcDbEntity(pEnt, dimensionId, AcDb::kForWrite);

AcDbAlignedDimension *pDimension = AcDbAlignedDimension::cast(pEnt);
if (pDimension != NULL)
{
// 移动文字位置前,设置文字和尺寸线移动时的关系(这里指定为:尺寸线不动,在文字和尺寸线之间加箭头)
pDimension->setDimtmove(1);

// 根据偏移向量修正文字插入点的位置
AcGePoint3d ptText = pDimension->textPosition();
ptText = ptText + vecOffset;
pDimension->setTextPosition(ptText);//尺寸文本的移动
}
pEnt->close();
return dimensionId;
}
注:移动标注文字必须在将其添加到模型空间之后进行。

(2)转角标注:AcDbRotatedDimension类

构造函数定义为:

AcDbRotatedDimension(double rotation, const AcGePoint3d& xLine1Point, const AcGePoint3d& xLine2Point, const AcGePoint3d& dimLinePoint, const ACHAR * dimText = NULL, AcDbObjectId dimStyle = AcDbObjectId::kNull);
第一个参数:rotation:标注的旋转角度;第二个参数:xLine1Point:第一条尺寸边界线的起点;第三个参数:xLine2Point:第二条尺寸边界线的起点;第四个参数:dimLinePoint:通过尺寸线的一点;第五个参数:dimText :标注文字; 第五个参数:dimStyle : 样式。

AcDbObjectId CCreateEnt::CreateDimRotated(const AcGePoint3d& pt1,const AcGePoint3d& pt2, const AcGePoint3d& ptLine,double rotation, const char* dimText,AcDbObjectId dimStyle)
{
AcDbRotatedDimension *pDim = new AcDbRotatedDimension(rotation,pt1, pt2, ptLine, dimText, dimStyle);
return CCreateEnt::PostToModelSpace(pDim);
}
(3)半径标注:AcDbRadialDimension类

构造函数定义为:

AcDbRadialDimension( const AcGePoint3d& center, const AcGePoint3d& chordPoint,double leaderLength, const ACHAR *  dimText = NULL,AcDbObjectId dimStyle = AcDbObjectId::kNull);
第一个参数:center:标注曲线的中心点;第二个参数:chordPoint:引线附着的坐标;第三个参数:leaderLength:引线长度;第四个参数:dimText :标注文字; 第五个参数:dimStyle : 样式。

//根据相对极坐标来确定一个点
AcGePoint3d CCalculation::PolarPoint(const AcGePoint3d& pt, double angle,double distance)
{
ads_point ptForm, ptTo;
ptForm[X] = pt.x;
ptForm[Y] = pt.y;
ptForm[Z] = pt.z;

acutPolar(ptForm, angle, distance, ptTo);
return asPnt3d(ptTo);
}

AcDbObjectId CCreateEnt::CreateDimRadial(const AcGePoint3d& ptCenter,double radius, double angle, double leaderLength)
{
AcGePoint3d ptChord = CCalculation::PolarPoint(ptCenter, angle,radius);
return CCreateEnt::CreateDimRadial(ptCenter, ptChord,leaderLength);
}
(4)直径标注:AcDbDiametricDimension类

构造函数定义为:

AcDbDiametricDimension(const AcGePoint3d& chordPoint,const AcGePoint3d& farChordPoint,double leaderLength, const ACHAR * dimText = NULL, AcDbObjectId  dimStyle = AcDbObjectId::kNull);
第一个参数:chordPoint:第二个参数:farChordPoint:标注直径的两个端点;第三个参数:leaderLength:引线长度; 第四个参数:dimText :标注文字; 第五个参数:dimStyle : 样式。

AcDbObjectId CCreateEnt::CreateDimDiametric(const AcGePoint3d& ptCenter,double radius, double angle, double leaderLength)
{
// 计算标注通过点的位置
AcGePoint3d ptChord1, ptChord2;
ptChord1 = CCalculation::PolarPoint(ptCenter, angle, radius);
ptChord2 = CCalculation::PolarPoint(ptCenter,angle + CCalculation::PI(), radius);
return CCreateEnt::CreateDimDiametric(ptChord1, ptChord2,leaderLength);
}
(5)角度标注:AcDb2LineAngularDimension 类 AcDb3PointAngularDimension类

构造函数定义为:

AcDb2LineAngularDimension( const AcGePoint3d& xLine1Start,const AcGePoint3d& xLine1End,const AcGePoint3d& xLine2Start,const AcGePoint3d& xLine2End, const AcGePoint3d& arcPoint, const ACHAR * dimText = NULL,AcDbObjectId dimStyle = AcDbObjectId::kNull);
第一个参数:xLine1Start:第一条尺寸边界线的起点;第二个参数:xLine1End:第一条尺寸边界线的终点:第三个参数:xLine2Start:第二条尺寸边界线的起点;第四个参数:xLine2End:第二条尺寸边界线的终点;第五个参数:arcPoint:圆弧点;第六个参数:dimText :标注文字; 第七个参数:dimStyle : 样式。

AcDb3PointAngularDimension(const AcGePoint3d& centerPoint, const AcGePoint3d& xLine1Point, const AcGePoint3d& xLine2Point, const AcGePoint3d& arcPoint, const ACHAR *dimText = NULL,AcDbObjectId dimStyle = AcDbObjectId::kNull);
  第一个参数:centerPoint:中心点;第二个参数:xLine1Point:第一条尺寸边界线的起点;第三个参数:xLine2Point:第二条尺寸边界线的起点;第四个参数:arcPoint:圆弧点;第五个参数:dimText :标注文字; 第六个参数:dimStyle : 样式。

AcDbObjectId CCreateEnt::CreateDim2LineAngular(const AcGePoint3d& ptStart1,const AcGePoint3d& ptEnd1, const AcGePoint3d& ptStart2,const AcGePoint3d& ptEnd2, const AcGePoint3d& ptArc,const char* dimText, AcDbObjectId dimStyle)
{
AcDb2LineAngularDimension *pDim = new AcDb2LineAngularDimension(ptStart1, ptEnd1, ptStart2, ptEnd2, ptArc, dimText, dimStyle);
return CCreateEnt::PostToModelSpace(pDim);
}

AcDbObjectId CCreateEnt::CreateDim3PtAngular(const AcGePoint3d& ptCenter,const AcGePoint3d& ptEnd1, const AcGePoint3d& ptEnd2,const AcGePoint3d& ptArc, const char* dimText,
AcDbObjectId dimStyle)
{
AcDb3PointAngularDimension *pDim = new AcDb3PointAngularDimension(ptCenter, ptEnd1, ptEnd2, ptArc, dimText, dimStyle);
return CCreateEnt::PostToModelSpace(pDim);
}
(6)坐标标注:AcDbOrdinateDimension类

AcDbOrdinateDimension(Adesk::Boolean useXAxis, const AcGePoint3d& definingPoint, const AcGePoint3d& leaderEndPoint,const ACHAR * dimText = NULL,AcDbObjectId  dimStyle  = AcDbObjectId::kNull);
第一个参数:useXAxis:是否是 X 轴标注;第二个参数:definingPoint:标注箭头的起始位置;第三个参数:leaderEndPoint:标注箭头的终止位置; 第四个参数:dimText :标注文字; 第五个参数:dimStyle : 样式。

AcDbObjectIdArray CCreateEnt::CreateDimOrdinate(const AcGePoint3d& ptDef,const AcGePoint3d& ptTextX, const AcGePoint3d& ptTextY)
{
AcDbObjectId dimId  = CCreateEnt::CreateDimOrdinate(Adesk::kTrue, ptDef,ptTextX);
AcDbObjectIdArray dimIds;
dimIds.append(dimId);
dimId = CCreateEnt::CreateDimOrdinate(Adesk::kFalse, ptDef,ptTextY);
dimIds.append(dimId);
return dimIds;
}

AcDbObjectIdArray CCreateEnt::CreateDimOrdinate(const AcGePoint3d& ptDef,const AcGeVector3d& vecOffsetX, const AcGeVector3d&vecOffsetY)
{
AcGePoint3d ptTextX = ptDef + vecOffsetX;
AcGePoint3d ptTextY = ptDef + vecOffsetY;
return CCreateEnt::CreateDimOrdinate(ptDef, ptTextX, ptTextY);
}
看一下整体调用:

//根据相对直角坐标来计算一个点的位置:
AcGePoint3d CCalculation::RelativePoint(const AcGePoint3d& pt,double x, double y)
{
AcGePoint3d ptReturn(pt.x + x, pt.y + y, pt.z);
return ptReturn;
}

void ZffCHAP2AddDimension()
{
// 指定起始点位置
AcGePoint3d pt1(200, 160, 0);
AcGePoint3d pt2= CCalculation::RelativePoint(pt1, -40, 0);
AcGePoint3d pt3 = CCalculation::PolarPoint(pt2,7 * CCalculation::PI() / 6, 20);
AcGePoint3d pt4 = CCalculation::RelativePoint(pt3, 6, -10);
AcGePoint3d pt5 = CCalculation::RelativePoint(pt1, 0, -20);

// 绘制外轮廓线
CCreateEnt::CreateLine(pt1, pt2);
CCreateEnt::CreateLine(pt2, pt3);
CCreateEnt::CreateLine(pt3, pt4);
CCreateEnt::CreateLine(pt4, pt5);
CCreateEnt::CreateLine(pt5, pt1);

// 绘制圆形
AcGePoint3d ptCenter1, ptCenter2;
ptCenter1 = CCalculation::RelativePoint(pt3, 16, 0);
ptCenter2 = CCalculation::RelativePoint(ptCenter1, 25, 0);
CCreateEnt::CreateCircle(ptCenter1, 3);
CCreateEnt::CreateCircle(ptCenter2, 4);

AcGePoint3d ptTemp1, ptTemp2;

// 转角标注:水平标注
ptTemp1 = CCalculation::RelativePoint(pt1, -20, 3);
CCreateEnt::CreateDimRotated(pt1, pt2, ptTemp1, 0);

// 转角标注:垂直标注
ptTemp1 = CCalculation::RelativePoint(pt1, 4, 10);
CCreateEnt::CreateDimRotated(pt1, pt5, ptTemp1,CCalculation::PI() / 2);

// 转角标注
ptTemp1 = CCalculation::RelativePoint(pt3, -3, -6);
CCreateEnt::CreateDimRotated(pt3, pt4, ptTemp1,7 * CCalculation::PI() / 4);

// 对齐标注
ptTemp1 = CCalculation::RelativePoint(pt2, -3, 4);
CCreateEnt::CreateDimAligned(pt2, pt3, ptTemp1,AcGeVector3d(4, 10, 0), "new position");

// 角度标注
ptTemp1 = CCalculation::RelativePoint(pt5, -5, 5);
CCreateEnt::CreateDim3PtAngular(pt5, pt1, pt4, ptTemp1);

// 半径标注
ptTemp1 = CCalculation::PolarPoint(ptCenter1,CCalculation::PI() / 4, 3);
CCreateEnt::CreateDimRadial(ptCenter1, ptTemp1, -3);

// 直径标注
ptTemp1 = CCalculation::PolarPoint(ptCenter2,CCalculation::PI() / 4, 4);
ptTemp2 = CCalculation::PolarPoint(ptCenter2,CCalculation::PI() / 4, -4);
CCreateEnt::CreateDimDiametric(ptTemp1, ptTemp2, 0);

// 坐标标注
CCreateEnt::CreateDimOrdinate(ptCenter2, AcGeVector3d(0, -10, 0),AcGeVector3d(10, 0, 0));
}
AcDbDimension::setDimensionText():设置尺寸文本的内容。[/code]

 

 

 

 

ObjectARX_尺寸标注
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

QQ|Archiver|中国膜结构网|中国膜结构协会|进口膜材|国产膜材|ETFE|PVDF|PTFE|设计|施工|安装|车棚|看台|污水池|中国膜结构网_中国空间膜结构协会

GMT+8, 2024-11-1 15:31 , Processed in 0.155872 second(s), 23 queries .

Powered by Discuz! X3.5

© 2001-2024 Discuz! Team.

快速回复 返回顶部 返回列表