///<summary> method <c>GetDrawingDocBOMTable</c> ///从SolidWorks 的Drawing文档获取到其材料明细表,一般一个文档一个,多余不获取 ///</summary> public void GetDrawingDocBOMTable(ModelDoc2 modelDoc, out BomTableAnnotation swBOMTable, out string configName, out string topFileName) { Feature feature = modelDoc.IFirstFeature(); swBOMTable = null; configName = ""; topFileName = ""; BomFeature swBomFeat = null; while (feature != null) { Type type = feature.GetType(); if ("BomFeat" == feature.GetTypeName()) { //Console.WriteLine("******************************"); //Console.WriteLine("Feature Name : " + feature.Name); swBomFeat = (BomFeature)feature.GetSpecificFeature2(); break; } string name = feature.Name; feature = feature.IGetNextFeature(); } if (swBomFeat == null || swBomFeat.GetTableAnnotationCount() <= 0) { return; } Feature swFeat = (Feature)swBomFeat.GetFeature(); string featureName = swFeat.Name; swBOMTable = swBomFeat.IGetTableAnnotations(1);// default(TableAnnotation); topFileName = swBomFeat.GetReferencedModelName(); int configCount = swBomFeat.GetConfigurationCount(true); // //object[] vTableArr = (object[])swBomFeat.GetTableAnnotations(); //foreach (object vTable_loopVariable in vTableArr) //{ // object vTable = vTable_loopVariable; // TableAnnotation swTable = (TableAnnotation)vTable; // ProcessTableAnn(modelDoc, swTable); //} configName = ""; if (configCount > 0) { bool visibility = true; configName = swBomFeat.IGetConfigurations(true, 0, ref visibility); } //swBOMTable.Iget return; }
/// <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); } }