private void DrawVRCTable(Point3d pt, int ListIndex)
        {
            Document myDoc = Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument;
            DocumentLock myLock = myDoc.LockDocument();
            Database acCurDb = myDoc.Database;
            Editor ed = myDoc.Editor;
            List<Line> lines = new List<Line>();
            DBObjectCollection ObjColl = new DBObjectCollection();
            double x0 = pt.X, y0 = pt.Y - 10 * K, z0 = pt.Z;
            #region Objects
            lines.Add(new Line(new Point3d(x0, y0, z0), new Point3d(x0, y0 - 15 * K, z0)));
            lines.Add(new Line(new Point3d(x0, y0, z0), new Point3d(x0 + 185 * K, y0, z0)));
            lines.Add(new Line(new Point3d(x0, y0 - 15 * K, z0), new Point3d(x0 + 185 * K, y0 - 15 * K, z0)));
            lines.Add(new Line(new Point3d(x0 + 15 * K, y0, z0), new Point3d(x0 + 15 * K, y0 - 15 * K, z0)));
            lines.Add(new Line(new Point3d(x0 + 155 * K, y0, z0), new Point3d(x0 + 155 * K, y0 - 15 * K, z0)));
            lines.Add(new Line(new Point3d(x0 + 185 * K, y0, z0), new Point3d(x0 + 185 * K, y0 - 15 * K, z0)));
            MText Header = new MyText(new Point3d(x0 + 92.5 * K, pt.Y - 5 * K, z0), "Ведомость рабочих чертежей", K * 4, acCurDb, AttachmentPoint.MiddleCenter);
            MText Text1 = new MyText(new Point3d(x0 + 7.5 * K, y0 - 7.5 * K, z0), "Лист", K * 4, acCurDb, AttachmentPoint.MiddleCenter);
            MText Text2 = new MyText(new Point3d(x0 + 85 * K, y0 - 7.5 * K, z0), "Наименование", K * 4, acCurDb, AttachmentPoint.MiddleCenter);
            MText Text3 = new MyText(new Point3d(x0 + 170 * K, y0 - 7.5 * K, z0), "Примечание", K * 4, acCurDb, AttachmentPoint.MiddleCenter);
            MText[,] texts = new MText[WDIList.Count, 3];
            for (int v = 0; v < WDIList.Count; v++)
            {
                texts[v, 0] = new MText();
                texts[v, 1] = new MText();
                texts[v, 2] = new MText();
            }
            double realH = y0 - 15 * K;
            int i = 0, thisRows = 0, thisRows2 = 0, rowsCount = 0; //счетчик  thisRows - в столбце Наименований, thisRows2 - примечаний
            double h = 0, hm;
            i = ListIndex;
            h += (P1.Y - pt.Y) + 25 * K;
            if (185 * K + pt.X <= P2.X + 185 * K) //если есть место для колонки
            {
                if (185 * K + pt.X < P2.X) //колонка левее штампа
                    hm = P1.Y - P3.Y;
                else hm = P1.Y - P3.Y - 55 * K;

                while (h < hm && i < WDIList.Count)
                {
                    texts[i, 0] = new MyText(new Point3d(x0 + 7.5 * K, realH - 3 * K, z0), WDIList[i].PNum, 3 * K, acCurDb, AttachmentPoint.TopLeft);
                    texts[i, 1] = new MyText(new Point3d(x0 + (15 + 2.5) * K, realH - 3 * K, z0), WDIList[i].Name, 3 * K, acCurDb, AttachmentPoint.TopLeft);
                    thisRows = (int)RowCount(texts[i, 1], 135);
                    texts[i, 1].LineSpaceDistance = 8;
                    texts[i, 2] = new MyText(new Point3d(x0 + (155 + 1) * K, realH - 3 * K, z0), WDIList[i].Note, 3 * K, acCurDb, AttachmentPoint.TopLeft);
                    thisRows2 = (int)RowCount(texts[i, 2], 28);
                    texts[i, 2].LineSpaceDistance = 8;
                    thisRows = Math.Max(thisRows, thisRows2);
                    if (h + thisRows * 8 * K > hm) break;
                    ObjColl.Add(texts[i, 0]);
                    ObjColl.Add(texts[i, 1]);
                    ObjColl.Add(texts[i, 2]);

                    for (int x = 0; x < thisRows; x++)
                    {
                        lines.Add(new Line(new Point3d(x0, realH - 8 * K, z0), new Point3d(x0 + 185 * K, realH - 8 * K, z0)));
                        realH -= 8 * K;
                    }
                    rowsCount += thisRows;
                    h += thisRows * 8 * K;
                    i++;
                }

                lines.Add(new Line(new Point3d(x0, y0 - 15 * K, z0), new Point3d(x0, y0 - K * (15 + 8 * rowsCount), z0)));
                lines.Add(new Line(new Point3d(x0 + 15 * K, y0 - 15 * K, z0), new Point3d(x0 + 15 * K, y0 - K * (15 + 8 * rowsCount), z0)));
                lines.Add(new Line(new Point3d(x0 + 155 * K, y0 - 15 * K, z0), new Point3d(x0 + 155 * K, y0 - K * (15 + 8 * rowsCount), z0)));
                lines.Add(new Line(new Point3d(x0 + 185 * K, y0 - 15 * K, z0), new Point3d(x0 + 185 * K, y0 - K * (15 + 8 * rowsCount), z0)));

            #endregion
                BlockTableRecord btr;
                BlockTable bt;
                //DBObjectCollection ObjColl = new DBObjectCollection(); //коллекция объектов
                #region AddObjects to collection
                ObjColl.Add(Text1); ObjColl.Add(Text2); ObjColl.Add(Text3); ObjColl.Add(Header);
                //for (int m=0; m<i; m++)
                //foreach (MText m in texts) ObjColl.Add(m);
                foreach (Line l in lines) ObjColl.Add(l);
                #endregion

                Database wbd = HostApplicationServices.WorkingDatabase;
                wbd.LineWeightDisplay = true;
                Transaction trans = wbd.TransactionManager.StartTransaction();
                bt = (BlockTable)trans.GetObject(wbd.BlockTableId, OpenMode.ForRead);
                btr = (BlockTableRecord)trans.GetObject(wbd.CurrentSpaceId, OpenMode.ForWrite);
                foreach (Entity ent in ObjColl)
                {
                    btr.AppendEntity(ent);
                    trans.AddNewlyCreatedDBObject(ent, true);
                }
                trans.Commit();
                trans.Dispose();

                if (i < WDIList.Count)
                    DrawVRCTable(new Point3d(pt.X + 186 * K, pt.Y, pt.Z), i);
            }
            else if (i < WDIList.Count && PageW >= 185)//места для колонки нет - создаем новый лист
            {
                DrawBorders(new Point3d(P1.X + (-10 + PageW) * K, P1.Y + (5 - PageH) * K, P1.Z));
                DrawVRCTable(P1, i);
            }
            else MessageBox.Show("Лист слишком узок для таблицы");
        }
        //рисует рамки листа и передает координаты правого нижнего угла функции рисования штампа
        /// <summary>
        /// Функция отрисовки листа
        /// </summary>
        /// <param name="pt3d">Координата левого нижнего угла</param>
        private void DrawBorders(Point3d pt3d)
        {
            PageH = double.Parse(pHeight.Text);
            PageW = double.Parse(pWidth.Text);
            double height = PageH, width = PageW, k = double.Parse(koebox.Text); K = k;
            Document myDoc = Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument;
            DocumentLock myLock = myDoc.LockDocument();
            Database acCurDb = myDoc.Database;
            double x0 = pt3d.X, y0 = pt3d.Y, z0 = pt3d.Z, a = PageA;
            height *= k; width *= k;
            //if (orientcbx.Text != "альбомная") { double x = height; height = width; width = x; }
            A = PageA;
            Line left = new Line(new Point3d(x0, y0 + height, z0), new Point3d(x0, y0, z0));
            Line leftin = new Line(new Point3d(x0 + 20 * k, y0 + height - 5 * k, z0), new Point3d(x0 + 20 * k, y0 + a * k, z0));
            leftin.LineWeight = LineWeight.LineWeight030;
            Line right = new Line(new Point3d(x0 + width, y0 + height, z0), new Point3d(x0 + width, y0, z0));
            Line rightin = new Line(new Point3d(x0 + width - 5 * k, y0 + height - 5 * k, z0), new Point3d(x0 + width - 5 * k, y0 + a * k, z0));
            rightin.LineWeight = LineWeight.LineWeight030;
            Line top = new Line(new Point3d(x0, y0 + height, z0), new Point3d(x0 + width, y0 + height, z0));
            Line topin = new Line(new Point3d(x0 + 20 * k, y0 + height - 5 * k, z0), new Point3d(x0 + width - 5 * k, y0 + height - 5 * k, z0));
            topin.LineWeight = LineWeight.LineWeight030;
            Line bottom = new Line(new Point3d(x0, y0, z0), new Point3d(x0 + width, y0, z0));
            Line bottomin = new Line(new Point3d(x0 + 20 * k, y0 + a * k, z0), new Point3d(x0 + width - 5 * k, y0 + a * k, z0));
            bottomin.LineWeight = LineWeight.LineWeight030;
            Line line1 = new Line(new Point3d(x0 + 8 * k, y0 + a * k, z0), new Point3d(x0 + 20 * k, y0 + a * k, z0));
            line1.LineWeight = LineWeight.LineWeight030;
            Line line2 = new Line(new Point3d(x0 + 8 * k, y0 + (a + 25) * k, z0), new Point3d(x0 + 20 * k, y0 + (a + 25) * k, z0));
            line2.LineWeight = LineWeight.LineWeight030;
            Line line3 = new Line(new Point3d(x0 + 8 * k, y0 + (a + 60) * k, z0), new Point3d(x0 + 20 * k, y0 + (a + 60) * k, z0));
            line3.LineWeight = LineWeight.LineWeight030;
            Line line4 = new Line(new Point3d(x0 + 8 * k, y0 + (a + 85) * k, z0), new Point3d(x0 + 20 * k, y0 + (a + 85) * k, z0));
            line4.LineWeight = LineWeight.LineWeight030;
            Line line5 = new Line(new Point3d(x0 + 8 * k, y0 + a * k, z0), new Point3d(x0 + 8 * k, y0 + (a + 85) * k, z0));
            line5.LineWeight = LineWeight.LineWeight030;
            Line line6 = new Line(new Point3d(x0 + 13 * k, y0 + a * k, z0), new Point3d(x0 + 13 * k, y0 + (a + 85) * k, z0));
            line6.LineWeight = LineWeight.LineWeight030;
            MText Text1 = new MyText(new Point3d(x0 + 10.5 * k, y0 + (12.5 + a) * k, z0), "Инв. № подл.", k * (5 - 2.3), acCurDb, AttachmentPoint.MiddleCenter, 90);
            MText Text2 = new MyText(new Point3d(x0 + 10.5 * k, y0 + (42.5 + a) * k, z0), "Подп. и дата", k * (5 - 2.3), acCurDb, AttachmentPoint.MiddleCenter, 90);
            MText Text3 = new MyText(new Point3d(x0 + 10.5 * k, y0 + (72.5 + a) * k, z0), "Взам. инв. №", k * (5 - 2.3), acCurDb, AttachmentPoint.MiddleCenter, 90);
            MText Text4 = new MyText(new Point3d(x0 + 2.5 * k, y0 + (86 + a) * k, z0), "Согласовано", k * (5 - 2.3), acCurDb, AttachmentPoint.MiddleLeft, 90);
            MText Text5 = new MyText(new Point3d(x0 + (width - 85) * k, y0 + a / 2 * k, z0), "Копировал", k * 3, acCurDb, AttachmentPoint.MiddleCenter);
            MText Text6 = new MyText(new Point3d(x0 + (width - 25) * k, y0 + a / 2 * k, z0), "Формат   " + formatcbx.Text, k * 3, acCurDb, AttachmentPoint.MiddleCenter);

            DBObjectCollection ObjColl = new DBObjectCollection();
            ObjColl.Add(left); ObjColl.Add(leftin); ObjColl.Add(right); ObjColl.Add(rightin);
            ObjColl.Add(top); ObjColl.Add(topin); ObjColl.Add(bottom); ObjColl.Add(bottomin);
            ObjColl.Add(line1); ObjColl.Add(line2); ObjColl.Add(line3); ObjColl.Add(line4); ObjColl.Add(line5); ObjColl.Add(line6);
            ObjColl.Add(Text1); ObjColl.Add(Text2); ObjColl.Add(Text3); ObjColl.Add(Text4); ObjColl.Add(Text5); ObjColl.Add(Text6);
            ObjColl.Add(new Line(new Point3d(x0, y0 + (a + 85) * k, z0), new Point3d(x0 + 20 * k, y0 + (a + 85) * k, z0)));
            ObjColl.Add(new Line(new Point3d(x0 + 5 * k, y0 + (a + 105) * k, z0), new Point3d(x0 + 20 * k, y0 + (a + 105) * k, z0)));
            ObjColl.Add(new Line(new Point3d(x0 + 5 * k, y0 + (a + 125) * k, z0), new Point3d(x0 + 20 * k, y0 + (a + 125) * k, z0)));
            ObjColl.Add(new Line(new Point3d(x0 + 5 * k, y0 + (a + 140) * k, z0), new Point3d(x0 + 20 * k, y0 + (a + 140) * k, z0)));
            ObjColl.Add(new Line(new Point3d(x0, y0 + (a + 150) * k, z0), new Point3d(x0 + 20 * k, y0 + (a + 150) * k, z0)));
            ObjColl.Add(new Line(new Point3d(x0 + 5 * k, y0 + (a + 85) * k, z0), new Point3d(x0 + 5 * k, y0 + (a + 150) * k, z0)));
            ObjColl.Add(new Line(new Point3d(x0 + 10 * k, y0 + (a + 85) * k, z0), new Point3d(x0 + 10 * k, y0 + (a + 150) * k, z0)));
            ObjColl.Add(new Line(new Point3d(x0 + 15 * k, y0 + (a + 85) * k, z0), new Point3d(x0 + 15 * k, y0 + (a + 150) * k, z0)));

            Database wbd = HostApplicationServices.WorkingDatabase;
            BlockTableRecord btr;
            BlockTable bt;
            Transaction trans = wbd.TransactionManager.StartTransaction();
            bt = (BlockTable)trans.GetObject(wbd.BlockTableId, OpenMode.ForRead);
            btr = (BlockTableRecord)trans.GetObject(wbd.CurrentSpaceId, OpenMode.ForWrite);
            foreach (Entity ent in ObjColl)
            {
                btr.AppendEntity(ent);
                trans.AddNewlyCreatedDBObject(ent, true);
            }
            trans.Commit();
            trans.Dispose();
            DrawStampLines(new Point3d(x0 + width - 5 * k, y0 + a * k, z0), k);
            //необходимые координаты
            Point3d InnerLeftTop = new Point3d(x0 + 20 * k, y0 + height - 5 * k, z0); P1 = InnerLeftTop;
            Point3d InnerLeftBottom = new Point3d(x0 + 20 * k, y0 + a * k, z0); P3 = InnerLeftBottom;
            Point3d StampLeftTop = new Point3d(x0 + width - 190 * k, y0 + (a + 55) * k, z0); P2 = StampLeftTop;
        }
        private void DrawLDTable(Point3d pt)
        {
            Document myDoc = Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument;
            DocumentLock myLock = myDoc.LockDocument();
            Database acCurDb = myDoc.Database;
            Editor ed = myDoc.Editor;
            List<Line> lines = new List<Line>();
            double x0 = pt.X, y0 = pt.Y - 10 * K, z0 = pt.Z;
            //double height = y0 - k * 55;
            #region Objects
            lines.Add(new Line(new Point3d(x0, y0, z0), new Point3d(x0, y0 - 15 * K, z0)));
            lines.Add(new Line(new Point3d(x0, y0, z0), new Point3d(x0 + 185 * K, y0, z0)));
            lines.Add(new Line(new Point3d(x0, y0 - 15 * K, z0), new Point3d(x0 + 185 * K, y0 - 15 * K, z0)));
            lines.Add(new Line(new Point3d(x0 + 60 * K, y0, z0), new Point3d(x0 + 60 * K, y0 - 15 * K, z0)));
            lines.Add(new Line(new Point3d(x0 + 155 * K, y0, z0), new Point3d(x0 + 155 * K, y0 - 15 * K, z0)));
            lines.Add(new Line(new Point3d(x0 + 185 * K, y0, z0), new Point3d(x0 + 185 * K, y0 - 15 * K, z0)));
            MText Header = new MyText(new Point3d(x0 + 92.5 * K, pt.Y - 5 * K, z0), "Ведомость прилагаемых документов", K * 4, acCurDb, AttachmentPoint.MiddleCenter);
            MText Text1 = new MyText(new Point3d(x0 + 30 * K, y0 - 7.5 * K, z0), "Обозначение", K * 4, acCurDb, AttachmentPoint.MiddleCenter);
            MText Text2 = new MyText(new Point3d(x0 + 107.5 * K, y0 - 7.5 * K, z0), "Наименование", K * 4, acCurDb, AttachmentPoint.MiddleCenter);
            MText Text3 = new MyText(new Point3d(x0 + 170 * K, y0 - 7.5 * K, z0), "Примечание", K * 4, acCurDb, AttachmentPoint.MiddleCenter);
            MText[,] texts = new MText[LDIList.Count, 3];
            double realH = y0 - 15 * K;
            int i = 0, thisRows = 0, thisRows2 = 0, rowsCount = 0; //счетчик  thisRows - в столбце Наименований, thisRows2 - примечаний

            //считаем кол-во строк
            for (i = 0; i < LDIList.Count; i++)
            {
                texts[i, 0] = new MyText(new Point3d(x0 + 30 * K, realH - 3 * K, z0), LDIList[i].Label, 3 * K, acCurDb, AttachmentPoint.TopCenter);
                texts[i, 1] = new MyText(new Point3d(x0 + (60 + 2.5) * K, realH - 3 * K, z0), LDIList[i].Name, 3 * K, acCurDb, AttachmentPoint.TopLeft);
                thisRows = (int)RowCount(texts[i, 1], 90);
                texts[i, 1].LineSpaceDistance = 8;
                texts[i, 2] = new MyText(new Point3d(x0 + (155 + 1) * K, realH - 3 * K, z0), LDIList[i].Note, 3 * K, acCurDb, AttachmentPoint.TopLeft);
                thisRows2 = (int)RowCount(texts[i, 2], 28);
                texts[i, 2].LineSpaceDistance = 8;
                thisRows = Math.Max(thisRows, thisRows2);
                for (int x = 0; x < thisRows; x++)
                {
                    lines.Add(new Line(new Point3d(x0, realH - 8 * K, z0), new Point3d(x0 + 185 * K, realH - 8 * K, z0)));
                    realH -= 8 * K;
                }
                rowsCount += thisRows;
            }
            lines.Add(new Line(new Point3d(x0, y0 - 15 * K, z0), new Point3d(x0, y0 - K * (15 + 8 * rowsCount), z0)));
            lines.Add(new Line(new Point3d(x0 + 60 * K, y0 - 15 * K, z0), new Point3d(x0 + 60 * K, y0 - K * (15 + 8 * rowsCount), z0)));
            lines.Add(new Line(new Point3d(x0 + 155 * K, y0 - 15 * K, z0), new Point3d(x0 + 155 * K, y0 - K * (15 + 8 * rowsCount), z0)));
            lines.Add(new Line(new Point3d(x0 + 185 * K, y0 - 15 * K, z0), new Point3d(x0 + 185 * K, y0 - K * (15 + 8 * rowsCount), z0)));

            #endregion
            BlockTableRecord btr;
            BlockTable bt;
            DBObjectCollection ObjColl = new DBObjectCollection(); //коллекция объектов
            #region AddObjects to collection
            ObjColl.Add(Text1); ObjColl.Add(Text2); ObjColl.Add(Text3); ObjColl.Add(Header);
            foreach (MText m in texts) ObjColl.Add(m);
            foreach (Line l in lines) ObjColl.Add(l);
            #endregion

            Database wbd = HostApplicationServices.WorkingDatabase;
            wbd.LineWeightDisplay = true;
            Transaction trans = wbd.TransactionManager.StartTransaction();
            bt = (BlockTable)trans.GetObject(wbd.BlockTableId, OpenMode.ForRead);
            btr = (BlockTableRecord)trans.GetObject(wbd.CurrentSpaceId, OpenMode.ForWrite);
            foreach (Entity ent in ObjColl)
            {
                btr.AppendEntity(ent);
                trans.AddNewlyCreatedDBObject(ent, true);
            }
            trans.Commit();
            trans.Dispose();
        }
        public void TextWrite(double x0, double y0, double z0, double k)
        {
            Document acDoc = Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument;// Get the current document and database
            DocumentLock myLock = acDoc.LockDocument();
            Database AcDb = acDoc.Database;
            Editor ed = acDoc.Editor;
            double step = 0.5 * k;  //шаг уменьшения размера текста
            double FS1 = k * (5 - 2.3); //Размер стандартного шрифта
            using (Transaction acTrans = AcDb.TransactionManager.StartTransaction())// Start a transaction
            {
                BlockTable acBlkTbl;// Open the Block table record for read
                acBlkTbl = acTrans.GetObject(AcDb.BlockTableId, OpenMode.ForRead) as BlockTable;
                BlockTableRecord acBlkTblRec;// Open the Block table record Model space for write
                acBlkTblRec = acTrans.GetObject(acBlkTbl[BlockTableRecord.ModelSpace], OpenMode.ForWrite) as BlockTableRecord;
                MText[][] MTX = new MText[11][];
                #region MTEXT
                MTX[0] = new MText[7];
                MTX[0][0] = new MyText(new Point3d(x0 + 1 * k, y0 - k, z0), TBx0_0.Text, FS1, AcDb);
                MTX[0][1] = new MyText(new Point3d(x0 + (1 + 10) * k, y0 - k, z0), TBx0_1.Text, FS1, AcDb);
                MTX[0][2] = new MyText(new Point3d(x0 + (1 + 20) * k, y0 - k, z0), TBx0_2.Text, FS1, AcDb);
                MTX[0][3] = new MyText(new Point3d(x0 + (1 + 30) * k, y0 - k, z0), TBx0_3.Text, FS1, AcDb);
                MTX[0][4] = new MyText(new Point3d(x0 + (1 + 40) * k, y0 - k, z0), CBx0_4.Text, FS1, AcDb);
                MTX[0][5] = new MyText(new Point3d(x0 + (1 + 55) * k, y0 - k, z0), TBx0_5.Text, FS1, AcDb);
                MTX[0][6] = new MyText(new Point3d(x0 + 125 * k, y0 - 5 * k, z0), TBx0_6.Text, k * 5, AcDb, AttachmentPoint.MiddleCenter);
                F.MtextSize(MTX[0][6], 115, 10, k, step, 3);

                MTX[1] = new MText[6];
                MTX[1][0] = new MyText(new Point3d(x0 + 1 * k, y0 - (1 + 5) * k, z0), TBx1_0.Text, FS1, AcDb);
                MTX[1][1] = new MyText(new Point3d(x0 + (1 + 10) * k, y0 - (1 + 5) * k, z0), TBx1_1.Text, FS1, AcDb);
                MTX[1][2] = new MyText(new Point3d(x0 + (1 + 20) * k, y0 - (1 + 5) * k, z0), TBx1_2.Text, FS1, AcDb);
                MTX[1][3] = new MyText(new Point3d(x0 + (1 + 30) * k, y0 - (1 + 5) * k, z0), TBx1_3.Text, FS1, AcDb);
                MTX[1][4] = new MyText(new Point3d(x0 + (1 + 40) * k, y0 - (1 + 5) * k, z0), CBx1_4.Text, FS1, AcDb);
                MTX[1][5] = new MyText(new Point3d(x0 + (1 + 55) * k, y0 - (1 + 5) * k, z0), TBx1_5.Text, FS1, AcDb);

                MTX[2] = new MText[7];
                MTX[2][0] = new MyText(new Point3d(x0 + 1 * k, y0 - (1 + 10) * k, z0), TBx2_0.Text, FS1, AcDb);
                MTX[2][1] = new MyText(new Point3d(x0 + (1 + 10) * k, y0 - (1 + 10) * k, z0), TBx2_1.Text, FS1, AcDb);
                MTX[2][2] = new MyText(new Point3d(x0 + (1 + 20) * k, y0 - (1 + 10) * k, z0), TBx2_2.Text, FS1, AcDb);
                MTX[2][3] = new MyText(new Point3d(x0 + (1 + 30) * k, y0 - (1 + 10) * k, z0), TBx2_3.Text, FS1, AcDb);
                MTX[2][4] = new MyText(new Point3d(x0 + (1 + 40) * k, y0 - (1 + 10) * k, z0), СBx2_4.Text, FS1, AcDb);
                MTX[2][5] = new MyText(new Point3d(x0 + (1 + 55) * k, y0 - (1 + 10) * k, z0), TBx2_5.Text, FS1, AcDb);
                MTX[2][6] = new MyText(new Point3d(x0 + 125 * k, y0 - 17.5 * k, z0), TBx2_6.Text, k * 5, AcDb, AttachmentPoint.MiddleCenter);
                F.MtextSize(MTX[2][6], 115, 15, k, step, 4);

                MTX[3] = new MText[6];
                MTX[3][0] = new MyText(new Point3d(x0 + 1 * k, y0 - (1 + 15) * k, z0), TBx3_0.Text, FS1, AcDb);
                MTX[3][1] = new MyText(new Point3d(x0 + (1 + 10) * k, y0 - (1 + 15) * k, z0), TBx3_1.Text, FS1, AcDb);
                MTX[3][2] = new MyText(new Point3d(x0 + (1 + 20) * k, y0 - (1 + 15) * k, z0), TBx3_2.Text, FS1, AcDb);
                MTX[3][3] = new MyText(new Point3d(x0 + (1 + 30) * k, y0 - (1 + 15) * k, z0), TBx3_3.Text, FS1, AcDb);
                MTX[3][4] = new MyText(new Point3d(x0 + (1 + 40) * k, y0 - (1 + 15) * k, z0), CBx3_4.Text, FS1, AcDb);
                MTX[3][5] = new MyText(new Point3d(x0 + (1 + 55) * k, y0 - (1 + 15) * k, z0), TBx3_5.Text, FS1, AcDb);

                MTX[4] = new MText[6];
                MTX[4][0] = new MyText(new Point3d(x0 + k, y0 - 21 * k, z0), "Изм", FS1, AcDb);
                MTX[4][1] = new MyText(new Point3d(x0 + (10 + 1) * k, y0 - 21 * k, z0), "Кол.уч.", FS1, AcDb);
                MTX[4][2] = new MyText(new Point3d(x0 + (20 + 1) * k, y0 - 21 * k, z0), "Лист", FS1, AcDb);
                MTX[4][3] = new MyText(new Point3d(x0 + (30 + 1) * k, y0 - 21 * k, z0), "№ док.", FS1, AcDb);
                MTX[4][4] = new MyText(new Point3d(x0 + (44 + 1) * k, y0 - 21 * k, z0), "Подп.", FS1, AcDb);
                MTX[4][5] = new MyText(new Point3d(x0 + (55 + 1) * k, y0 - 21 * k, z0), "Дата", FS1, AcDb);

                MTX[5] = new MText[7];
                MTX[5][0] = new MyText(new Point3d(x0 + 1 * k, y0 - 26 * k, z0), CBx5_0.Text, FS1, AcDb);
                MTX[5][1] = new MyText(new Point3d(x0 + (0.5 + 20) * k, y0 - 27.5 * k, z0), CBx5_1.Text, FS1, AcDb, AttachmentPoint.MiddleLeft);
                F.MtextSize(MTX[5][1], 19.4, k, 0.1);
                MTX[5][2] = new MyText(new Point3d(x0 + (1 + 55) * k, y0 - (1 + 25) * k, z0), TBx5_2.Text, FS1, AcDb);
                MTX[5][3] = new MyText(new Point3d(x0 + 100 * k, y0 - 32.5 * k, z0), TBx5_3.Text, k * 4.5, AcDb, AttachmentPoint.MiddleCenter);
                F.MtextSize(MTX[5][3], 65, 15, k, step, 4);
                MTX[5][4] = new MyText(new Point3d(x0 + (135 + 1) * k, y0 - 26 * k, z0), "Стадия", FS1, AcDb);
                MTX[5][5] = new MyText(new Point3d(x0 + (150 + 1) * k, y0 - 26 * k, z0), "Лист", FS1, AcDb);
                MTX[5][6] = new MyText(new Point3d(x0 + (165 + 1) * k, y0 - 26 * k, z0), "Листов", FS1, AcDb);

                MTX[6] = new MText[6];
                MTX[6][0] = new MyText(new Point3d(x0 + 1 * k, y0 - (1 + 30) * k, z0), CBx6_0.Text, FS1, AcDb);
                MTX[6][1] = new MyText(new Point3d(x0 + ( 0.5 + 20 ) * k, y0 - 32.5 * k, z0), CBx6_1.Text, FS1, AcDb, AttachmentPoint.MiddleLeft);
                F.MtextSize(MTX[6][1], 19.4, k, 0.1);
                MTX[6][2] = new MyText(new Point3d(x0 + (1 + 55) * k, y0 - (1 + 30) * k, z0), TBx6_2.Text, FS1, AcDb);
                MTX[6][3] = new MyText(new Point3d(x0 + 142.5 * k, y0 - 35 * k, z0), CBx6_3.Text, k * 4, AcDb, AttachmentPoint.MiddleCenter);
                MTX[6][4] = new MyText(new Point3d(x0 + 157.5 * k, y0 - 35 * k, z0), TBx6_4.Text, k * 4, AcDb, AttachmentPoint.MiddleCenter);
                MTX[6][5] = new MyText(new Point3d(x0 + (1 + 175) * k, y0 - 35 * k, z0), TBx6_5.Text, k * 4, AcDb, AttachmentPoint.MiddleCenter);
                MTX[7] = new MText[3];
                MTX[7][0] = new MyText(new Point3d(x0 + 1 * k, y0 - (1 + 35) * k, z0), CBx7_0.Text, FS1, AcDb);
                MTX[7][1] = new MyText(new Point3d(x0 + (0.5 + 20) * k, y0 - 37.5 * k, z0), CBx7_1.Text, FS1, AcDb, AttachmentPoint.MiddleLeft);
                F.MtextSize(MTX[7][1], 19.4, k, 0.1);
                MTX[7][2] = new MyText(new Point3d(x0 + (1 + 55) * k, y0 - (1 + 35) * k, z0), TBx7_2.Text, FS1, AcDb);
                MTX[8] = new MText[5];
                MTX[8][0] = new MyText(new Point3d(x0 + 1 * k, y0 - (1 + 40) * k, z0), CBx8_0.Text, FS1, AcDb);
                MTX[8][1] = new MyText(new Point3d(x0 + (0.5 + 20) * k, y0 - 42.5 * k, z0), CBx8_1.Text, k * 3, AcDb, AttachmentPoint.MiddleLeft);
                F.MtextSize(MTX[8][1], 19.4, k, 0.1);
                MTX[8][2] = new MyText(new Point3d(x0 + (1 + 55) * k, y0 - (1 + 40) * k, z0), TBx8_2.Text, FS1, AcDb);
                MTX[8][3] = new MyText(new Point3d(x0 + 100 * k, y0 - 47.5 * k, z0), TBx8_3.Text, k * 4.5, AcDb, AttachmentPoint.MiddleCenter);
                F.MtextSize(MTX[8][3], 65, 15, k, step, 4);
                MTX[8][4] = new MyText(new Point3d(x0 + 185 * k, y0 - 47.5 * k, z0), TBx8_4.Text, k * 2.3, AcDb, AttachmentPoint.MiddleRight);
                MTX[9] = new MText[3];
                MTX[9][0] = new MyText(new Point3d(x0 + 1 * k, y0 - (1 + 45) * k, z0), CBx9_0.Text, FS1, AcDb);
                MTX[9][1] = new MyText(new Point3d(x0 + (0.5 + 20) * k, y0 - 47.5 * k, z0), CBx9_1.Text, k * 3, AcDb, AttachmentPoint.MiddleLeft);
                F.MtextSize(MTX[9][1], 19.4, k, 0.1);
                MTX[9][2] = new MyText(new Point3d(x0 + (1 + 55) * k, y0 - (1 + 45) * k, z0), TBx9_2.Text, FS1, AcDb);
                MTX[10] = new MText[3];
                MTX[10][0] = new MyText(new Point3d(x0 + 1 * k, y0 - (1 + 50) * k, z0), CBx10_0.Text, FS1, AcDb);
                MTX[10][1] = new MyText(new Point3d(x0 + (0.5 + 20) * k, y0 - 52.5 * k, z0), CBx10_1.Text, k * 3, AcDb, AttachmentPoint.MiddleLeft);
                F.MtextSize(MTX[10][1], 19.4, k, 0.1);
                MTX[10][2] = new MyText(new Point3d(x0 + (1 + 55) * k, y0 - (1 + 50) * k, z0), TBx10_2.Text, FS1, AcDb);

                //номер листа
                //if (isfirsttime && textb1_Copy47.Text != "-1")
                //{
                //    try
                //    {
                //        nomer_lista = int.Parse(textb1_Copy47.Text); isfirsttime = false;
                //    }
                //    catch (System.Exception ex)
                //    {
                //        nomer_lista = -1;
                //        Debug.Print("Обновление нумерации. " + ex.Message);
                //    }
                //}
                //else nomer_lista++;
                #endregion
                //Вставка подписей
                try
                {
                    if (CBx5_1.Text!="")
                        GetSign((int)CBx5_1.SelectedValue, new Point3d(x0 + (0.2 + 40) * k, y0 - (0 + 30) * k, z0));
                    if (CBx6_1.Text != "")
                        GetSign((int)CBx6_1.SelectedValue, new Point3d(x0 + (0.2 + 40) * k, y0 - (0 + 35) * k, z0));
                    if (CBx7_1.Text != "")
                        GetSign((int)CBx7_1.SelectedValue, new Point3d(x0 + (0.2 + 40) * k, y0 - (0 + 40) * k, z0));
                    if (CBx8_1.Text != "")
                        GetSign((int)CBx8_1.SelectedValue, new Point3d(x0 + (0.2 + 40) * k, y0 - (0 + 45) * k, z0));
                    if (CBx9_1.Text != "")
                        GetSign((int)CBx9_1.SelectedValue, new Point3d(x0 + (0.2 + 40) * k, y0 - (0 + 50) * k, z0));
                    if (CBx10_1.Text != "")
                        GetSign((int)CBx10_1.SelectedValue, new Point3d(x0 + (0.2 + 40) * k, y0 - (0 + 55) * k, z0));
                }
                catch (System.Exception SystEx)
                {
                    MessageBox.Show(SystEx.Message);
                }
                //Вставка логотипа
                string blockQualifiedFileName = logoStr;
                string blockName = "ETUlogo";
                Database tmpDb = new Database(false, true);
                tmpDb.ReadDwgFile(blockQualifiedFileName, System.IO.FileShare.Read, true, "");
                double scale = 1.0;
                Matrix3d Transform = Matrix3d.Identity;
                Transform = Transform * Matrix3d.Scaling(scale, Point3d.Origin);
                // add the block to the ActiveDrawing blockTable
                AcDb.Insert(blockName, tmpDb, true);
                Point3d insPt = new Point3d(x0 + 135 * k, y0 - 47.5 * k - 2.5 * k, z0);
                BlockTableRecord btr = (BlockTableRecord)acTrans.GetObject(AcDb.CurrentSpaceId, OpenMode.ForWrite);
                BlockReference br = new BlockReference(Point3d.Origin, acBlkTbl[blockName]);
                br.TransformBy(Matrix3d.Displacement(insPt - Point3d.Origin).PreMultiplyBy(ed.CurrentUserCoordinateSystem));
                btr.AppendEntity(br);
                acTrans.AddNewlyCreatedDBObject(br, true);

                //DBObjectCollection objColl = new DBObjectCollection();
                for (int i = 0; i < MTX.Length; i++)
                    for (int j = 0; j < MTX[i].Length; j++ )
                    {
                        acBlkTblRec.AppendEntity(MTX[i][j]);
                        if (i == 6 && j == 4) listobind = MTX[i][j].Id;

                        acTrans.AddNewlyCreatedDBObject(MTX[i][j], true);
                    }

                //foreach (MText[] ma in MTX)
                //    foreach (MText m in ma)
                //    {
                //        acBlkTblRec.AppendEntity(m);
                //        acTrans.AddNewlyCreatedDBObject(m, true);
                //    }
                //foreach (Entity en in objColl)
                //{
                //    acBlkTblRec.AppendEntity(en);
                //    acTrans.AddNewlyCreatedDBObject(en, true);
                //}
                acTrans.Commit();
            }
        }