1. 程式人生 > >修改采樣線名稱

修改采樣線名稱

nbsp ttext typeof ldoc info mit ble tor post

問題來源:

在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"); } } }

測試結果如下:

技術分享圖片

這些簡寫,可以通過修改圖形設置進行自定義。

修改采樣線名稱