Exemplo n.º 1
0
        public void SpsDoc(int n_str, string text, string dat, int n_doc)
        {
            IKompasDocument doc   = appl.Documents.Open(path[n_doc], true, false);// Получаем интерфейс активного документа 2D в API7
            ksSpcDocument   DocS  = (ksSpcDocument)kompas.SpcActiveDocument();
            ksStamp         stamp = DocS.GetStamp();



            stamp.ksOpenStamp();

            //_______________________________________
            LayoutSheets _ls   = doc.LayoutSheets;
            LayoutSheet  LS    = _ls.ItemByNumber[1];
            var          q     = _ls.ItemByNumber[1].Stamp;
            IStamp       isamp = LS.Stamp;
            IText        qq    = isamp.Text[10];

            Console.WriteLine("Есть ли руковод -------------  " + qq.Str);
            //________________________________________


            stamp.ksColumnNumber(120);
            ksTextItemParam itemParam = (ksTextItemParam)kompas.GetParamStruct((short)StructType2DEnum.ko_TextItemParam);

            if (itemParam != null)
            {
                itemParam.Init();

                ksTextItemFont itemFont = (ksTextItemFont)itemParam.GetItemFont();
                if (itemFont != null)
                {
                    itemFont.SetBitVectorValue(ldefin2d.NEW_LINE, true);
                    itemFont.fontName = "Staccato222 BT";

                    itemParam.s = "44444";
                    stamp.ksTextLine(itemParam);
                }
            }

            stamp.ksCloseStamp();
        }
Exemplo n.º 2
0
        public void Doc2D(int n_str, int n_str_dat, string text, string dat, int n_doc, bool ruk = false)
        {
            IKompasDocument doc   = appl.Documents.Open(path[n_doc], true, false);// Получаем интерфейс активного документа 2D в API7
            ksDocument2D    docD  = (ksDocument2D)kompas.ActiveDocument2D();
            ksStamp         stamp = (ksStamp)docD.GetStamp();

            Console.WriteLine("функция Doc2D ");


            stamp.ksOpenStamp();


            //_____________________________________________________________
            LayoutSheets _ls   = doc.LayoutSheets;
            LayoutSheet  LS    = _ls.ItemByNumber[1];
            IStamp       isamp = LS.Stamp;
            IText        qq    = isamp.Text[10];

            Console.WriteLine("Есть ли руководитель -------------  " + qq.Str);
            //_____________________________________________________________



            stamp.ksColumnNumber(n_str);
            ksTextItemParam itemParam = (ksTextItemParam)kompas.GetParamStruct((short)StructType2DEnum.ko_TextItemParam);

            if (itemParam != null)
            {
                itemParam.Init();

                ksTextItemFont itemFont = (ksTextItemFont)itemParam.GetItemFont();
                if (itemFont != null)
                {
                    itemFont.SetBitVectorValue(ldefin2d.NEW_LINE, true);
                    itemParam.s = text;
                    docD.ksTextLine(itemParam);
                }
            }

            stamp.ksColumnNumber(n_str_dat);

            if (itemParam != null)
            {
                itemParam.Init();

                ksTextItemFont itemFont = (ksTextItemFont)itemParam.GetItemFont();
                if (itemFont != null)
                {
                    itemFont.SetBitVectorValue(ldefin2d.NEW_LINE, true);
                    itemParam.s = dat;
                    docD.ksTextLine(itemParam);
                }
            }


            if (ruk == true)
            {
                stamp.ksColumnNumber(123);

                if (itemParam != null)
                {
                    itemParam.Init();

                    ksTextItemFont itemFont = (ksTextItemFont)itemParam.GetItemFont();
                    if (itemFont != null)
                    {
                        itemFont.SetBitVectorValue(ldefin2d.NEW_LINE, true);
                        itemParam.s = textBox2.Text;
                        docD.ksTextLine(itemParam);
                    }
                }


                stamp.ksColumnNumber(133);

                if (itemParam != null)
                {
                    itemParam.Init();

                    ksTextItemFont itemFont = (ksTextItemFont)itemParam.GetItemFont();
                    if (itemFont != null)
                    {
                        itemFont.SetBitVectorValue(ldefin2d.NEW_LINE, true);
                        itemParam.s = dat;
                        docD.ksTextLine(itemParam);
                    }
                }
            }

            stamp.ksCloseStamp();



            //doc.Close(0); //Закрыть документ
        }
