• 修改采样线名称


    问题来源:

    在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(
                    "
    选择路线");
                opt.AllowNone = true;
                opt.SetRejectMessage("
    选定的图元必须属于类型:采样线!");
                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");
            }
        }
    }

    测试结果如下:

    这些简写,可以通过修改图形设置进行自定义。

  • 相关阅读:
    spring子模块----->Spring Security------->相关教程(参考资料)
    Maven--->学习心得--->maven 概述
    Spring和Spring MVC 、Spring Security的关系
    leapMotion简介
    软件工程需求分析
    大型web网站-----系统架构
    Maven的安装与配置
    A Java Exception occured 解决
    mysql-5.7.20安装和配置
    线段树 poj 3667
  • 原文地址:https://www.cnblogs.com/myzw/p/8449282.html
Copyright © 2020-2023  润新知