老师您好,我首先在ORD里面画了一条线,并且激活了纵断面,然后在代码中直接获取这条线元素alignment,用来创建廊道,但是得到的newCorridor为空。
CorridorEdit newCorridor = CorridorEdit.CreateByAlignment(con, name, alignment);
请用下面代码测试一下:
public static AlignmentEdit CreateCorridorFromLine () { //创建两条直线 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); ConsensusConnectionEdit con = ConsensusConnectionEdit.GetActive(); con.StartTransientMode(); AlignmentEdit align1 = AlignmentEdit.CreateByLinearElement(con, complexAlign1, true); AlignmentEdit align2 = AlignmentEdit.CreateByLinearElement(con, complexAlign2, true); if ( null == align1 || null == align2 ) return null; //特征属性 List<string> featureNames = new List<string>(); FeatureDefinitionManager fdm = FeatureDefinitionManager.Instance; featureNames.AddRange(fdm.GetFeatureDefinitions(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 null; 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, 0, align1.Geometry.SumOfLengths(), PointControlMode.Vertical, 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; }
好的,谢谢老师