尺寸标注用来在项目中显示距离和尺寸的专有元素。
7.2.1 尺寸标注类型
尺寸标注主要有三种类型:线性标注、连续线性标注、角度标注,具体标注对象类见表7-4。
表7-4 尺寸标注对象列表
线性标注对象 | BPDimensionLinear |
---|---|
连续线性标注对象 | BPDimensionLinearContinuous |
角度标注对象 | BPDimension3PAngle |
7.2.2 尺寸标注样式
对于所有尺寸标注,可通过标注样式类BPDimensionStyle
设置标注样式,常用接口见表7-5,可根据需要设置相应的样式。
表7-5 尺寸标注样式接口
属性/方法 | 描述 |
---|---|
int Dimatfit | 文字和箭头 1-文字 2-箭头 3-文字或箭头 |
bool DimisShow1 | 尺寸界限1隐藏状态 |
bool DimisShow2 | 尺寸界限2隐藏状态 |
string DimName | 样式名称 |
int Dimposition | 文字位置 0-居中 1-上部 2-外部 |
int Dimpdec | 主单位-线性标注-单位格式,0-8 |
double Dimrnd | 线性标注-舍入 |
double Dimscale | 标注特征比例 |
double Dimtxt | 文字高度 |
double Dimgap | 文字位置-从尺寸线偏移 |
double Dimdle | 尺寸线超出尺寸界线的距离 |
double Dimexe | 尺寸界线超出尺寸线的距离 |
double Dimasz | 符号和箭头-箭头大小 |
double Dimexo | 尺寸界限-起点偏移量 |
bool Dimtix | 文字始终保持在尺寸界线之间 |
double DimtxtWith | 文字宽度 |
double Dimtsz | 代替箭头的小斜线的尺寸 |
BPGeSymbology Dimclrt | 文字颜色 |
BPGeSymbology Dimclrd | 尺寸线颜色 |
BPGeSymbology Dimclre | 尺寸界线颜色 |
create(string name, BPDocument doc) | 通过名称和项目创建标注样式 |
add() | 增加标注样式 |
deleteDim(string oldname, BPDocument doc) | 通过名称删除标注样式 |
getByName(string name, BPDocument doc) | 通过名称获取标注样式 |
replace(string oldname, BPDocument doc) | 修改标注样式 |
7.2.3 尺寸标注创建
尺寸标注创建的一般步骤为:如果没有符合需求的标注样式需先创建标注样式;然后通过尺寸标注的构造函数创建标注对象;设置标注对象的标注样式;最后根据需求使用该标注对象。
- 线性标注
示例代码7-3以绘制线段为例,在绘制线段过程中动态显示线性标注,示例代码中根据传入的点,绘制两点线段的线性标注。
BPDocument doc = BPApplication.singleton().activeDocument; BPModel model = doc.modelManager.activeModel;
//先要创建一个标注样式
BPDimensionStyle dimstyle = BPDimensionStyle.create("标注样式", doc);
dimstyle.add();
dimstyle.Dimposition = 1;//控制文字位置,1-上方
dimstyle.DimisShow1 = true; //尺寸界线1是否显示
dimstyle.DimisShow2 = true; //尺寸界线2是否显示
dimstyle.Dimdec = 0;
dimstyle.Dimrnd = 0;//舍入
dimstyle.Dimscale = 1;//全局比例
dimstyle.Dimtxt = 1000;//文字高度
dimstyle.Dimgap = 20;//文字偏移
dimstyle.Dimdle = 200;//尺寸线超出尺寸界线的距离
dimstyle.Dimexe = 200;//尺寸界线超出尺寸线的距离
dimstyle.Dimexo = 0.1;//尺寸界线-起点偏移量
dimstyle.Dimasz = 300;//符号和箭头-箭头大小
dimstyle.Dimtsz = 300;
dimstyle.Dimatfit = 3; // 1-箭头
dimstyle.Dimtix = true;
dimstyle.DimtxtWidth = 5;
BPGeSymbology symb = new BPGeSymbology { color = System.Drawing.Color.Red, style = 0, weight = 1 };
BPGeSymbology symb0 = new BPGeSymbology { color = System.Drawing.Color.Blue, style = 0, weight = 1 };
BPGeSymbology symb1 = new BPGeSymbology { color = System.Drawing.Color.Green, style = 0, weight = 1 };
BPGeSymbology symb2 = new BPGeSymbology { color = System.Drawing.Color.Green, style = 0, weight = 1 };
dimstyle.Dimclrt = symb;//文宁颜色
dimstyle.Dimclrd = symb1;//尺寸线颜色
dimstyle.Dimclre = symb2;//尺寸界线颜色
int status = dimstyle.replace("标注样式", doc);
BPPlacement placement = new BPPlacement();
GePoint3d xLine1Point = new GePoint3d(0, 0, 0);
GePoint3d xLine2Point = new GePoint3d(2000,0, 0); GePoint3d textPos = new GePoint3d(1000,1000,0);
string str = "测试标注文宁";
BPDimensionLinear linearDim = new BPDimensionLinear(placement,textPos, xLine1Point,xLine2Point, textPos,str);
linearDim.dimstyle = "标注样式";
BIMBaseCS.BPStatus sta = linearDim.addToDocument(model);
代码7-3 线性标注创建(代码片段)
线性标注效果如图所示:

