Civil3D开发者指南系列之一——用代码访问设置

1. 输出文档中道路名和最长边的长度

  1. public void InterateCorridors()
  2. {
  3. using (var tr = db.TransactionManager.StartTransaction())
  4. {
  5. foreach (var id in civilDoc.CorridorCollection)
  6. {
  7. var corridor = id.GetObject(OpenMode.ForRead) as Corridor;
  8. ed.WriteMessage(
  9. $"Corridor:{corridor.Name}\nLargest posible Triangle side:{corridor.MaximumTriangleSideLength}");
  10. }
  11. tr.Commit();
  12. }
  13. }

2. 创建点样式

  1. /// <summary>
  2. /// 创建点样式
  3. /// </summary>
  4. /// <param name="ptSName"></param>
  5. public void CreatePointStyle(string ptSName)
  6. {
  7. var psId = ObjectId.Null;
  8. if (civilDoc.Styles.PointStyles.Contains(ptSName))
  9. psId = civilDoc.Styles.PointStyles[ptSName];
  10. else
  11. psId = civilDoc.Styles.PointStyles.Add(ptSName);
  12. using (var tr = db.TransactionManager.StartTransaction())
  13. {
  14. var ptStyle = psId.GetObject(OpenMode.ForWrite) as PointStyle;
  15. ptStyle.Elevation = 114.6;
  16. tr.Commit();
  17. }
  18. }

Civil3D开发者指南系列之一——用代码访问设置 - 图1

3. 获取线路设置

  1. public void AlignmentSetting()
  2. {
  3. var sa = civilDoc.Settings.GetSettings<SettingsAlignment>();
  4. var angleSettings = sa.Angle;
  5. ed.WriteMessage(@"Alignment setting:
  6. Precision: {0}
  7. Rounding:{1}
  8. Unit:{2}
  9. Drop Decimal:{3}
  10. DropZeros:{4}",
  11. angleSettings.Precision.Value,
  12. angleSettings.Rounding.Value,
  13. angleSettings.Unit.Value, angleSettings.DropDecimalForWholeNumbers.Value,
  14. angleSettings.DropLeadingZerosForDegrees.Value);
  15. }

Civil3D开发者指南系列之一——用代码访问设置 - 图2

4. 获取线路对象线型

  1. public void AlignmentTypeOption()
  2. {
  3. var ato = civilDoc.Settings
  4. .GetSettings<SettingsCmdCreateAlignmentLayout>();
  5. ed.WriteMessage(@"Alignment Layout Command settings :Alignment:{0}",
  6. ato.AlignmentTypeOption.AlignmentType.Value);
  7. }

Civil3D开发者指南系列之一——用代码访问设置 - 图3