public static void Run(Tekla.Technology.Akit.IScript akit) { Model model = new Model(); ModelObjectEnumerator modelObjectEnum = model.GetModelObjectSelector().GetSelectedObjects(); Tekla.Structures.Model.UI.Picker picker = new Tekla.Structures.Model.UI.Picker(); if (modelObjectEnum.GetSize() == 0) { modelObjectEnum = picker.PickObjects(Tekla.Structures.Model.UI.Picker.PickObjectsEnum.PICK_N_PARTS); } ArrayList arrayPoints = picker.PickPoints(Tekla.Structures.Model.UI.Picker.PickPointEnum.PICK_TWO_POINTS); Point point1 = (Tekla.Structures.Geometry3d.Point)arrayPoints[0]; Point point2 = (Tekla.Structures.Geometry3d.Point)arrayPoints[1]; Line line = new Tekla.Structures.Geometry3d.Line(point1, point2); while (modelObjectEnum.MoveNext()) { if (modelObjectEnum.Current is Beam) { Beam beam = (Beam)modelObjectEnum.Current; Line line2 = new Line(beam.StartPoint, beam.EndPoint); Point intersection = Intersection.LineToLine(line, line2).Point1; Tekla.Structures.Model.Operations.Operation.Split(beam, intersection); } } model.CommitChanges(); }
/// <summary>Checks intersection between two line segments. Line segments are fragments of lines with start and end point.</summary> /// <param name="lineSegment1"></param> /// <param name="lineSegment2"></param> /// <param name="intersectionPoint">The point on the first or second line segment.</param> /// <returns>Return true if lines intersects and if point is on the linesegments.</returns> public static bool LineSegmentToLineSegment(T3D.LineSegment lineSegment1, T3D.LineSegment lineSegment2, out T3D.Point intersectionPoint) { intersectionPoint = new T3D.Point(); if (lineSegment1 == null | lineSegment2 == null) { return(false); } var line1 = new T3D.Line(lineSegment1); var line2 = new T3D.Line(lineSegment2); var intersectionLineSegment = T3D.Intersection.LineToLine(line1, line2); if (intersectionLineSegment == null) { return(false); } intersectionPoint = T3D.Projection.PointToLine(intersectionLineSegment.Point1, line1); if (!IsThePointOnTheLineSegment(lineSegment1, intersectionPoint)) { return(false); } intersectionPoint = T3D.Projection.PointToLine(intersectionLineSegment.Point1, line2); if (!IsThePointOnTheLineSegment(lineSegment2, intersectionPoint)) { return(false); } return(true); }