图7-2 线性标注范例效果图
- 连续线性标注
示例代码7-4以连续绘制线段为例,根据传入的点,绘制连续线性标注。
BPDocument doc = BPApplication.singleton().activeDocument; BPModel model = doc.modelManager.activeModel;
//先要创建一个标注样式
BPDimensionStyle dimstyle = BPDimensionStyle.create("标注样式",doc);
dimstyle.add();
dimstyle.Dimposition = 1;//控制文字位置,1-上方
dimstyle.DimisShow1 = true; //尺寸界线1是否显示
dimstyle.DimisShow2 = true;//尺寸界线2是否显示
dimstyle.Dimdec = 0;
dimstyle.Dimrnd = 0;//舍入
dimstyle.Dimscale = 1;//全局比例
dimstyle.Dimtxt = 1000;//文字高度
dimstyle.Dimgap = 20;//文字偏移
dimstyle.Dimdle = 200;//尺寸线超出尺寸界线的距离
dimstyle.Dimexe = 200;//尺寸界线超出尺寸线的距离
dimstyle.Dimexo = 0.1;//尺寸界线-起点偏移量
dimstyle.Dimasz = 300;//符号和箭头-箭头大小
dimstyle.Dimtsz = 300;
dimstyle.Dimatfit = 1; // 1-箭头
dimstyle.Dimtix = true;
BPGeSymbology symb = new BPGeSymbology { color = System.Drawing.Color.Red, style = 0, weight = 1 };
BPGeSymbology symb1 = new BPGeSymbology { color = System.Drawing.Color.Blue, style = 0, weight = 1 };
BPGeSymbology symb2 = new BPGeSymbology { color = System.Drawing.Color.Green, style = 0, weight = 1 };
dimstyle.Dimclrt = symb; //文字颜色
dimstyle.Dimclrd = symb1; //尺寸线颜i色
dimstyle.Dimclre = symb2; // 尺寸界线颜色
int status = dimstyle.replace("标注样式", doc);
BPPlacement placement = new BPPlacement();
GePoint3d xLine1Point = new GePoint3d(0, 0, 0);
GePoint3d xLine2Point = new GePoint3d(2000, 0, 0);
GePoint3d xLine3Point = new GePoint3d(2500, 0, 0);
GePoint3d definedPos = new GePoint3d(2500, 1000, 0);
string str = "测试标注文字";
BPDimensionLinearContinuous linearDim = new BPDimensionLinearContinuous();
linearDim.dimstyle = "标注样式";
List<GePoint3d> pts = new List<GePoint3d>();
pts.Add(xLine1Point);
pts.Add(xLine2Point);
pts.Add(xLine3Point);
linearDim.xlinePts = pts;
List<string> str1 = new List<string>(){ "<>","<>" };
linearDim.multiDimText = str1;
BIMBaseCS.BPStatus sta = linearDim.addToDocument(model);//文字进行避让
int sta2 = linearDim.setGeometryAvoided(model);
代码7-4 连续线性标注创建(代码片段)
连续线性标注效果如图所示:

图7-3 连续线性标注范例效果图
- 弧线、角度标注
示例代码7-5以绘制弧线为例,在绘制线段过程中动态显示弧长或角度标注,示例代码中根据传入的弧线的起点、终点、弧上点确定标注。
BPDocument doc = BPApplication.singleton().activeDocument; BPModel model = doc.modelManager.activeModel;
//先要创建一个标注样式
BPDimensionStyle dimstyle = BPDimensionStyle.create("标注样式", doc);
dimstyle.add();
dimstyle.Dimposition = 1;//控制文字位置,1-上方
dimstyle.DimisShow1 = true;//尺寸界线Ⅰ是否显示
dimstyle.DimisShow2 = true;//尺寸界线2是否显示
dimstyle.Dimdec = 0;
dimstyle.Dimrnd = 0;//舍入
dimstyle.Dimscale = 1;//全局比例
dimstyle.Dimtxt = 300;//文字高度
dimstyle.Dimgap = 20;//文字偏移
dimstyle.Dimdle = 200;//尺寸线超出尺寸界线的距离
dimstyle.Dimexe = 200;//尺寸界线超出尺寸线的距离
dimstyle.Dimexo = 0.1;//尺寸界线-起点偏移量
dimstyle.Dimasz = 300;//符号和箭头-箭头大小
dimstyle.Dimtsz = 300;
dimstyle.Dimatfit = 1; // 1-箭头
dimstyle.Dimtix = true;
BPGeSymbology symb = new BPGeSymbology { color = System.Drawing.Color.Red, style = 0, weight = 1 };
BPGeSymbology symb1 = new BPGeSymbology { color = System.Drawing.Color.Blue, style = 0, weight = 1 };
BPGeSymbology symb2 = new BPGeSymbology { color = System.Drawing.Color.Green, style = 0, weight = 1 };
dimstyle.Dimclrt = symb;//文宁颜色
dimstyle.Dimclrd = symb1 ;//尺寸线颜色
dimstyle.Dimclre = symb2;//尺寸界线颤色
int status = dimstyle.replace("标注样式", doc);
BPPlacement placement = new BPPlacement();
GePoint3d centerPos = new GePoint3d(0, 0,0);
GePoint3d StartPoint = new GePoint3d(2000, 0,0);
GePoint3d EndPoint = new GePoint3d(0, 2500,0);
GeVec3d dirVec = GeVec3d.createByStartEndNormalize(StartPoint, EndPoint);
dirVec.rotate2D(Math.PI / 2) ;
GePoint3d definedPos = StartPoint + dirVec * 200;
BPDimension3PAngle AngleDim = new BPDimension3PAngle();
AngleDim.dimstyle ="标注样式";
AngleDim.centerPoint = centerPos;
AngleDim.arcStartPoint = StartPoint;AngleDim.arcEndPoint = EndPoint;
AngleDim.arcDefinePoint = definedPos;
BIMBaseCS.BPStatus sta = AngleDim.addToDocument(model);
代码7-5 连续线性标注创建(代码片段)
角度标注效果如图所示:

图7-4 角度标注范例效果图