예제 #1
0
        internal static List <Face> CompareNormals(Dictionary <Plane, Face> FirstBeamNormals, Dictionary <Plane, Face> SecondaryBeamNormals, double MaximumOffset)
        {
            List <Face> Faces = new List <Face>();

            foreach (Plane Plane in FirstBeamNormals.Keys)
            {
                foreach (Plane PlaneToCompare in SecondaryBeamNormals.Keys)
                {
                    Vector PlaneNormal          = Vector.Cross(Plane.AxisX, Plane.AxisY);
                    Vector PlaneToCompareNormal = Vector.Cross(PlaneToCompare.AxisX, PlaneToCompare.AxisY);

                    if (Vector.Dot(PlaneNormal.GetNormal(), PlaneToCompareNormal.GetNormal()) == -1)
                    {
                        GeometricPlane GeometricPlane = new GeometricPlane(PlaneToCompare.Origin, PlaneToCompareNormal);
                        double         distance       = Distance.PointToPlane(Plane.Origin, GeometricPlane);

                        if (distance <= MaximumOffset)
                        {
                            DrawMesh(Plane);
                            Faces.Add(FirstBeamNormals[Plane]);
                        }
                    }
                }
            }
            return(Faces);
        }
 public static dynamic GetTSObject(GeometricPlane dynObject)
 {
     if (dynObject is null)
     {
         return(null);
     }
     return(dynObject.teklaObject);
 }
 public static GeometricPlane Transform(Matrix matToTrans, GeometricPlane plane)
 {
     return(new GeometricPlane()
     {
         Origin = matToTrans.Transform(plane.Origin),
         Normal = Geometry.Transform(matToTrans, plane.Normal)
     });
 }
        private static void DrawFaceOfIntersectionPoint(Point intersectPoint, Dictionary <Plane, Face> partPlanes)
        {
            foreach (Plane plane in partPlanes.Keys)
            {
                GeometricPlane geometricPlane = new GeometricPlane(plane.Origin, plane.AxisX, plane.AxisY);
                double         myDistance     = Distance.PointToPlane(intersectPoint, geometricPlane);

                if (myDistance >= 1)
                {
                    DrawMesh(partPlanes[plane]);
                }
            }
        }
예제 #5
0
        public GeometricPlane PickFace()
        {
            Picker           picker     = new Picker();
            PickInput        input      = picker.PickFace("Pick a FACE");
            IEnumerator      enumerator = input.GetEnumerator();
            List <T3D.Point> points     = new List <T3D.Point>();

            while (enumerator.MoveNext())
            {
                InputItem item = enumerator.Current as InputItem;
                if (item.GetInputType() == InputItem.InputTypeEnum.INPUT_POLYGON)
                {
                    ArrayList alist = item.GetData() as ArrayList;
                    //           int counter = 1;
                    foreach (T3D.Point p in alist)
                    {
                        points.Add(p);
                        //              Txt(p, counter.ToString());
                        //              counter++;
                    }
                }
            }
            T3D.Point      origin    = points[1];
            T3D.Vector     axisX     = new T3D.Vector(points[0] - points[1]);
            T3D.Vector     axisY     = new T3D.Vector(points[2] - points[1]);
            GeometricPlane geomPlane = new GeometricPlane(origin, axisX, axisY);

            Model               model        = new Model();
            WorkPlaneHandler    workPlane    = model.GetWorkPlaneHandler();
            TransformationPlane currentPlane = workPlane.GetCurrentTransformationPlane();
            Matrix              matrix       = currentPlane.TransformationMatrixToLocal;

            T3D.Point p1 = matrix.Transform(geomPlane.Origin);
            T3D.Point p2 = matrix.Transform(geomPlane.Origin + geomPlane.Normal);
            geomPlane.Origin = p1;
            geomPlane.Normal = new T3D.Vector(p2 - p1);
            T3D.Point dummy   = null;
            int       counter = 1;

            foreach (T3D.Point pt in points)
            {
                dummy = matrix.Transform(pt);
                Txt(dummy, counter.ToString());
                counter++;
            }

            return(geomPlane);
        }
