【ORD C#】廊道创建点控制

老师,下面的代码是我参考另一个帖子老师提供的创建点控制例子,廊道和控制线都已经获取到了,但是还是设置失败。这是我的测试文件111.dgn

public static void PointCtrlTest()
        {
            DgnModel model = Bentley.MstnPlatformNET.Session.Instance.GetActiveDgnModel();

            Bentley.CifNET.SDK.Edit.ConsensusConnectionEdit con = Bentley.CifNET.SDK.Edit.ConsensusConnectionEdit.GetActive();

            Bentley.CifNET.GeometryModel.SDK.Alignment planAlignment = null;

            foreach (Bentley.CifNET.GeometryModel.SDK.Alignment alignment in con.GetActiveGeometricModel().Alignments)

            {

                if (alignment.FeatureName == "Alignment\\Geom_Baseline" && alignment.ActiveProfile != null)

                {

                    planAlignment = alignment;

                    break;

                }

            }

            Bentley.CifNET.GeometryModel.SDK.Corridor corridor = null;

            foreach (Bentley.CifNET.GeometryModel.SDK.Corridor cor in con.GetActiveGeometricModel().Corridors)

            {

                corridor = cor;

                break;

            }

            con.StartTransientMode();
            if(planAlignment == null || corridor == null)
            {
                return;
            }

            Bentley.CifNET.GeometryModel.SDK.Edit.CorridorEdit corridorEdit = corridor as Bentley.CifNET.GeometryModel.SDK.Edit.CorridorEdit;

            //CreatePointControl

            Bentley.CifNET.GeometryModel.SDK.Edit.PointControlParameter parameters = new PointControlParameter(planAlignment, planAlignment.ActiveProfile, corridorEdit.StartDistance, corridorEdit.EndDistance, PointControlMode.Both, PointControlType.Alignment3d);

            parameters.Description = "Test Create PointControl";

            parameters.PointName = "EOP_L";

            parameters.UseAsSecondaryAlignment = false;

            parameters.Priority = 1;

            Bentley.CifNET.GeometryModel.SDK.Edit.PointControlEdit newPointControlEdit = corridorEdit.AddPointControl(parameters);
            con.PersistTransients();
        }

