- 积分
- 30299
- 明经币
- 个
- 注册时间
- 2016-9-16
- 在线时间
- 小时
- 威望
-
- 金钱
- 个
- 贡献
-
- 激情
-
|
本帖最后由 fangmin723 于 2021-7-31 12:26 编辑
只有代码,没有演示,就这么干看着不合适,不适合,来上传个演示看看,演示中所有标准均为这几个标注方法创建!!!
- /// <summary>
- /// 将图形添加到图形文件中---本方法为李小科AutoCAD.Net教程封装方法
- /// </summary>
- /// <param name="db">图形数据库</param>
- /// <param name="ent">图形对象</param>
- /// <returns>ObjectId图元名</returns>
- public static ObjectId AddEntityToModelSpace(this Database db, Entity ent)
- {
- //声明ObjectId,用于返回
- ObjectId entId = ObjectId.Null;
- //开启事务处理
- using (Transaction trans = db.TransactionManager.StartTransaction())
- {
- //打开块表
- BlockTable bt = (BlockTable)trans.GetObject(db.BlockTableId, OpenMode.ForRead);
- //打开块表记录
- BlockTableRecord btr = (BlockTableRecord)trans.GetObject(bt[BlockTableRecord.ModelSpace], OpenMode.ForWrite);
- //添加图形到块表记录
- entId = btr.AppendEntity(ent);
- //更新数据信息
- trans.AddNewlyCreatedDBObject(ent, true);
- //提交事务
- trans.Commit();
- }
- return entId;
- }
- /// <summary>
- /// 创建转角标注
- /// </summary>
- /// <param name="pt1">标注起始点</param>
- /// <param name="pt2">标注结束点</param>
- /// <param name="txtpt">文字放置点</param>
- /// <param name="txt">标注内容</param>
- /// <param name="IsH">是否横向</param>
- /// <param name="scal">标注比例</param>
- /// <param name="lfac">标注比例</param>
- /// <param name="dec">标注精度</param>
- /// <returns>图元ObjectId</returns>
- public static ObjectId RotatedDim(Point3d pt1, Point3d pt2, Point3d txtpt, string txt, bool IsH, double scal = 1, double lfac = 1, int dec = 0)
- {
- RotatedDimension dim = new RotatedDimension
- {
- XLine1Point = pt1,
- XLine2Point = pt2,
- DimLinePoint = txtpt,
- TextPosition = txtpt,
- DimensionText = txt,
- Dimdec = dec,
- Dimscale = scal,
- Dimlfac = lfac
- };
- dim.Rotation = IsH ? 0 : Math.PI * 0.5;
- return db.AddEntityToModelSpace(dim);
- }
- /// <summary>
- /// 创建圆弧半径标注
- /// </summary>
- /// <param name="center">圆弧圆心</param>
- /// <param name="startang">圆弧起始角度</param>
- /// <param name="endang">圆弧终点角度</param>
- /// <param name="cpt">标注弦点</param>
- /// <param name="txtpt">标注文字放置点</param>
- /// <param name="dimstr">标注内容</param>
- /// <param name="scal">标注全局比例</param>
- /// <param name="lfac">标注线型比例</param>
- /// <returns>图元ObjectId</returns>
- public static ObjectId ArcRadialDim(Point3d center, double startang, double endang, Point3d cpt, Point3d txtpt, string dimstr, double scal, double lfac)
- {
- RadialDimension rdim = new RadialDimension
- {
- Center = center,
- ChordPoint = cpt,
- DimensionText = dimstr,
- UsingDefaultTextPosition = true,
- LeaderLength = 5,
- Dimscale = scal,
- Dimlfac = lfac,
- TextPosition = txtpt
- };
- ResultBuffer resBuf = new ResultBuffer();
- resBuf.Add(new TypedValue((int)DxfCode.ExtendedDataRegAppName, "ACAD_DSTYLE_DIMRADIAL_EXTENSION"));
- resBuf.Add(new TypedValue((int)DxfCode.ExtendedDataInteger16, 387));
- resBuf.Add(new TypedValue((int)DxfCode.ExtendedDataInteger16, 1));
- resBuf.Add(new TypedValue((int)DxfCode.ExtendedDataInteger16, 388));
- resBuf.Add(new TypedValue((int)DxfCode.ExtendedDataReal, startang));//圆弧的开始角度
- resBuf.Add(new TypedValue((int)DxfCode.ExtendedDataInteger16, 390));
- resBuf.Add(new TypedValue((int)DxfCode.ExtendedDataReal, endang));//圆弧的结束角度
- rdim.XData = resBuf;
- return db.AddEntityToModelSpace(rdim);
- }
- /// <summary>
- /// 创建直径标注
- /// </summary>
- /// <param name="cpt">第一标注点</param>
- /// <param name="fcpt">第二标注点</param>
- /// <param name="txtpt">文字放置点</param>
- /// <param name="scal">标注比例</param>
- /// <param name="lfac">标注线型比例</param>
- /// <param name="dec">标注精度</param>
- /// <returns>图元ObjectId</returns>
- public static ObjectId DiametricDim(Point3d cpt, Point3d fcpt, Point3d txtpt, string dimstr = "<>", double scal = 1, double lfac = 1, int dec = 0)
- {
- DiametricDimension dim = new DiametricDimension
- {
- ChordPoint = cpt,
- FarChordPoint = fcpt,
- TextPosition = txtpt,
- DimensionText = dimstr,
- Dimdec = dec,
- Dimscale = scal,
- Dimlfac = lfac
- };
- return db.AddEntityToModelSpace(dim);
- }
- /// <summary>
- /// 创建直线角度标注
- /// </summary>
- /// <param name="pt1s">起始角度直线起始点</param>
- /// <param name="pt1e">起始角度直线终止点</param>
- /// <param name="pt2s">终止角度直线起始点</param>
- /// <param name="pt2e">终止角度直线终止点</param>
- /// <param name="arcpt">圆弧位置点</param>
- /// <param name="scal">标注比例</param>
- /// <param name="lfac">标注线型比例</param>
- /// <param name="dec">标注精度</param>
- /// <returns>图元ObjectId</returns>
- public static ObjectId AngularDim(Point3d pt1s, Point3d pt1e, Point3d pt2s, Point3d pt2e, Point3d arcpt, double scal = 1, double lfac = 1, int dec = 0)
- {
- LineAngularDimension2 dim = new LineAngularDimension2
- {
- XLine1Start = pt1s,
- XLine1End = pt1e,
- XLine2Start = pt2s,
- XLine2End = pt2e,
- ArcPoint = arcpt,
- Dimdec = dec,
- Dimadec = dec,
- Dimscale = scal,
- Dimlfac = lfac
- };
- return db.AddEntityToModelSpace(dim);
- }
|
本帖子中包含更多资源
您需要 登录 才可以下载或查看,没有账号?注册
x
|