예제 #6
0
        /// <summary>
        /// Определение пересекаются ли отрезки.
        /// возвращает bool.
        /// </summary>
        /// <param name="segmentOne"></param>
        /// <param name="segmentTwo"></param>
        /// <returns></returns>
        public static bool IntersectionSegmentToSegment(LineSegment segmentOne, LineSegment segmentTwo)
        {
            Vector vectorOne = new Vector(segmentOne.Point2.X - segmentOne.Point1.X, segmentOne.Point2.Y - segmentOne.Point1.Y, segmentOne.Point2.Z - segmentOne.Point1.Z);
            Vector vectorTwo = new Vector(segmentTwo.Point2.X - segmentTwo.Point1.X, segmentTwo.Point2.Y - segmentTwo.Point1.Y, segmentTwo.Point2.Z - segmentTwo.Point1.Z);

            Vector vectorZ = vectorOne.Cross(vectorTwo);

            GeometricPlane planeOne = new GeometricPlane(segmentOne.Point1, vectorOne, vectorZ);
            GeometricPlane planeTwo = new GeometricPlane(segmentTwo.Point1, vectorTwo, vectorZ);

            bool conditionOne;
            bool conditionTwo;
            var  pointIntersectionOne = Intersection.LineSegmentToPlane(segmentOne, planeTwo);
            var  pointIntersectionTwo = Intersection.LineSegmentToPlane(segmentTwo, planeOne);

            if (pointIntersectionOne == null)
            {
                conditionOne = false;
            }
            else
            {
                conditionOne = true;
            }

            if (pointIntersectionTwo == null)
            {
                conditionTwo = false;
            }
            else
            {
                conditionTwo = true;
            }

            if (conditionOne && conditionTwo)
            {
                return(true);
            }
            else
            {
                return(false);
            }
        }
예제 #7
0
        public void FittingBeamByFace()
        {
            Beam           beam      = PickBeam();
            GeometricPlane geomPlane = PickFace();

            Fitting fitting = new Fitting();

            fitting.Father = beam;
            CoordinateSystem beamCS = beam.GetCoordinateSystem();

            ReperShow(beamCS);
            Line lineAlongBeamAxisX = new Line(beamCS.Origin, beamCS.AxisX);

            //do u need Z asis
            //T3D.Vector axisZ = beamCS.
            T3D.Point intersectionPoint = Intersection.LineToPlane(lineAlongBeamAxisX, geomPlane);
            PointShow(intersectionPoint, "intersectionPoint");

            T3D.Point randomPoint = new T3D.Point(intersectionPoint + new T3D.Point(500, 500, 500));
            PointShow(randomPoint, "randomPoint");
            randomPoint = Projection.PointToPlane(randomPoint, geomPlane);
            PointShow(randomPoint, "Projected randomPoint");
            T3D.Vector       x        = new T3D.Vector(randomPoint - intersectionPoint);
            T3D.Vector       y        = geomPlane.Normal.Cross(x);
            CoordinateSystem itersect = new CoordinateSystem(intersectionPoint, x, y);

            ReperShow(itersect);

            Plane plane = new Plane();

            plane.Origin = intersectionPoint;
            plane.AxisX  = x;
            plane.AxisY  = y;
            x.Normalize(500);
            y.Normalize(500);
            fitting.Plane = plane;
            fitting.Insert();

            Model.CommitChanges();
        }
        private void TryApplyFits(Part beam, List <Tuple <Tuple <Point, Point, Point>, Plane> > fitPlanes)
        {
            if (null == fitPlanes)
            {
                return;
            }

            var centerLine = GetBeamCenterLineSegmentExpanded(beam, 10.0);

            if (null == centerLine)
            {
                return;
            }

            // check collision
            foreach (var fitPlaneDef in fitPlanes)
            {
                //var pps = fitPlaneDef.Item1;
                var plane = fitPlaneDef.Item2;
                //var geomPlane = new GeometricPlane(pps.Item1, new Vector(pps.Item3));
                var geomPlane    = new GeometricPlane(plane.Origin, plane.AxisX, plane.AxisY);
                var intersection = Intersection.LineSegmentToPlane(centerLine, geomPlane);
                if (null == intersection)
                {
                    Tracer._trace($"Does not intersect with {beam.Profile.ProfileString}");
                    continue;
                }
                var operativePart = fitPlaneDef.Item2;

                var fitPlane = new Fitting();
                fitPlane.Father = beam;
                fitPlane.Plane  = operativePart;
                if (!fitPlane.Insert())
                {
                    Tracer._trace("Insert failed!");
                }
                Tracer._trace($"Fit solid: {beam.Name}.");
            }
        }
