Ejemplo n.º 1
0
        /// <summary>
        /// Returns Lists of Custom_parts and Standard_Parts
        /// </summary>
        /// <param name="swModel"></param>
        /// <param name="swTableAnn"></param>
        /// <param name="ConfigName"></param>
        /// <param name="Standard_Parts"></param>
        /// <param name="Custom_Parts"></param>
        public static void Get_Sorted_Part_Data(ModelDoc2 swModel, BomFeature swBomFeat, List <BOM_Part_Informations> Standard_Parts, List <BOM_Part_Informations> Custom_Parts, string projectpath)
        {
            try
            {
                int nNumRow              = 0;
                int J                    = 0;
                int I                    = 0;
                int numStandard_Part     = 1;
                int numCustom_Part       = 1;
                int quantity             = 0;
                int index_description    = 0;
                int index_article_number = 0;
                int index_supplier       = 0;


                BOM_Part_Informations part_informations;



                string ItemNumber = null;
                string PartNumber = null;

                // Debug.Print("   Table Title        " + swTableAnn.Title);
                Feature  swFeat       = default(Feature);
                object[] vTableArr    = null;
                object   vTable       = null;
                string[] vConfigArray = null;
                object   vConfig      = null;
                string   ConfigName   = null;
                string   partconfig   = null;

                TableAnnotation swTable      = default(TableAnnotation);
                Annotation      swAnnotation = default(Annotation);
                object          visibility   = null;


                swFeat    = swBomFeat.GetFeature();
                vTableArr = (object[])swBomFeat.GetTableAnnotations();

                foreach (TableAnnotation vTable_loopVariable in vTableArr)
                {
                    vTable       = vTable_loopVariable;
                    swTable      = (TableAnnotation)vTable;
                    vConfigArray = (string[])swBomFeat.GetConfigurations(true, ref visibility);

                    foreach (object vConfig_loopVariable in vConfigArray)
                    {
                        vConfig    = vConfig_loopVariable;
                        ConfigName = (string)vConfig;



                        //    MessageBox.Show(ConfigName);


                        // swTable.SaveAsPDF(@"C:\Users\alex\Desktop\test.pdf");



                        nNumRow = swTable.RowCount;

                        BomTableAnnotation swBOMTableAnn = default(BomTableAnnotation);
                        swBOMTableAnn = (BomTableAnnotation)swTable;
                        //swTable.GetColumnTitle
                        for (int h = 0; h < swTable.ColumnCount; h++)
                        {
                            switch (swTable.GetColumnTitle(h))
                            {
                            case "Benennung":
                                index_description = h;
                                break;

                            case "Artikelnummer":
                                index_article_number = h;
                                break;

                            case "Lieferant":
                                index_supplier = h;
                                break;

                            default:
                                break;
                            }
                        }
                        if (index_supplier != 0 || index_supplier != 0 || index_article_number != 0) //Standard BOM Template
                        {
                            for (int n = 0; n <= nNumRow - 1; n++)
                            {
                                // Debug.Print("   Row Number " + J + " Component Count  : " + swBOMTableAnn.GetComponentsCount2(J, ConfigName, out ItemNumber, out PartNumber));
                                //  Debug.Print("       Item Number  : " + ItemNumber);
                                // Debug.Print("       Part Number  : " + PartNumber);
                                // MessageBox.Show("bubu");
                                object[]   vPtArr = null;
                                Component2 swComp = null;
                                object     pt     = null;
                                quantity = swBOMTableAnn.GetComponentsCount2(n, ConfigName, out ItemNumber, out PartNumber);

                                vPtArr = (object[])swBOMTableAnn.GetComponents2(n, ConfigName);

                                if (((vPtArr != null)))
                                {
                                    for (I = 0; I <= vPtArr.GetUpperBound(0); I++)
                                    {
                                        pt     = vPtArr[I];
                                        swComp = (Component2)pt;
                                        if ((swComp != null))
                                        {
                                            part_informations = new BOM_Part_Informations();

                                            part_informations.manufacturer = swTable.get_Text(n, index_supplier);
                                            part_informations.order_number = swTable.get_Text(n, index_article_number);
                                            part_informations.IsAssembly   = false;

                                            part_informations.part_number = PartNumber.TrimStart();
                                            part_informations.quantity    = quantity.ToString();

                                            //Custom part
                                            if (swComp.GetPathName().Contains(projectpath))
                                            {
                                                if (swComp.GetPathName().Contains(".sldasm") || swComp.GetPathName().Contains(".SLDASM"))
                                                {
                                                    // MessageBox.Show(swComp.GetPathName());
                                                    part_informations.IsAssembly = true;
                                                }

                                                part_informations.description = swComp.ReferencedConfiguration;
                                                part_informations.item_number = numCustom_Part.ToString();
                                                numCustom_Part++;

                                                Custom_Parts.Add(part_informations);
                                                break;
                                            }

                                            part_informations.description = swTable.get_Text(n, index_description);
                                            part_informations.item_number = numStandard_Part.ToString();
                                            numStandard_Part++;
                                            Standard_Parts.Add(part_informations);
                                            break;
                                        }
                                        else
                                        {
                                            Debug.Print("  Could not get component.");
                                        }
                                    }
                                }
                            }
                        }
                        else //No Standard BOM Template
                        {
                            for (J = 0; J <= nNumRow - 1; J++)
                            {
                                // Debug.Print("   Row Number " + J + " Component Count  : " + swBOMTableAnn.GetComponentsCount2(J, ConfigName, out ItemNumber, out PartNumber));
                                //  Debug.Print("       Item Number  : " + ItemNumber);
                                // Debug.Print("       Part Number  : " + PartNumber);

                                object[]   vPtArr = null;
                                Component2 swComp = null;
                                object     pt     = null;
                                quantity = swBOMTableAnn.GetComponentsCount2(J, ConfigName, out ItemNumber, out PartNumber);

                                vPtArr = (object[])swBOMTableAnn.GetComponents2(J, ConfigName);

                                if (((vPtArr != null)))
                                {
                                    for (I = 0; I <= vPtArr.GetUpperBound(0); I++)
                                    {
                                        pt     = vPtArr[I];
                                        swComp = (Component2)pt;
                                        if ((swComp != null))
                                        {
                                            part_informations = new BOM_Part_Informations();

                                            part_informations.description = swComp.ReferencedConfiguration;
                                            part_informations.part_number = PartNumber;
                                            part_informations.quantity    = quantity.ToString();
                                            //Custom part
                                            if (swComp.GetPathName().Contains(projectpath))
                                            {
                                                if (swComp.GetPathName().Contains(".sldasm") || swComp.GetPathName().Contains(".SLDASM"))
                                                {
                                                    break;
                                                }
                                                else
                                                {
                                                    part_informations.item_number = numCustom_Part.ToString();
                                                    numCustom_Part++;

                                                    Custom_Parts.Add(part_informations);
                                                    break;
                                                }
                                            }

                                            part_informations.item_number = numStandard_Part.ToString();
                                            numStandard_Part++;
                                            Standard_Parts.Add(part_informations);
                                            break;
                                        }
                                        else
                                        {
                                            Debug.Print("  Could not get component.");
                                        }
                                    }
                                }
                            }
                        }
                        break;
                    }
                }
                swAnnotation = swTable.GetAnnotation();
                swAnnotation.Select3(false, null);
                swModel.EditDelete();
            }

            catch (Exception ex)
            {
                MessageBox.Show(ex.Message + ex.StackTrace);
            }
        }
