本帖转载于:AutoCAD.Net圆弧半径标注延长线 - 程序园 (voidcn.com)(略有改动)
    带这种延长线的.png

    1. #region 注册RegApp
    2. public static void CheckRegApp(string regapptablename)
    3. {
    4. Database db = HostApplicationServices.WorkingDatabase;
    5. using (Transaction trans = db.TransactionManager.StartTransaction())
    6. {
    7. RegAppTable appTbl = trans.GetObject(db.RegAppTableId, OpenMode.ForWrite) as RegAppTable;
    8. if (!appTbl.Has(regapptablename))
    9. {
    10. RegAppTableRecord appTblRcd = new RegAppTableRecord();
    11. appTblRcd.Name = regapptablename;
    12. appTbl.Add(appTblRcd);
    13. trans.AddNewlyCreatedDBObject(appTblRcd, true);
    14. }
    15. trans.Commit();
    16. }
    17. return;
    18. }
    19. #endregion
    20. [CommandMethod("mydra")]
    21. public static void mydra()
    22. {
    23. // 获取当前数据库
    24. Document acDoc = Application.DocumentManager.MdiActiveDocument;
    25. Database acCurDb = acDoc.Database;
    26. // Start a transaction启动事务
    27. using (Transaction acTrans = acCurDb.TransactionManager.StartTransaction())
    28. {
    29. // Open the Block table for read以读模式打开块表
    30. BlockTable acBlkTbl;
    31. acBlkTbl = acTrans.GetObject(acCurDb.BlockTableId,
    32. OpenMode.ForRead) as BlockTable;
    33. // Open the Block table record Model space for write
    34. // 以写模式打开块表记录ModelSpace
    35. BlockTableRecord acBlkTblRec;
    36. acBlkTblRec = acTrans.GetObject(acBlkTbl[BlockTableRecord.ModelSpace],
    37. OpenMode.ForWrite) as BlockTableRecord;
    38. // Create the radial dimension创建半径标注
    39. RadialDimension acRadDim = new RadialDimension();
    40. acRadDim.Center = new Point3d(0, 0, 0); //圆心
    41. acRadDim.ChordPoint = new Point3d(5, 5, 0); //标注点
    42. acRadDim.LeaderLength = 5; //引线长度
    43. acRadDim.DimensionText= "S<>"; //标注内容
    44. acRadDim.TextPosition = new Point3d(5, 5, 0); //文字放置位置
    45. acRadDim.DimensionStyle = acCurDb.Dimstyle; //标注样式
    46. acRadDim.Dimscale = scal; //全局比例
    47. acRadDim.Dimlfac = sca; //线型比例
    48. // 添加新对象到模型空间和事务
    49. CheckRegApp("ACAD_DSTYLE_DIMRADIAL_EXTENSION");//自定义函数检查RegApp名字是否存在,不存在就添加regApp名字
    50. ResultBuffer resBuf = new ResultBuffer();
    51. resBuf.Add(new TypedValue((int)DxfCode.ExtendedDataRegAppName, "ACAD_DSTYLE_DIMRADIAL_EXTENSION"));
    52. resBuf.Add(new TypedValue((int)DxfCode.ExtendedDataInteger16, 387));
    53. resBuf.Add(new TypedValue((int)DxfCode.ExtendedDataInteger16, 1));
    54. resBuf.Add(new TypedValue((int)DxfCode.ExtendedDataInteger16, 388));
    55. resBuf.Add(new TypedValue((int)DxfCode.ExtendedDataReal, 6.26953));//圆弧的开始角度
    56. resBuf.Add(new TypedValue((int)DxfCode.ExtendedDataInteger16, 390));
    57. resBuf.Add(new TypedValue((int)DxfCode.ExtendedDataReal, 2.67146));//圆弧的结束角度
    58. acRadDim.XData = resBuf;
    59. acBlkTblRec.AppendEntity(acRadDim);
    60. acTrans.AddNewlyCreatedDBObject(acRadDim, true);
    61. // 提交修改,关闭事务
    62. acTrans.Commit();
    63. }
    64. }