ObjectARX_尺寸標註

尺寸標註:轉角標註、對齊標註、角度標註、半徑標註、直徑標註和座標標註。app

須要頭文件#include " dbdim.h "函數

(1)對齊標註:AcDbAlignedDimension類3d

構造函數定義爲:code

AcDbAlignedDimension( const AcGePoint3d& xLine1Point, const AcGePoint3d& xLine2Point, const AcGePoint3d& dimLinePoint, const ACHAR * dimText = NULL, AcDbObjectId dimStyle = AcDbObjectId::kNull);

第一個參數:xLine1Point:第一條尺寸邊界線的起點;第二個參數:xLine2Point:第二條尺寸邊界線的起點:第三個參數:dimLinePoint:經過尺寸線的一點;第四個參數:dimText :標註文字;第五個參數:dimStyle :樣式。orm

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;
}

注:移動標註文字必須在將其添加到模型空間以後進行。it

(2)轉角標註:AcDbRotatedDimension類io

構造函數定義爲:ast

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 : 樣式。class

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():設置尺寸文本的內容。

相關文章
相關標籤/搜索