Ejemplo n.º 2
0
        public void ProcessTableAnn(BomTableAnnotation swBOMTableAnn, string ConfigName, SldAsm asmPrd)
        {
            int             nNumRow    = 0;
            string          ItemNumber = null;
            string          PartNumber = null;
            TableAnnotation swTableAnn = (TableAnnotation)swBOMTableAnn;

            Console.WriteLine("   Table Title        " + swTableAnn.Title);
            IEdmVault5 vault = new EdmVault5();

            vault.LoginAuto("科德研发部", 0);
            if (!vault.IsLoggedIn)
            {
                Console.WriteLine("登录PDM失败");
                return;
            }
            nNumRow       = swTableAnn.RowCount;
            swBOMTableAnn = (BomTableAnnotation)swTableAnn;
            for (int j = 0; j < swTableAnn.RowCount; j++)
            {
                //
                //for (int i = 0; i < swTableAnn.ColumnCount;i++ )
                //    Console.WriteLine(swTableAnn.get_Text(j, i));
                //获取类别和特有信息
                //if (j == swTableAnn.RowCount - 1)//最后一行为标题栏,跳过
                //     continue;
                string filePath   = "";
                string compName   = "";
                string compConfig = "";
                int    compCount  = swBOMTableAnn.GetComponentsCount2(j, ConfigName, out ItemNumber, out PartNumber);
                for (int i = 0; i < compCount; i++)
                {
                    Component2 comp2 = swBOMTableAnn.IGetComponents2(j, ConfigName, i);
                    if (comp2 != null)
                    {
                        filePath   = comp2.GetPathName();
                        compName   = comp2.Name2;
                        compConfig = comp2.ReferencedConfiguration;
                        Console.WriteLine("           Component Name :" + comp2.Name2 + "      Configuration Name : " + comp2.ReferencedConfiguration);
                        Console.WriteLine("           Component Path :" + comp2.GetPathName());
                    }
                }
                if (filePath == "")
                {
                    continue;
                }
                SldBsp bsp = GetSldPrdInfoFromFile(vault, filePath);
                if (bsp == null)
                {
                    continue;
                }
                bsp.path = filePath;
                //SldBsp bsp = new SldBsp();
                swTableAnn.get_Text(j, 0);                              //序号
                bsp.number = swTableAnn.get_Text(j, 1);                 //代号
                bsp.name   = swTableAnn.get_Text(j, 2);                 //名称
                string amout = swTableAnn.get_Text(j, 3);
                bsp.amout    = amout == ""?0:int.Parse(amout);          //数量
                bsp.material = swTableAnn.get_Text(j, 4);               //材料
                string weight = swTableAnn.get_Text(j, 5);
                bsp.weight      = weight == "" ? 0 : int.Parse(weight); //单重
                bsp.totalWeight = bsp.weight * bsp.amout;               // swTableAnn.get_Text(j, 6);//总重
                bsp.remark      = swTableAnn.get_Text(j, 7);            //备注
                string number = swTableAnn.get_Text(j, 8);              //测试
                if (bsp.number == "")
                {
                    bsp.number = number;
                }
                if (bsp is SldPrt)
                {
                    asmPrd.sldPrtList.Add((SldPrt)bsp);
                }
                else if (bsp is SldStd)
                {
                    asmPrd.sldStdList.Add((SldStd)bsp);
                }
                else if (bsp is SldBuy)
                {
                    asmPrd.sldBuyList.Add((SldBuy)bsp);
                }
            }
            return;
        }