Exemplo n.º 3
0
        public void START()
        {
            int stolb     = 1; //   A - B - C - D     //Cells(5, 3) = C5
            int stroka    = 1; //  1-2-3
            int nomer_Sps = 1;



            spec_stroka[] Spisok_dok = new spec_stroka[1500];



            //for (int i1 = 0; i1 <1000;i1++)
            //{
            //    Sps[i1] = new spec_stroka();
            //}



            Console.WriteLine("Количество документов = " + path.Count);
            for (int i = 0; i < path.Count; i++)
            {
                IKompasDocument doc = appl.Documents.Open(path[i], false, false);// Получаем интерфейс активного документа 2D в API7
                Console.WriteLine("Получение спецификации из документа № - " + Convert.ToInt32(i + 1));

                SpecificationDescription Specification_Descriptions = doc.SpecificationDescriptions.Active;



                if (Specification_Descriptions != null)
                {
                    ISpecificationCommentObjects SpcObjects     = Specification_Descriptions.CommentObjects;
                    ISpecificationBaseObjects    SpcObjectsBase = Specification_Descriptions.BaseObjects;


                    //Console.WriteLine(" ВСПОМОГАТЕЛЬНЫЕ объекты " + SpcObjects.Count);
                    //Console.WriteLine(" Базовые объекты " + SpcObjectsBase.Count);
                    int kol_com  = SpcObjects.Count;
                    int kol_base = SpcObjectsBase.Count;

                    if (kol_com == 0 & kol_base > 0)
                    {
                        tip_obj_base = true;
                        num          = kol_base;
                    }
                    if (kol_base == 0 & kol_com > 0)
                    {
                        tip_obj_base = false;
                        num          = kol_com;
                    }



                    ISpecificationObject  Specification_Object;
                    ISpecificationColumns Specification_Columns;
                    ISpecificationColumn  Specification_Column;

                    // Начало блока вспомагательных объктов
                    for (int SD = 0; SD < num; SD++)
                    {
                        Console.WriteLine("----- Строка " + (SD + 1) + "   ---- ");
                        Console.WriteLine("");
                        //var ww = SpcObjects[SD];
                        if (!tip_obj_base)
                        {
                            ISpecificationCommentObject obj = SpcObjects[SD];
                            var OBJ = obj;
                            ISpecificationColumns oC = obj.Columns;
                            int qq = obj.Section;
                            Console.WriteLine("!!!!СЕКЦИЯ " + (qq) + "   !!!!!");
                            Specification_Object = obj;
                            nomer_razdela        = qq;
                            //5 - документация   10 - комплексы    15 - сборочные единицы   20 - детали    25 - стандартные изделия   30 - прочие изделия    35 - материалы      40 - комплекты
                        }
                        else
                        {
                            ISpecificationBaseObject obj_base = SpcObjectsBase[SD];
                            var OBJ = obj_base;
                            ISpecificationColumns oC = obj_base.Columns;
                            int qq = obj_base.Section;
                            Console.WriteLine("!!!!СЕКЦИЯ " + (qq) + "   !!!!!");
                            Specification_Object = obj_base;
                            nomer_razdela_base   = qq;
                        }

                        if (((nomer_razdela == 5) | (nomer_razdela_base == 5)) & (i != 0))
                        {
                            Console.WriteLine("----------------Пропуск раздела документация-------------------");
                            continue;
                        }
                        else
                        {
                            Sps[nomer_Sps]          = new spec_stroka();
                            Sps[nomer_Sps].doc_name = ObrezFileName(path[i]);
                            Sps[nomer_Sps].sortir   = false;


                            if (nomer_razdela == 5 | nomer_razdela_base == 5)
                            {
                                Sps[nomer_Sps].tip_stroki = "CБ";
                                Console.WriteLine("----------------Запись раздела документация  ГЛАВНОГО ДОКУМЕНТА-------------------");
                            }

                            if (nomer_razdela == 15 | nomer_razdela_base == 15)
                            {
                                Sps[nomer_Sps].tip_stroki = "CБ";
                            }
                            if (nomer_razdela == 25 | nomer_razdela_base == 25)
                            {
                                Sps[nomer_Sps].tip_stroki = "СТ";
                            }
                            if (nomer_razdela == 30 | nomer_razdela_base == 30)
                            {
                                Sps[nomer_Sps].tip_stroki = "П";
                            }
                            if (nomer_razdela == 35 | nomer_razdela_base == 35)
                            {
                                Sps[nomer_Sps].tip_stroki = "М";
                            }



                            Specification_Columns = Specification_Object.Columns;

                            for (int bCol = 0; bCol < Specification_Columns.Count; bCol++)
                            {
                                Specification_Column = Specification_Columns[bCol];
                                var st = Specification_Column.Text.Str;
                                Console.WriteLine("Столбец " + (bCol + 1) + " - " + st);

                                //Заполнение      /////////////////////////////////////                            ///////////////////////////
                                //sheet.Cells[stroka, stolb] = st;
                                if (nomer_razdela == 20 | nomer_razdela_base == 20)
                                {
                                    if (bCol == 0)
                                    {
                                        if (st != "БЧ")
                                        {
                                            Sps[nomer_Sps].tip_stroki = "Д";
                                        }
                                        else
                                        {
                                            Sps[nomer_Sps].tip_stroki = "БЧ";
                                        }
                                    }
                                }

                                switch (bCol)
                                {
                                case 0:
                                    Sps[nomer_Sps].format = st;


                                    break;

                                case 2:
                                    Sps[nomer_Sps].poz = st;
                                    break;

                                case 3:
                                    //Sps[nomer_Sps].obozn = st;
                                    Sps[nomer_Sps].obozn = ObrezSB(st);
                                    break;

                                case 4:
                                    //Sps[nomer_Sps].naimen = st;
                                    if (nomer_razdela == 5 | nomer_razdela_base == 5)
                                    {
                                        Sps[nomer_Sps].naimen = textBox4.Text;
                                    }
                                    else
                                    {
                                        Sps[nomer_Sps].naimen = Regex.Replace(st, @"[ \n]", " ");
                                    }

                                    break;

                                case 5:
                                    Sps[nomer_Sps].kol = st;
                                    break;

                                case 6:
                                    Sps[nomer_Sps].prim = st;
                                    break;
                                }

                                //stolb += 1;
                            }

                            Console.WriteLine("----- Конец cтроки ---- ");
                            // stolb = 1;
                            //stroka += 1;
                            nomer_Sps         += 1;
                            nomer_razdela      = 0;
                            nomer_razdela_base = 0;
                        }
                    }



                    if (doc != null)
                    {
                        doc.Close(0); //Закрыть документ
                    }
                }
                else
                {
                    Console.WriteLine("Пропущен документ (документ не спецификации, и не на чертеже)");
                    if (doc != null)
                    {
                        ksDocument2D docD  = (ksDocument2D)kompas.ActiveDocument2D();
                        ksStamp      stamp = (ksStamp)docD.GetStamp();


                        LayoutSheets _ls   = doc.LayoutSheets;
                        LayoutSheet  LS    = _ls.ItemByNumber[1];
                        IStamp       isamp = LS.Stamp;
                        IText        qq    = isamp.Text[3];
                        IText        ww    = isamp.Text[2];

                        Console.WriteLine("ШТАМП Материал -------------  " + qq.Str);
                        Console.WriteLine("ШТАМП Обозначение -------------  " + ww.Str);

                        Sps[nomer_Sps]            = new spec_stroka();
                        Sps[nomer_Sps].doc_name   = ObrezFileName(path[i]);
                        Sps[nomer_Sps].obozn      = ww.Str;
                        Sps[nomer_Sps].tip_stroki = "Материал из детали";
                        Sps[nomer_Sps].material   = qq.Str;
                        Sps[nomer_Sps].sortir     = false;

                        nomer_Sps += 1;
                        doc.Close(0); //Закрыть документ
                    }
                }

                doc.Close(0);
                Console.WriteLine("");
                Console.WriteLine("-Проверка-");
            }



            ////////////////////////////////////////////////////////////////////////////////////////

            //sheet.Columns["D:D"].ColumnWidth = 16.0;
            // sheet.Columns["E:E"].ColumnWidth = 25.0;


            try
            {
                //ex.Application.ActiveWorkbook.SaveAs("D:\\1111111111111111111.xlsx", Type.Missing,
                // Type.Missing, Type.Missing, Type.Missing, Type.Missing, Excel.XlSaveAsAccessMode.xlNoChange,
                //Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing);
            }
            catch
            {
                MessageBox.Show("Сперва закройте БазуНСИ");
            }



            ///////////////////////////////////////////

            /*
             *
             * workBook = null;
             * sheet = null;
             * //ex.Quit();
             * ex = null;
             * GC.Collect();
             *
             */



            for (int i2 = 0; i2 < 1500; i2++)
            {
                if (Sps[i2] != null)
                {
                    if (Sps[i2].sortir != null)
                    {
                        Sps[i2].GetInfoSst();
                    }
                }
            }
        }