private static double DrawOffset(int N1, int N2, double dist, bool boo)
        {
            double rez = 0;

            using (Transaction transaction = _db.TransactionManager.StartTransaction())
            {
                BlockTable blockTable = transaction.GetObject(_db.BlockTableId, OpenMode.ForRead) as BlockTable;

                // Open the Block table record Model space for write
                BlockTableRecord modelSpace = transaction.GetObject(blockTable[BlockTableRecord.ModelSpace], OpenMode.ForWrite) as BlockTableRecord;

                LayerTable layerTable = transaction.GetObject(_db.LayerTableId, OpenMode.ForRead) as LayerTable;

                Polyline bpLine = (Polyline)transaction.GetObject(_polylineId, OpenMode.ForWrite);

                int      off       = -1;
                Polyline firstPoly = new Polyline();
                firstPoly.SetDatabaseDefaults();

                #region make poly
                ArrayList arrayList = new ArrayList();
                for (int j = 1; j <= (bpLine.NumberOfVertices >> 1); j++)
                {
                    if ((N1 + j) > (bpLine.NumberOfVertices - 1))
                    {
                        off++;
                    }
                    int           i   = (off < 0) ? (N1 + j) : off;
                    LineSegment2d seg = bpLine.GetLineSegment2dAt(i);
                    double        bulge;
                    if ((i - 1) < 0)
                    {
                        bulge = bpLine.GetBulgeAt(bpLine.NumberOfVertices - 1);
                    }
                    else
                    {
                        if ((i - 1) > bpLine.NumberOfVertices - 1)
                        {
                            bulge = bpLine.GetBulgeAt(0);
                        }
                        else
                        {
                            bulge = -bpLine.GetBulgeAt(i - 1);
                        }
                    }
                    firstPoly.AddVertexAt(0, new Point2d(seg.StartPoint.X, seg.StartPoint.Y), bulge, 0, 0);
                    arrayList.Add(bpLine.GetBulgeAt(i));
                }

                modelSpace.AppendEntity(firstPoly);
                transaction.AddNewlyCreatedDBObject(firstPoly, true);
                #endregion

                #region coating
                if (boo)
                {
                    LineSegment2d seg1 = firstPoly.GetLineSegment2dAt(0);
                    LineSegment2d seg2 = bpLine.GetLineSegment2dAt(N2);
                    Complex       mid  = new Complex((seg2.StartPoint.X + seg2.EndPoint.X) / 2, (seg2.StartPoint.Y + seg2.EndPoint.Y) / 2);
                    Line2d        l    = new Line2d(new Complex(seg1.StartPoint.X, seg1.StartPoint.Y), new Complex(seg1.EndPoint.X, seg1.EndPoint.Y));

                    int k = l.PositionOfТhePointToLineSign(mid);

                    DBObjectCollection oc = firstPoly.GetOffsetCurves((k < 0) ? dist : -dist);
                    foreach (Entity acEnt in oc)
                    {
                        modelSpace.AppendEntity(acEnt);
                        transaction.AddNewlyCreatedDBObject(acEnt, true);
                        acEnt.TransformBy(_ed.CurrentUserCoordinateSystem);
                        try
                        {
                            acEnt.Layer = _sheetDescriptionForm.GetCoatingLayer();
                        }
                        catch
                        {
                            LayerTableRecord acLyrTblRec = transaction.GetObject(_db.Clayer, OpenMode.ForWrite) as LayerTableRecord;
                            acEnt.Layer = acLyrTblRec.Name;
                        }
                        try
                        {
                            System.Drawing.Color color = _sheetDescriptionForm.GetCoatingColor();
                            if (color.Name == "ByLayer")
                            {
                                throw new ArgumentNullException();
                            }
                            acEnt.Color = Color.FromColor(color);
                        }
                        catch
                        {
                            //LayerTableRecord acLyrTblRec = acTrans.GetObject(Db.Clayer, OpenMode.ForWrite) as LayerTableRecord;
                            LayerTableRecord acLyrTblRec = transaction.GetObject(layerTable[acEnt.Layer], OpenMode.ForWrite) as LayerTableRecord;
                            acEnt.Color = acLyrTblRec.Color;
                        }

                        _entityTemp.Add(acEnt);
                    }
                    Polyline acPoly11 = oc[0] as Polyline;
                }
                #endregion

                #region calculate length
                for (int j = 0; j < firstPoly.NumberOfVertices - 1; j++)
                {
                    if (Math.Abs(firstPoly.GetBulgeAt(j)) != 0.0)
                    {
                        CircularArc2d arc = firstPoly.GetArcSegment2dAt(j);
                        double        rad = arc.Radius;
                        double        ang = Math.Abs(Math.Atan(firstPoly.GetBulgeAt(j)));
                        rez += (4 * ang * rad);
                    }
                    else
                    {
                        LineSegment2d seg = firstPoly.GetLineSegment2dAt(j);
                        Complex       s   = new Complex(seg.StartPoint.X, seg.StartPoint.Y);
                        Complex       e   = new Complex(seg.EndPoint.X, seg.EndPoint.Y);
                        rez += (s - e).abs();
                    }
                }
                #endregion

                firstPoly.Erase();
                transaction.Commit();
            }
            _ed.Regen();
            return(rez);
        }