通过civil3d提供的api,也就是纵断面Profile类提供的方法---public double ElevationAt(double station),就可以很轻松的获取纵断面对象某桩号处的高程值,进而可以批量获取高程值。下面给出实现的代码。

首先写一个纵断面Profile类的扩展方法(扩展方法相当有用),用于返回某桩号处的高程值。

         /// <summary>
/// 给定桩号值获取纵断面中的高程值,2018年4月21日
/// 如果给定的桩号在纵断面范围内,则返回对应的高程值,否则返回null
/// </summary>
/// <param name="profile"></param>
/// <param name="station"></param>
/// <returns></returns>
public static double? GetElevationFromProfile(this Profile profile, double station)
{
double? elevation = null;//定义一个可空类型的数据
var startStation = profile.StartingStation;
var endStation = profile.EndingStation;
if (station >= startStation && station <= endStation)//判断桩号在纵断面桩号范围之内
{
elevation = profile.ElevationAt(station);
} return elevation;
}

然后就可以通过调用上面的方法,就可以获取桩号对应的高程数据了。

 1         [CommandMethod("getElvFromProfile")]
public static void GetElvFromProfile()
{
Document doc = AcadApp.DocumentManager.MdiActiveDocument;
Database db = doc.Database;
Editor ed = doc.Editor;
CivilDocument civilDoc = CivilApplication.ActiveDocument;
var opt = new PromptEntityOptions("\n 请拾取一个纵断面对象 ");
opt.SetRejectMessage("\n 对象必须是纵断面对象");
opt.AddAllowedClass(typeof(Profile), false);
var res = ed.GetEntity(opt);
if (res.Status != PromptStatus.OK)
{
ed.WriteMessage("\n你已经取消了选择");
return;
}
var doubleResult = ed.GetDouble("\n请输入一个桩号");
double station = doubleResult.Value;
using (DocumentLock docLock = doc.LockDocument())
using (Transaction trans = db.TransactionManager.StartTransaction())
{
Profile profile = trans.GetObject(res.ObjectId, OpenMode.ForRead) as Profile;//获取纵断面对象
double? elevation = profile.GetElevationFromProfile(station);//调用扩展方法,获取高程值
//ed.WriteMessage(profile.GetElevationFromProfile(station).ToString());
ed.WriteMessage(elevation?.ToString());
}
}

如过想要批量获取高程值得话,借助循环就可以完成了。

04-21 01:02