修改采样线名称
问题来源:
在Autodesk论坛中,一位朋友提出了这样一个问题:要把路线曲线点、超高点等特征信息在横断面图标题中显示出来,注意是横断面图。
解决方法:
如果直接解决这个问题,貌似不可行,但可以稍稍绕一点路,通过采样线名称来实现——把采样线名称当做横断面图的标题!
这样以来,我们只需修改采样线名称即可!手工修改应该不大现实,我们可以通过简单的代码来实现!
代码如下:
注意这只是测试代码,测试前提假定路线有一个采样线编组,如果采样线编组多于一个,代码也只能修改第一个采样线编组中采样线的名称。
超高点、纵断面点的操作类似,代码没有给出,有兴趣的朋友可以自行完成。
using System; using Autodesk.AutoCAD.ApplicationServices; using Autodesk.AutoCAD.DatabaseServices; using Autodesk.AutoCAD.EditorInput; using Autodesk.Civil.ApplicationServices; using Autodesk.Civil.DatabaseServices; using Autodesk.Civil.Settings; namespace ProfileTools { class RenameSampleline { Document doc; Editor ed; CivilDocument civilDoc; public RenameSampleline() { doc = Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument; ed = doc.Editor; civilDoc = Autodesk.Civil.ApplicationServices.CivilApplication.ActiveDocument; } public void DoSth() { PromptEntityOptions opt = new PromptEntityOptions( "\n选择路线"); opt.AllowNone = true; opt.SetRejectMessage("\n选定的图元必须属于类型:采样线!"); opt.AddAllowedClass(typeof(Alignment), false); PromptEntityResult res = doc.Editor.GetEntity(opt); if (res.Status != PromptStatus.OK) return; using (Transaction tr = doc.Database.TransactionManager.StartTransaction()) { Alignment al = res.ObjectId.GetObject(OpenMode.ForRead) as Alignment; if (al != null) { ObjectIdCollection ids = al.GetSampleLineGroupIds(); if (ids.Count > 0) { Station[] stas = al.GetStationSet(StationTypes.All); SampleLineGroup slg = ids[0].GetObject(OpenMode.ForRead) as SampleLineGroup; if (slg != null) { ids = slg.GetSampleLineIds(); foreach (ObjectId id in ids) { SampleLine sl = id.GetObject(OpenMode.ForWrite) as SampleLine; double sta = sl.Station; sl.Name= GetStaStr(stas, sta); } } } } tr.Commit(); } } private string GetStaStr(Station[] stas, double sta) { string str = ""; foreach (Station station in stas) { if (Math.Abs(station.RawStation - sta) < 0.002) { AlignmentGeometryPointStationType types = station.GeometryStationType; switch(types) { case AlignmentGeometryPointStationType.BegOfAlign: str = civilDoc.Settings.DrawingSettings.AbbreviationsSettings.AlignmentGeoPointText.GetAlignmentAbbreviation(AbbreviationAlignmentType.AlignmentBeginning); break; case AlignmentGeometryPointStationType.EndOfAlign: str = civilDoc.Settings.DrawingSettings.AbbreviationsSettings.AlignmentGeoPointText.GetAlignmentAbbreviation(AbbreviationAlignmentType.AlignmentEnd); break; case AlignmentGeometryPointStationType.TanTan: str = civilDoc.Settings.DrawingSettings.AbbreviationsSettings.AlignmentGeoPointText.GetAlignmentAbbreviation(AbbreviationAlignmentType.TangentTangentIntersect); break; case AlignmentGeometryPointStationType.TanCurve: str = civilDoc.Settings.DrawingSettings.AbbreviationsSettings.AlignmentGeoPointText.GetAlignmentAbbreviation(AbbreviationAlignmentType.TangentCurveIntersect); break; case AlignmentGeometryPointStationType.CurveTan: str = civilDoc.Settings.DrawingSettings.AbbreviationsSettings.AlignmentGeoPointText.GetAlignmentAbbreviation(AbbreviationAlignmentType.CurveTangentIntersect); break; case AlignmentGeometryPointStationType.CurveCompCurve: str = civilDoc.Settings.DrawingSettings.AbbreviationsSettings.AlignmentGeoPointText.GetAlignmentAbbreviation(AbbreviationAlignmentType.CompoundCurveCurveIntersect); break; case AlignmentGeometryPointStationType.CurveRevCurve: str = civilDoc.Settings.DrawingSettings.AbbreviationsSettings.AlignmentGeoPointText.GetAlignmentAbbreviation(AbbreviationAlignmentType.ReverseCurveCurveIntersect); break; case AlignmentGeometryPointStationType.TanSpiral: str = civilDoc.Settings.DrawingSettings.AbbreviationsSettings.AlignmentGeoPointText.GetAlignmentAbbreviation(AbbreviationAlignmentType.TangentSpiralIntersect); break; case AlignmentGeometryPointStationType.SpiralTan: str = civilDoc.Settings.DrawingSettings.AbbreviationsSettings.AlignmentGeoPointText.GetAlignmentAbbreviation(AbbreviationAlignmentType.SpiralTangentIntersect); break; case AlignmentGeometryPointStationType.CurveSpiral: str = civilDoc.Settings.DrawingSettings.AbbreviationsSettings.AlignmentGeoPointText.GetAlignmentAbbreviation(AbbreviationAlignmentType.CurveSpiralIntersect); break; case AlignmentGeometryPointStationType.SpiralCurve: str = civilDoc.Settings.DrawingSettings.AbbreviationsSettings.AlignmentGeoPointText.GetAlignmentAbbreviation(AbbreviationAlignmentType.SpiralCurveIntersect); break; case AlignmentGeometryPointStationType.SpiralCompSpiral: str = civilDoc.Settings.DrawingSettings.AbbreviationsSettings.AlignmentGeoPointText.GetAlignmentAbbreviation(AbbreviationAlignmentType.SpiralSpiralIntersect); break; case AlignmentGeometryPointStationType.SpiralRevSpiral: str = civilDoc.Settings.DrawingSettings.AbbreviationsSettings.AlignmentGeoPointText.GetAlignmentAbbreviation(AbbreviationAlignmentType.ReverseSpiralIntersect); break; case AlignmentGeometryPointStationType.ProfileTanCurve: str = civilDoc.Settings.DrawingSettings.AbbreviationsSettings.Profile.GetProfileAbbreviation(AbbreviationProfileType.BeginVerticalCurve); break; } break; } } if (str=="") { return sta.ToString("0+000.00"); } return str+"_"+sta.ToString("0+000.00"); } } }
测试结果如下:
这些简写,可以通过修改图形设置进行自定义。
标签:
Civil3d
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· Linux系列:如何用 C#调用 C方法造成内存泄露
· AI与.NET技术实操系列(二):开始使用ML.NET
· 记一次.NET内存居高不下排查解决与启示
· 探究高空视频全景AR技术的实现原理
· 理解Rust引用及其生命周期标识(上)
· DeepSeek 开源周回顾「GitHub 热点速览」
· 物流快递公司核心技术能力-地址解析分单基础技术分享
· .NET 10首个预览版发布:重大改进与新特性概览!
· AI与.NET技术实操系列(二):开始使用ML.NET
· 单线程的Redis速度为什么快?