예제 #9
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="solid"></param>
        /// <param name="plane"></param>
        /// <returns></returns>
        List <List <Point> > IntersectSolid(Solid solid, GeometricPlane plane)
        {
            Point p1, p2, p3 = null;

            p1 = new Point(plane.Origin);
            p2 = new Point(p1);
            p2.Translate(100, 100, 100);
            p2 = Projection.PointToPlane(p2, plane);
            Vector x = new Vector(p2 - p1);

            x.Normalize(1000);
            Vector y = Vector.Cross(plane.Normal, x);

            y.Normalize(1000);
            p3 = new Point(p1 + y);
            p3 = Projection.PointToPlane(p3, plane);

            IEnumerator          faceEnumerator = solid.IntersectAllFaces(p1, p2, p3);
            List <List <Point> > polygons       = new List <List <Point> >();

            while (faceEnumerator.MoveNext())
            {
                ArrayList   points    = faceEnumerator.Current as ArrayList;
                IEnumerator LoopsEnum = points.GetEnumerator();
                while (LoopsEnum.MoveNext())
                {
                    ArrayList    ps      = LoopsEnum.Current as ArrayList;
                    List <Point> polygon = new List <Point>();
                    foreach (object o in ps)
                    {
                        Point p = o as Point;
                        polygon.Add(p);
                    }
                    polygons.Add(polygon);
                }
            }
            return(polygons);
        }
예제 #10
0
            public static void Run()
            {
                var model  = new Model();
                var picker = new Picker();

                try
                {
                    var selected = picker.PickObjects(Picker.PickObjectsEnum.PICK_N_PARTS, "Select beams to extend to beam");
                    if (selected.GetSize() < 1)
                    {
                        return;
                    }

                    var pickedBeam = picker.PickObject(Picker.PickObjectEnum.PICK_ONE_PART, "Select beam") as Beam;
                    if (pickedBeam == null)
                    {
                        return;
                    }

                    var coordSystem       = pickedBeam.GetCoordinateSystem();
                    var intersectionPlane = new GeometricPlane(coordSystem.Origin, coordSystem.AxisX,
                                                               new Vector(0, 0, 1));

                    Operation.DisplayPrompt("Beams are being extended/trimmed to the beam");

                    while (selected.MoveNext())
                    {
                        var beam = selected.Current as Beam;
                        if (beam == null)
                        {
                            continue;
                        }

                        var beamLine       = new Line(beam.StartPoint, beam.EndPoint);
                        var intersectPoint = Intersection.LineToPlane(beamLine, intersectionPlane);
                        if (intersectPoint == null)
                        {
                            continue;
                        }

                        var startDist = Distance.PointToPoint(intersectPoint, beam.StartPoint);
                        var endDist   = Distance.PointToPoint(intersectPoint, beam.EndPoint);

                        if (startDist <= endDist)
                        {
                            beam.StartPoint = intersectPoint;
                        }
                        else
                        {
                            beam.EndPoint = intersectPoint;
                        }

                        beam.Modify();
                    }

                    Operation.DisplayPrompt("Beams have been extended/trimmed to the beam");
                }
                catch (Exception ex)
                {
                }

                model.CommitChanges();
            }