Parents
  • PointControlParameter(planAlignment, planAlignment.ActiveProfile, corridorEdit.StartDistance, corridorEdit.EndDistance, PointControlMode.Both, PointControlType.Alignment3d);

    这个方法 PointControlMode.Both和横向都不生效,只有纵向生效,怎么能让横向生效呢?

    还有StartDistance和EndDistance两个参数反了

  • 你试试 Bentley.CifNET.GeometryModel.SDK.Edit.PointControlParameter parameters = new PointControlParameter(planAlignment
    , planAlignment.ActiveProfile, 0, 10, PointControlMode.Horizontal, PointControlType.Alignment3d);

  • 目前测试出来有两个问题

    1、只有PointControlMode.Vertical能生效,PointControlMode.Both和PointControlMode.Horizontal都无法生效

    2、double startDistance, double endDistance这两个参数位置是反的。

  •         static void testCorridorEditElementID()
            {
                //创建两条直线
                double beginHeight = 3.5, profileSlope = 0.02;
                double mUor = Session.Instance.GetActiveDgnModel().GetModelInfo().UorPerMeter;
                List<Line> lineList1 = new List<Line>();
                List<Line> lineList2 = new List<Line>();
                Line line1 = new Line(DPoint3d.FromXYZ(0, 0, 0), DPoint3d.FromXYZ(10 * mUor, 0, 0));
                Line line2 = new Line(DPoint3d.FromXYZ(0, 15 * mUor, 0), DPoint3d.FromXYZ(10 * mUor, 15 * mUor, 0));
                lineList1.Add(line1);
                lineList2.Add(line2);
    
                LinearComplex complexAlign1 = LinearComplex.Create1(lineList1.ToArray(), false, false, 0.001);
                LinearComplex complexAlign2 = LinearComplex.Create1(lineList2.ToArray(), false, false, 0.001);
    
                Bentley.CifNET.SDK.Edit.ConsensusConnectionEdit con = Bentley.CifNET.SDK.Edit.ConsensusConnectionEdit.GetActive();
                con.StartTransientMode();
                AlignmentEdit align1 = AlignmentEdit.CreateByLinearElement(con, complexAlign1, true);
                AlignmentEdit align2 = AlignmentEdit.CreateByLinearElement(con, complexAlign2, true);
    
                if (null == align1 || null == align2)
                    return;
    
                //特征属性
                List<string> featureNames = new List<string>();
                FeatureDefinitionManager fdm = FeatureDefinitionManager.Instance;
                featureNames.AddRange(fdm.GetFeatureDefinitions(Bentley.CifNET.SDK.Edit.ConsensusConnectionEdit.GetActive(), "Alignment"));
                string featureName = "";
                if (featureNames.Count > 0)
                    featureName = featureNames[0];
                align1.SetFeatureDefinition(featureName);
                align2.SetFeatureDefinition(featureName);
    
                //创建纵面
                ProfileLine profileLine = new ProfileLine(DPoint3d.FromXYZ(0, beginHeight * mUor, 0), DPoint3d.FromXYZ(align1.LinearGeometry.Length
               , align1.LinearGeometry.Length * profileSlope + beginHeight * mUor, 0));
                // create profile and active the profile
                ProfileEdit profile = ProfileEdit.CreateByProfileElement(con, align1, profileLine, true, false);
                //profile.SetFeatureDefinition(con, featureName);
                align1.SetActiveProfile(profile);
    
    
                //设置模板
                TemplateDefinition template = new TemplateDefinition("Haha");
                template.IsTunnelTemplate = false;
                template.LastRevisedBy = "Haha";
                template.TranslationX = 0;
                template.TranslationY = 0;
    
                //右 面层
                TemplatePointConstraint cons1 = new TemplatePointConstraint(ConstraintType.None, 0, "");
                TemplatePoint tp1 = new TemplatePoint("_m", "", "", false, 0, 0.4, 0, "", "", 0, cons1, cons1);
                template.AddPoint(tp1);
                TemplatePointConstraint cons3 = new TemplatePointConstraint(ConstraintType.Horizontal, 0, "_m");
                TemplatePointConstraint cons4 = new TemplatePointConstraint(ConstraintType.Vertical, -0.4, "_m");
                TemplatePoint tp2 = new TemplatePoint("_b", "", "", false, 0, 0.4, 0, "", "", 0, cons3, cons4);
                template.AddPoint(tp2);
                TemplatePointConstraint cons5 = new TemplatePointConstraint(ConstraintType.Slope, -0.02, "_m");
                TemplatePointConstraint cons6 = new TemplatePointConstraint(ConstraintType.Horizontal, 12, "_m");
                TemplatePoint tp3 = new TemplatePoint("_R", "", "", false, 12, 0.16, 0, "", "", 0, cons5, cons6);
                template.AddPoint(tp3);
                TemplatePointConstraint cons7 = new TemplatePointConstraint(ConstraintType.Horizontal, 0.0, "_R");
                TemplatePointConstraint cons8 = new TemplatePointConstraint(ConstraintType.Vertical, -0.4, "_R");
                TemplatePoint tp4 = new TemplatePoint("1_R", "", "", false, 12, -0.24, 0, "", "", 0, cons7, cons8);
                template.AddPoint(tp4);
    
                TemplateComponent comp1 = new TemplateComponent("Aggregate_R", "TC_Aggregate Typ A", TemplateComponentType.Normal, true, "", "");
                comp1.AddVertex(new TemplateVertex(tp1, 0));
                comp1.AddVertex(new TemplateVertex(tp3, 0));
                comp1.AddVertex(new TemplateVertex(tp4, 0));
                comp1.AddVertex(new TemplateVertex(tp2, 0));
                comp1.MaterialPath = "Mesh\\Aggregate\\";
                template.AddComponent(comp1);
                //左
                TemplatePointConstraint cons9 = new TemplatePointConstraint(ConstraintType.Slope, -0.02, "_m");
                TemplatePointConstraint cons10 = new TemplatePointConstraint(ConstraintType.Horizontal, -12, "_m");
                TemplatePoint tp5 = new TemplatePoint("_L", "", "", false, -12, 0.16, 0, "", "", 0, cons9, cons10);
                template.AddPoint(tp5);
                TemplatePointConstraint cons11 = new TemplatePointConstraint(ConstraintType.Horizontal, 0.0, "_L");
                TemplatePointConstraint cons12 = new TemplatePointConstraint(ConstraintType.Vertical, -0.4, "_L");
                TemplatePoint tp6 = new TemplatePoint("1_L", "", "", false, -12, -0.24, 0, "", "", 0, cons11, cons12);
                template.AddPoint(tp6);
    
                TemplateComponent comp2 = new TemplateComponent("Aggregate_L", "TC_Aggregate Typ A", TemplateComponentType.Normal, true, "", "");
                comp2.AddVertex(new TemplateVertex(tp1, 0));
                comp2.AddVertex(new TemplateVertex(tp5, 0));
                comp2.AddVertex(new TemplateVertex(tp6, 0));
                comp2.AddVertex(new TemplateVertex(tp2, 0));
                comp2.MaterialPath = "Mesh\\Aggregate\\";
                template.AddComponent(comp2);
    
                //以align1创建廊道
                if (align1.ActiveProfile == null)
                    return;
                Bentley.CifNET.GeometryModel.SDK.Edit.CorridorEdit newCorridor = Bentley.CifNET.GeometryModel.SDK.Edit.CorridorEdit.CreateByAlignment(con, "Corridor", align1);
                TemplateDropParameters tempDP = new TemplateDropParameters(template, 0, align1.Geometry.SumOfLengths());
                tempDP.Interval = 15;//设置步长
                newCorridor.AddTemplateDrop(tempDP);
    
                //生成控制点
    
                //创建align2纵面
                ProfileLine profileLine2 = new ProfileLine(DPoint3d.FromXYZ(0, beginHeight * mUor, 0), DPoint3d.FromXYZ(align2.LinearGeometry.Length
               , align2.LinearGeometry.Length * profileSlope + beginHeight * mUor, 0));
                // create profile and active the profile
                ProfileEdit profile2 = ProfileEdit.CreateByProfileElement(con, align2, profileLine2, true, false);
                //profile.SetFeatureDefinition(con, featureName);
                align2.SetActiveProfile(profile2);
    
                Bentley.CifNET.GeometryModel.SDK.Edit.PointControlParameter parameters = new PointControlParameter(align2
                    , align2.ActiveProfile, newCorridor.StartDistance, newCorridor.EndDistance, PointControlMode.Horizontal, PointControlType.Alignment3d);
                parameters.Description = "Test Create PointControl";
                parameters.PointName = "_L";
                parameters.UseAsSecondaryAlignment = false;
                parameters.Priority = 2;
                parameters.StartOffsetHorizontal = 0;
                parameters.StopOffsetHorizontal = 0;
                parameters.FeatureDefinition = "Alignment\\Geom_BaseLine";
                PointControlEdit newPointControlEdit = newCorridor.AddPointControl(parameters);
    
                con.PersistTransients();
                //return align1;
    
                ElementId id = newCorridor.DgnECInstance.Element.ElementId;
            }

    corridor.dgn

  • 用这个代码执行还是不行,没有变化 我把这里的值改了的

Reply Children
No Data