Ejemplo n.º 3
0
        public void ProcessTableAnn(IEdmVault5 poVault, BomTableAnnotation swBOMTableAnn, string ConfigName, SldAsm asmPrd)
        {
            int             nNumRow    = 0;
            string          ItemNumber = null;
            string          PartNumber = null;
            TableAnnotation swTableAnn = (TableAnnotation)swBOMTableAnn;

            nNumRow       = swTableAnn.RowCount;
            swBOMTableAnn = (BomTableAnnotation)swTableAnn;
            for (int j = 0; j < swTableAnn.RowCount; j++)
            {
                //
                //for (int i = 0; i < swTableAnn.ColumnCount;i++ )
                //    Console.WriteLine(swTableAnn.get_Text(j, i));
                //获取类别和特有信息
                if (j == swTableAnn.RowCount - 1)//最后一行为标题栏,跳过
                {
                    continue;
                }
                string   filePath   = "";
                string   compName   = "";
                string   compConfig = "";
                int      compCount  = swBOMTableAnn.GetComponentsCount2(j, ConfigName, out ItemNumber, out PartNumber);
                object[] vPtArr     = swBOMTableAnn.GetComponents2(j, ConfigName);
                if (vPtArr != null)
                {
                    for (int prIndex = 0; prIndex <= vPtArr.GetUpperBound(0); prIndex++)
                    {
                        Component2 swComp = (Component2)vPtArr[prIndex];
                        if ((swComp != null))
                        {
                            //Debug.Print("           Component Name :" + swComp.Name2 + "      Configuration Name : " + swComp.ReferencedConfiguration);
                            //Debug.Print("           Component Path :" + swComp.GetPathName());
                            filePath   = swComp.GetPathName();
                            compName   = swComp.Name2;
                            compConfig = swComp.ReferencedConfiguration;
                            break;
                        }
                        else
                        {
                            continue;
                        }
                    }

                    //Component2 comp2 = null;
                    //comp2 = swBOMTableAnn.IGetComponents2(j, ConfigName, 0);
                    //if (comp2 != null)
                    //{
                    //    filePath = comp2.GetPathName();
                    //    compName = comp2.Name2;
                    //    compConfig = comp2.ReferencedConfiguration;
                    //}
                }

                SldBsp bsp = null;
                if (filePath == "")
                {
                    errors++;
                    errorStr += "明细表第" + (j + 1) + "行" + swTableAnn.get_Text(j, 1) + " 未找到关联文件\n";
                    bsp       = new SldBsp();
                    bsp.type  = 5;
                }
                else
                {
                    bsp = GetSldPrdInfoFromFile(poVault, filePath);
                    if (bsp == null)
                    {
                        errors++;
                        errorStr += "明细表第" + (j + 1) + "行" + swTableAnn.get_Text(j, 1) + " 文件:" + filePath + " 在PDM中未找到\n";
                        bsp       = new SldBsp();
                        bsp.type  = 5;
                    }
                }

                bsp.path = filePath;
                //SldBsp bsp = new SldBsp();
                swTableAnn.get_Text(j, 0);              //序号
                bsp.number = swTableAnn.get_Text(j, 1); //代号
                bsp.name   = swTableAnn.get_Text(j, 2); //名称
                string amout    = swTableAnn.get_Text(j, 3);
                int    parseInt = 0;
                try
                {
                    parseInt = int.Parse(amout);
                }catch (Exception) {
                    parseInt = 0;
                }
                bsp.amout    = parseInt;                  //数量
                bsp.material = swTableAnn.get_Text(j, 4); //材料
                string weight      = swTableAnn.get_Text(j, 5);
                double parseDouble = 0.0;
                try
                {
                    parseDouble = double.Parse(weight);
                }
                catch (Exception)
                {
                    parseDouble = 0.0;
                }
                bsp.weight      = parseDouble;               //单重
                bsp.totalWeight = bsp.weight * bsp.amout;    // swTableAnn.get_Text(j, 6);//总重
                bsp.remark      = swTableAnn.get_Text(j, 7); //备注
                //string number = swTableAnn.get_Text(j, 8);//测试
                //if (bsp.number == "") bsp.number = number;
                if (bsp is SldPrt)
                {
                    bsp.materialNumber = bsp.number == ""?"":("03." + bsp.number);
                    asmPrd.sldPrtList.Add((SldPrt)bsp);
                }
                else if (bsp is SldStd)
                {
                    asmPrd.sldStdList.Add((SldStd)bsp);
                }
                else if (bsp is SldBuy)
                {
                    asmPrd.sldBuyList.Add((SldBuy)bsp);
                }
                else if (bsp is SldBsp)
                {
                    asmPrd.sldBspList.Add(bsp);
                }
            }
            return;
        }