예제 #11
0
        public override bool Run(List <InputDefinition> Input)
        {
            try
            {
                GetValuesFromDialog();

                WorkPlaneHandler wph = Model.GetWorkPlaneHandler();

                TransformationPlane tp     = wph.GetCurrentTransformationPlane();
                TransformationPlane tppart = null;


                BoltGroup bg = Model.SelectModelObject((Identifier)Input[0].GetInput()) as BoltGroup;
                bg.Select();
                List <Part> parts = new List <Part>();
                parts.Add(bg.PartToBeBolted);
                parts.Add(bg.PartToBoltTo);
                foreach (Part p in bg.OtherPartsToBolt)
                {
                    parts.Add(p);
                }

                #region Clear
                List <Part> _part = new List <Part>();

                foreach (Part p in parts)
                {
                    bool flag = false;
                    foreach (Part pp in _part)
                    {
                        if (pp.Identifier.ID == p.Identifier.ID)
                        {
                            flag = true;
                        }
                    }
                    if (!flag)
                    {
                        _part.Add(p);
                    }
                }

                parts.Clear();
                parts = _part;
                #endregion

                foreach (Part p in parts)
                {
                    if (p is Beam)
                    {
                        Beam b = p as Beam;
                        b.Select();

                        double k = 0.0; b.GetReportProperty("PROFILE.FLANGE_SLOPE_RATIO", ref k);
                        if (k == 0)
                        {
                            continue;
                        }

                        tppart = new TransformationPlane(p.GetCoordinateSystem());
                        wph.SetCurrentTransformationPlane(tppart);
                        bg.Select();
                        foreach (Point pb in bg.BoltPositions)
                        {
                            Point _pb = new Point(pb);

                            #region Уклон полок - точки через солид

                            GeometricPlane gp = new GeometricPlane(
                                _pb,
                                new Vector(0, 1, 0),
                                new Vector(0, 0, 1));
                            List <List <Point> > lp = IntersectSolid(p.GetSolid(), gp);

                            List <LineSegment> ls = new List <LineSegment>();


                            for (int i = 0; i < lp[0].Count - 1; i++)
                            {
                                Point  p1 = lp[0][i];
                                Point  p2 = lp[0][i + 1];
                                Vector v  = new Vector(p2.X - p1.X, p2.Y - p1.Y, p2.Z - p1.Z);
                                v.Normalize(1.0);
                                if (v.Y != 0 && v.Z != 0)
                                {
                                    ControlLine cl = new ControlLine();
                                    cl.Line.Point1 = p1;
                                    cl.Line.Point2 = p2;
                                    // cl.Insert();
                                    ls.Add(new LineSegment(p1, p2));
                                }
                            }

                            Point  _p1 = lp[0][0];
                            Point  _p2 = lp[0][lp[0].Count - 1];
                            Vector _v  = new Vector(_p2.X - _p1.X, _p2.Y - _p1.Y, _p2.Z - _p1.Z);
                            if (_v.Y != 0 && _v.Z != 0)
                            {
                                ls.Add(new LineSegment(_p1, _p2));
                                ControlLine cl = new ControlLine();
                                cl.Line.Point1 = _p1;
                                cl.Line.Point2 = _p2;
                                // cl.Insert();
                            }


                            #endregion

                            #region Точки для построения пластины

                            double diam = bg.BoltSize;

                            double tol = GOST_10906_78[diam][0];
                            double _b  = GOST_10906_78[diam][1];
                            double t1  = GOST_10906_78[diam][2];
                            double t2  = GOST_10906_78[diam][3];

                            int kf = (_pb.Z <= ((Point)b.GetReferenceLine(false)[0]).Z ? -1 : 1);

                            _pb.Z += kf * _b * 0.5;


                            double      h   = double.MaxValue;
                            LineSegment lsb = ls[0];

                            foreach (LineSegment lsi in ls)
                            {
                                double t = Distance.PointToLineSegment(_pb, lsi);
                                if (h >= t)
                                {
                                    h   = t;
                                    lsb = lsi;
                                }
                            }
                            //ControlLine cli = new ControlLine();
                            //cli.Line.Point1 = lsb.Point1;
                            //cli.Line.Point2 = lsb.Point2;
                            //cli.Insert();
                            Point pb1 = new Point(_pb.X, _pb.Y + 1000, _pb.Z);

                            Point pbi = Intersection.LineToLine(
                                new Line(lsb),
                                new Line(_pb, pb1)).Point1;
                            //cli.Line.Point1 = _pb;
                            //cli.Line.Point2 = pbi;
                            //cli.Insert();

                            #endregion

                            ContourPlate cp = new ContourPlate();

                            Contour cr = new Contour();
                            cr.AddContourPoint(new ContourPoint(new Point(pbi.X - _b * 0.5, pbi.Y, pbi.Z), null));

                            cr.AddContourPoint(new ContourPoint(new Point(pbi.X + _b * 0.5, pbi.Y, pbi.Z), null));
                            cr.AddContourPoint(new ContourPoint(new Point(pbi.X + _b * 0.5, pbi.Y, pbi.Z - kf * _b), null));
                            cr.AddContourPoint(new ContourPoint(new Point(pbi.X - _b * 0.5, pbi.Y, pbi.Z - kf * _b), null));

                            cp.Contour = cr;


                            cp.Profile.ProfileString      = "PL" + t1.ToString();
                            cp.AssemblyNumber.Prefix      = prefix_asm;
                            cp.AssemblyNumber.StartNumber = start_part;
                            cp.PartNumber.Prefix          = prefix_part;
                            cp.PartNumber.StartNumber     = start_part;

                            cp.Name = name;
                            cp.Material.MaterialString = material;
                            cp.Finish = finish;

                            if (kf == -1 && pbi.Y > 0)
                            {
                                cp.Position.Depth = Position.DepthEnum.FRONT;
                            }
                            else if (kf == -1 && pbi.Y < 0)
                            {
                                cp.Position.Depth = Position.DepthEnum.BEHIND;
                            }
                            else if (kf == 1 && pbi.Y > 0)
                            {
                                cp.Position.Depth = Position.DepthEnum.BEHIND;
                            }
                            else if (kf == 1 && pbi.Y < 0)
                            {
                                cp.Position.Depth = Position.DepthEnum.FRONT;
                            }

                            cp.Insert();

                            if (weight != 0.0 && us_prop_weight != "")
                            {
                                cp.SetUserProperty(us_prop_weight, weight);
                                cp.Modify();
                            }

                            BooleanPart  bp  = new BooleanPart();
                            ContourPlate cp2 = new ContourPlate();
                            Contour      cr2 = new Contour();

                            cr2.AddContourPoint(new ContourPoint(new Point(pbi.X, pbi.Y, pbi.Z), null));
                            cr2.AddContourPoint(new ContourPoint(new Point(pbi.X, pbi.Y, pbi.Z - kf * _b), null));
                            cr2.AddContourPoint(new ContourPoint(new Point(pbi.X, pbi.Y + (pbi.Y > 0 ? -1 * (t1 - t2) : (t1 - t2)), pbi.Z - kf * _b), null));

                            cp2.Contour = cr2;
                            cp2.Profile.ProfileString = "PL" + (_b + 10).ToString();
                            cp2.Class = BooleanPart.BooleanOperativeClassName;

                            cp2.Insert();

                            bp.Father        = cp;
                            bp.OperativePart = cp2;
                            bp.Insert();
                            cp2.Delete();

                            BoltArray ba = new BoltArray();
                            ba.FirstPosition  = pb;
                            ba.SecondPosition = new Point(pb.X + 100, pb.Y, pb.Z);

                            ba.BoltStandard      = bg.BoltStandard;
                            ba.Position.Rotation = Position.RotationEnum.TOP;
                            ba.BoltType          = bg.BoltType;
                            ba.BoltSize          = bg.BoltSize;
                            ba.Tolerance         = tol;
                            ba.Bolt = false;
                            ba.AddBoltDistX(0);
                            ba.AddBoltDistY(0);
                            ba.PartToBeBolted = cp;
                            ba.PartToBoltTo   = cp;
                            ba.Insert();
                        }
                    }
                }
                wph.SetCurrentTransformationPlane(tp);
            }
            catch (Exception Exc)
            {
                MessageBox.Show(Exc.ToString());
            }

            return(true);
        }
예제 #12
0
        private void button1_Click(object sender, EventArgs e)
        {
            if (MyModel.GetConnectionStatus())
            {
                double off1 = Convert.ToDouble(textBox4.Text);
                double off2 = Convert.ToDouble(textBox5.Text);
                TransformationPlane currentPlane = MyModel.GetWorkPlaneHandler().GetCurrentTransformationPlane();
                Picker piku = new Picker();

                ArrayList info = new ArrayList();
                info = new ArrayList {
                    "END_X", "END_Y", "END_Z", "START_X", "START_Y", "START_Z"
                };
                ArrayList info2 = new ArrayList();
                info2 = new ArrayList {
                    "END_X", "END_Y", "END_Z", "START_X", "START_Y", "START_Z"
                };
                ModelObject part  = new Beam();
                ModelObject part2 = new Beam();
                Hashtable   p1    = new Hashtable();
                Hashtable   p2    = new Hashtable();
                part = piku.PickObject(Picker.PickObjectEnum.PICK_ONE_PART);
                part.GetDoubleReportProperties(info, ref p1);
                double rotpart = (part as Part).Position.RotationOffset;
                part2 = piku.PickObject(Picker.PickObjectEnum.PICK_ONE_PART);
                part2.GetDoubleReportProperties(info2, ref p2);
                double rotpart2 = (part2 as Part).Position.RotationOffset;


                Point st1 = new Point(Convert.ToDouble(p1["START_X"]), Convert.ToDouble(p1["START_Y"]), Convert.ToDouble(p1["START_Z"]));
                Point st2 = new Point(Convert.ToDouble(p2["END_X"]), Convert.ToDouble(p2["END_Y"]), Convert.ToDouble(p2["END_Z"]));
                Point st3 = new Point(Convert.ToDouble(p1["END_X"]), Convert.ToDouble(p1["END_Y"]), Convert.ToDouble(p1["END_Z"]));
                Point st4 = new Point(Convert.ToDouble(p2["START_X"]), Convert.ToDouble(p2["START_Y"]), Convert.ToDouble(p2["START_Z"]));

                LineSegment l1 = new LineSegment(st1, st2);
                LineSegment l3 = new LineSegment(st1, st3); Vector vl3 = l3.GetDirectionVector(); vl3.Normalize();
                LineSegment l4 = new LineSegment(st2, st1);
                LineSegment l5 = new LineSegment(st2, st4); Vector vl5 = l5.GetDirectionVector(); vl5.Normalize();

                st1.Translate(vl3.X * (off1 / vl3.GetLength()), vl3.Y * (off1 / vl3.GetLength()), vl3.Z * (off1 / vl3.GetLength()));
                st2.Translate(vl5.X * (off2 / vl5.GetLength()), vl5.Y * (off2 / vl5.GetLength()), vl5.Z * (off2 / vl5.GetLength()));


                ControlLine cl1 = new ControlLine(l1, true);
                cl1.Color = ControlLine.ControlLineColorEnum.YELLOW_RED;

                //cl1.Insert();

                CoordinateSystem cs1 = new CoordinateSystem();
                cs1 = part.GetCoordinateSystem();
                CoordinateSystem cs2 = new CoordinateSystem();
                cs2 = part2.GetCoordinateSystem();

                Tekla.Structures.Model.Plane pl1 = new Tekla.Structures.Model.Plane();
                pl1.AxisX  = cs1.AxisX;
                pl1.AxisY  = cs1.AxisY;
                pl1.Origin = cs1.Origin;

                Tekla.Structures.Model.Plane pl2 = new Tekla.Structures.Model.Plane();
                pl2.AxisX  = cs2.AxisX;
                pl2.AxisY  = cs2.AxisY;
                pl2.Origin = cs2.Origin;

                GeometricPlane gp1 = new GeometricPlane(cs1);
                GeometricPlane gp2 = new GeometricPlane(cs2);

                ControlPlane cp1 = new ControlPlane(pl1, true);
                //cp1.Insert();
                ControlPlane cp2 = new ControlPlane(pl2, true);
                //cp2.Insert();

                LineSegment l2 = Projection.LineSegmentToPlane(l1, gp1);
                LineSegment l6 = Projection.LineSegmentToPlane(l4, gp2);

                ControlLine cl2 = new ControlLine(l2, true);
                ControlLine cl3 = new ControlLine(l6, true);


                cl2.Color = ControlLine.ControlLineColorEnum.YELLOW_RED;
                //cl2.Insert();
                cl3.Color = ControlLine.ControlLineColorEnum.YELLOW_RED;
                //cl3.Insert();

                Part         p3   = part as Part;
                Solid        sl1  = p3.GetSolid();
                ArrayList    al1  = sl1.Intersect(l2);
                Point        px   = new Point(al1[1] as Point);
                ControlPoint cpp1 = new ControlPoint(px);
                //cpp1.Insert();

                Part         p4   = part2 as Part;
                Solid        sl2  = p4.GetSolid();
                ArrayList    al2  = sl2.Intersect(l6);
                Point        py   = new Point(al2[1] as Point);
                ControlPoint cpp4 = new ControlPoint(py);
                //cpp4.Insert();

                double distance  = Distance.PointToLineSegment(st3, l2);
                double distance1 = l3.Length();
                double cos       = distance / distance1;
                double distance2 = Distance.PointToLineSegment(st4, l6);
                double distance3 = l5.Length();
                double cos1      = distance2 / distance3;

                Point        p10  = dlugosc(st1, st3, 4, cos, px);
                ControlPoint cpp2 = new ControlPoint(p10);
                //cpp2.Insert();
                Point        p20  = dlugosc(st2, st4, 4, cos1, py);
                ControlPoint cpp5 = new ControlPoint(p20);
                //cpp5.Insert();


                Point  p5   = new Point(l2.StartPoint);
                Point  p6   = new Point(l2.EndPoint);
                Vector v1   = new Vector((p6.X - p5.X) / 10000, (p6.Y - p5.Y) / 10000, (p6.Z - p5.Z) / 10000);
                double v1d  = v1.GetLength();
                double dlbl = Convert.ToDouble(textBox2.Text);
                Point  p11  = new Point(px);
                p11.Translate(v1.X * (dlbl / v1d), v1.Y * (dlbl / v1d), v1.Z * (dlbl / v1d));
                Point        p12  = dlugosc(st1, st3, 4, cos, p11);
                ControlPoint cpp3 = new ControlPoint(p12);
                //cpp3.Insert();
                Point  p7    = new Point(l6.StartPoint);
                Point  p8    = new Point(l6.EndPoint);
                Vector v2    = new Vector((p8.X - p7.X) / 10000, (p8.Y - p7.Y) / 10000, (p8.Z - p7.Z) / 10000);
                double v2d   = v2.GetLength();
                double dlbl1 = Convert.ToDouble(textBox2.Text);
                Point  p21   = new Point(py);
                p21.Translate(v2.X * (dlbl1 / v2d), v2.Y * (dlbl1 / v2d), v2.Z * (dlbl1 / v2d));
                Point        p22  = dlugosc(st2, st4, 4, cos1, p21);
                ControlPoint cpp6 = new ControlPoint(p22);
                //cpp6.Insert();


                Beam blachast = CreateBlacha(p10, p12, rotpart, 0, textBox1.Text);
                blachast.Insert();
                int        id1  = blachast.Identifier.ID;
                Identifier id11 = new Identifier(id1);
                MyModel.GetWorkPlaneHandler().SetCurrentTransformationPlane(setWorkPlane(st1, vl3, v1));
                ModelObject blachast3   = MyModel.SelectModelObject(id11);
                double      rotblachast = (blachast3 as Beam).Position.RotationOffset;
                MyModel.GetWorkPlaneHandler().SetCurrentTransformationPlane(currentPlane);
                //textBox1.Text = Convert.ToString(rotblachast);
                blachast.Position.RotationOffset = -rotblachast;
                blachast.PartNumber.Prefix       = "PL";
                blachast.PartNumber.StartNumber  = 1001;
                blachast.Modify();


                Beam blachast2 = CreateBlacha(p20, p22, rotpart2, 1, textBox1.Text);
                blachast2.Insert();
                int        id2  = blachast2.Identifier.ID;
                Identifier id12 = new Identifier(id2);
                MyModel.GetWorkPlaneHandler().SetCurrentTransformationPlane(setWorkPlane(st2, vl5, v2));
                ModelObject blachast4    = MyModel.SelectModelObject(id12);
                double      rotblachast2 = (blachast4 as Beam).Position.RotationOffset;
                MyModel.GetWorkPlaneHandler().SetCurrentTransformationPlane(currentPlane);
                blachast2.Position.RotationOffset = -rotblachast2;
                blachast2.PartNumber.Prefix       = "PL";
                blachast2.PartNumber.StartNumber  = 1001;
                blachast2.Modify();

                Point p15 = new Point(p12);
                p15.Translate(v1.X * (-30 / v1d), v1.Y * (-30 / v1d), v1.Z * (-30 / v1d));
                ControlPoint cpp7 = new ControlPoint(p15);
                //cpp7.Insert();

                Point p16 = new Point(p22);
                p16.Translate(v2.X * (-30 / v2d), v2.Y * (-30 / v2d), v2.Z * (-30 / v2d));
                ControlPoint cpp8 = new ControlPoint(p16);
                //cpp8.Insert();

                Vector v11516 = new Vector((p16.X - p15.X) / 10000, (p16.Y - p15.Y) / 10000, (p16.Z - p15.Z) / 10000);

                Point p151 = new Point(p15); Point p152 = new Point(p15); Point p153 = new Point(p15);
                Point p161 = new Point(p16); Point p162 = new Point(p16); Point p163 = new Point(p16);

                p151.Translate(v11516.X * (-30 / v11516.GetLength()), v11516.Y * (-30 / v11516.GetLength()), v11516.Z * (-30 / v11516.GetLength()));
                p152.Translate(v11516.X * (120 / v11516.GetLength()), v11516.Y * (120 / v11516.GetLength()), v11516.Z * (120 / v11516.GetLength()));
                p153.Translate(v11516.X * (70 / v11516.GetLength()), v11516.Y * (70 / v11516.GetLength()), v11516.Z * (70 / v11516.GetLength()));

                p161.Translate(v11516.X * (30 / v11516.GetLength()), v11516.Y * (30 / v11516.GetLength()), v11516.Z * (30 / v11516.GetLength()));
                p162.Translate(v11516.X * (-120 / v11516.GetLength()), v11516.Y * (-120 / v11516.GetLength()), v11516.Z * (-120 / v11516.GetLength()));
                p163.Translate(v11516.X * (-70 / v11516.GetLength()), v11516.Y * (-70 / v11516.GetLength()), v11516.Z * (-70 / v11516.GetLength()));

                Beam BlSt1 = BlachaSt(p151, p152, 0);
                BlSt1.Insert();
                int        id3  = BlSt1.Identifier.ID;
                Identifier id13 = new Identifier(id3);
                MyModel.GetWorkPlaneHandler().SetCurrentTransformationPlane(setWorkPlane(st1, vl3, v1));
                ModelObject blachast5 = MyModel.SelectModelObject(id13);
                double      rot5      = (blachast5 as Beam).Position.RotationOffset;
                MyModel.GetWorkPlaneHandler().SetCurrentTransformationPlane(currentPlane);
                //textBox1.Text = Convert.ToString(rotblachast);
                BlSt1.Position.RotationOffset = -rot5;
                BlSt1.PartNumber.Prefix       = "PL";
                BlSt1.PartNumber.StartNumber  = 1001;
                BlSt1.Modify();

                Beam BlSt2 = BlachaSt(p161, p162, 1);
                BlSt2.Insert();
                int        id4  = BlSt2.Identifier.ID;
                Identifier id14 = new Identifier(id4);
                MyModel.GetWorkPlaneHandler().SetCurrentTransformationPlane(setWorkPlane(st2, vl5, v2));
                ModelObject blachast6 = MyModel.SelectModelObject(id14);
                double      rot6      = (blachast6 as Beam).Position.RotationOffset;
                MyModel.GetWorkPlaneHandler().SetCurrentTransformationPlane(currentPlane);
                //textBox1.Text = Convert.ToString(rotblachast);
                BlSt2.Position.RotationOffset = -rot6;
                BlSt2.PartNumber.Prefix       = "PL";
                BlSt2.PartNumber.StartNumber  = 1001;
                BlSt2.Modify();

                Beam St12 = CreateStezenie12(p153, p163);
                St12.Insert();
                int        id5  = St12.Identifier.ID;
                Identifier id15 = new Identifier(id5);
                MyModel.GetWorkPlaneHandler().SetCurrentTransformationPlane(setWorkPlane(st1, vl3, v1));
                ModelObject stezenie1 = MyModel.SelectModelObject(id15);
                (stezenie1 as Beam).StartPointOffset.Dy    = 4;
                (stezenie1 as Part).PartNumber.Prefix      = "Pr";
                (stezenie1 as Part).PartNumber.StartNumber = 1001;
                stezenie1.Modify();
                MyModel.GetWorkPlaneHandler().SetCurrentTransformationPlane(currentPlane);
                MyModel.GetWorkPlaneHandler().SetCurrentTransformationPlane(setWorkPlane(st2, vl5, v2));
                ModelObject stezenie2 = MyModel.SelectModelObject(id15);
                (stezenie2 as Beam).EndPointOffset.Dy      = -6;
                (stezenie2 as Part).PartNumber.Prefix      = "Pr";
                (stezenie2 as Part).PartNumber.StartNumber = 1001;
                stezenie2.Modify();
                MyModel.GetWorkPlaneHandler().SetCurrentTransformationPlane(currentPlane);

                double split      = Convert.ToDouble(textBox3.Text);
                Point  pointsplit = new Point(p163);
                pointsplit.Translate(v11516.X * (-split / v11516.GetLength()), v11516.Y * (-split / v11516.GetLength()), v11516.Z * (-split / v11516.GetLength()));


                BoltArray b1 = sruby(p151, p152, BlSt1, blachast);
                b1.Insert();
                int        id6  = b1.Identifier.ID;
                Identifier id16 = new Identifier(id6);
                MyModel.GetWorkPlaneHandler().SetCurrentTransformationPlane(setWorkPlane(st1, vl3, v1));
                ModelObject b1m = MyModel.SelectModelObject(id16);
                (b1m as BoltArray).Position.RotationOffset = 0;
                (b1m as BoltArray).BoltStandard            = "4017-8.8";
                (b1m as BoltArray).ExtraLength             = 5;
                b1m.Modify();
                MyModel.GetWorkPlaneHandler().SetCurrentTransformationPlane(currentPlane);

                BoltArray b2 = sruby(p161, p162, BlSt2, blachast2);
                b2.Insert();
                int        id7  = b2.Identifier.ID;
                Identifier id17 = new Identifier(id7);
                MyModel.GetWorkPlaneHandler().SetCurrentTransformationPlane(setWorkPlane(st2, vl5, v2));
                ModelObject b2m = MyModel.SelectModelObject(id17);
                (b2m as BoltArray).Position.RotationOffset = 180;
                b2m.Modify();
                MyModel.GetWorkPlaneHandler().SetCurrentTransformationPlane(currentPlane);


                Weld w  = new Weld();
                Weld w2 = new Weld();
                Weld w3 = new Weld();
                Weld w4 = new Weld();
                w.MainObject      = stezenie2;
                w.SecondaryObject = BlSt1;
                w.ShopWeld        = true;
                w.Insert();
                w2.MainObject      = stezenie2;
                w2.SecondaryObject = BlSt2;
                w2.ShopWeld        = true;
                w2.Insert();
                w3.MainObject      = part;
                w3.SecondaryObject = blachast;
                w3.ShopWeld        = true;
                w3.Insert();
                w4.MainObject      = part2;
                w4.SecondaryObject = blachast2;
                w4.ShopWeld        = true;
                w4.Insert();
                Beam       st122 = Operation.Split(stezenie2 as Beam, pointsplit);
                Connection sr    = new Connection();
                sr.Name   = "Połączenie śrubą rzymską";
                sr.Number = 126;
                sr.LoadAttributesFromFile("82269_M12");
                sr.SetPrimaryObject(stezenie2);
                sr.SetSecondaryObject(st122);
                sr.Insert();
            }


            MyModel.CommitChanges();
        }