Beispiel #1
0
        public static void InsertBOM(SldWorks swApp)
        {
            ModelDoc2         md = (ModelDoc2)swApp.ActiveDoc;
            DrawingDoc        dd = (DrawingDoc)swApp.ActiveDoc;
            ModelDocExtension ex = (ModelDocExtension)md.Extension;
            int bom_type         = (int)swBomType_e.swBomType_PartsOnly;
            int bom_numbering    = (int)swNumberingType_e.swNumberingType_Flat;
            int bom_anchor       = (int)swBOMConfigurationAnchorType_e.swBOMConfigurationAnchor_TopLeft;

            SolidWorks.Interop.sldworks.View v = GetFirstView(swApp);
            BomTableAnnotation bta             = null;
            TableAnnotation    ta = null;

            if (dd.ActivateView(v.Name))
            {
                bta = v.InsertBomTable4(
                    false,
                    Properties.Settings.Default.BOMLocationX, Properties.Settings.Default.BOMLocationY,
                    bom_anchor,
                    bom_type,
                    v.ReferencedConfiguration,
                    Properties.Settings.Default.BOMTemplatePath,
                    false,
                    bom_numbering,
                    false);
            }

            if (bta != null)
            {
                ta = (TableAnnotation)bta;
                if (ta != null)
                {
                    int        deptcol = 0;
                    List <int> rowdpt  = new List <int>();
                    System.Text.RegularExpressions.Regex r = new System.Text.RegularExpressions.Regex(BOMFilter[0]);

                    for (int i = 0; i < ta.ColumnCount; i++)
                    {
                        if (ta.Text[0, i].ToUpper() == @"DEPTID")
                        {
                            deptcol = i;
                            break;
                        }
                    }

                    for (int i = 0; i < ta.RowCount; i++)
                    {
                        if (!r.IsMatch(ta.Text[i, deptcol]))
                        {
                            rowdpt.Add(i);
                        }
                    }

                    foreach (int item in rowdpt)
                    {
                        ta.set_RowHidden(item, true);
                    }
                }
            }
        }
Beispiel #2
0
        public void InsertBom()
        {
            SldWorks       swApp     = default(SldWorks);
            ModelDoc2      swModel   = default(ModelDoc2);
            SelectionMgr   swSelMgr  = default(SelectionMgr);
            FeatureManager swFeatMgr = default(FeatureManager);

            SolidWorks.Interop.sldworks.View swView;
            BomTableAnnotation swBomAnn  = default(BomTableAnnotation);
            BomFeature         swBomFeat = default(BomFeature);
            long   anchorType            = 0;
            long   bomType       = 0;
            string configuration = null;
            string tableTemplate = null;

            object     visible = null;
            DrawingDoc swDraw;
            Sheet      swSheet = default(Sheet);

            //swApp = DirectCast(Marshal.GetActiveObject("SldWorks.Application"), SldWorks)
            swApp     = (SldWorks)Marshal.GetActiveObject("SldWorks.Application");
            swModel   = swApp.ActiveDoc;
            swFeatMgr = swModel.FeatureManager;
            swDraw    = (DrawingDoc)swModel;
            swSheet   = swDraw.GetCurrentSheet();

            swModel.Extension.SetUserPreferenceString((int)swUserPreferenceStringValue_e.swDetailingLayer, (int)swUserPreferenceOption_e.swDetailingBillOfMaterial, "");
            //ecли FALSE вставляются все конфигурации
            swModel.Extension.SetUserPreferenceToggle((int)swUserPreferenceToggle_e.swOneConfigOnlyTopLevelBom, 0, false);

            swModel.Extension.SetUserPreferenceToggle((int)swUserPreferenceToggle_e.swBomTableDontAddQTYNextToConfigName, 0, true);
            swModel.Extension.SetUserPreferenceToggle((int)swUserPreferenceToggle_e.swDontCopyQTYColumnNameFromTemplate, 0, true);
            //swDraw.SetUserPreferenceIntegerValue(swBomTableZeroQuantityDisplay, swZeroQuantityBlank);

            //Select View
            swModel.ClearSelection2(true);
            swView = swDraw.GetCurrentSheet().GetViews()[0];

            //Insert BOM Table
            anchorType = (int)swBOMConfigurationAnchorType_e.swBOMConfigurationAnchor_TopLeft;
            bomType    = (int)swBomType_e.swBomType_TopLevelOnly;

            swModel.ClearSelection2(true);

            configuration = "";

            tableTemplate = "C:\\Program Files\\SW-Complex\\Template.sldbomtbt";

            swBomAnn = swView.InsertBomTable2(false, -0, -0, (int)anchorType, (int)bomType, configuration, tableTemplate);

            swFeatMgr.UpdateFeatureTree();

            swBomFeat = swBomAnn.BomFeature;

            var Names = swBomFeat.GetConfigurations(false, visible);

            visible = true;
            swBomFeat.SetConfigurations(true, visible, Names);
        }
        ///<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;
        }
Beispiel #4
0
        private static void LerBOM(BomTableAnnotation swBomTable, ModelDoc2 swModel)
        {
            TableAnnotation tabela = (TableAnnotation)swBomTable;
            long            coluna = tabela.ColumnCount;
            long            linha  = tabela.RowCount;

            listaDeCodigos.Add(Path.GetFileNameWithoutExtension(swModel.GetPathName()) + ";");

            for (int i = 0; i < linha - 1; i++)
            {
                listaDeCodigos.Add((tabela.Text[i, 1] + ";" + tabela.Text[i, 5]));
            }
            listaDeCodigos.Add(";");
        }
Beispiel #5
0
    private void fill_table(BomFeature bom)
    {
        found_bom = bom;
        string itno = string.Empty;
        string ptno = string.Empty;

        _cols.Clear();
        _prts.Clear();
        swTable = (ITableAnnotation)bom.IGetTableAnnotations(1);
        part.ClearSelection2(true);

        _col_count = swTable.ColumnCount;
        find_part_column();
        _row_count = swTable.RowCount;
        for (int i = 0; i < _col_count; i++)
        {
            _cols.Add(swTable.get_DisplayedText(0, i));
        }
        object[]           bomtaa = (object[])bom.GetTableAnnotations();
        BomTableAnnotation bta    = (BomTableAnnotation)bomtaa[0];
        int prtcol = get_column_by_name(_part_column);

        for (int i = 0; i < _row_count; i++)
        {
            string prt_ = swTable.get_DisplayedText(i, prtcol);
            _prts.Add(prt_);
            string[] pathnames = (string[])bta.GetModelPathNames(i, out itno, out ptno);
            if (pathnames != null)
            {
                foreach (string pathname in pathnames)
                {
                    FileInfo fi_ = new FileInfo(pathname);
                    path_list.Add(fi_);
                    if (!path_dict.ContainsKey(prt_.ToUpper()))
                    {
                        path_dict.Add(prt_.ToUpper(), fi_);
                    }
                }
            }
        }
        initialated = true;
    }
Beispiel #6
0
        ///<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 = "";
            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;
            }
            swBOMTable  = swBomFeat.IGetTableAnnotations(1);// default(TableAnnotation);
            topFileName = swBomFeat.GetReferencedModelName();
            configName  = "";
            if (configCount > 0)
            {
                bool visibility = true;
                configName = swBomFeat.IGetConfigurations(true, 0, ref visibility);
            }
            //swBOMTable.Iget
            return;
        }
Beispiel #7
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;
        }
Beispiel #8
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);
            }
        }
Beispiel #9
0
        static void Main(string[] args)
        {
            SldWorks.SldWorks swApp;
            ModelDoc2         swModel;

            swApp = SW.Get_swApp();
            //swApp.SendMsgToUser("teste conectado!");

            IEnumerable <int> codigos = Enumerable.Range(4020001, 256);
            string            fullPath;

            try
            {
                foreach (var codigo in codigos)
                {
                    int erro = 0, aviso = 0;
                    fullPath = $@"C:\ELETROFRIO\ENGENHARIA SMR\PRODUTOS FINAIS ELETROFRIO\MECÂNICA\RACK PADRAO\RACK PADRAO TESTE\{codigo}.SLDDRW";
                    //swApp.DocumentVisible(false, (int)swDocumentTypes_e.swDocDRAWING);
                    swModel = swApp.OpenDoc6(fullPath, (int)swDocumentTypes_e.swDocDRAWING, (int)swOpenDocOptions_e.swOpenDocOptions_RapidDraft, "", erro, aviso);
                    if (swModel == null)
                    {
                        Console.WriteLine("Erro: " + erro);
                        Console.WriteLine("Aviso: " + aviso);
                        continue;
                    }

                    DrawingDoc swDraw = (DrawingDoc)swModel;
                    View       swActiveView;
                    View       swSheetView;

                    //A first view é a folha, e não a vista propriamente dita
                    swSheetView  = swDraw.GetFirstView();
                    swActiveView = swSheetView.GetNextView();
                    var nomeDaVista = swActiveView.GetName2();

                    //ModelDoc2 swModelDaVista;
                    //swModelDaVista = swActiveView.ReferencedDocument;
                    //var nomeDo3DdaVista = swModelDaVista.GetPathName();

                    //Object[] anotacoesDaVista = swActiveView.GetAnnotations();

                    //foreach (var a in anotacoesDaVista)
                    //{
                    //    Annotation annot = (Annotation)a;
                    //    Console.WriteLine(annot.GetName());
                    //}

                    BomFeature swBomFeature;
                    swBomFeature = GetBOM(swModel);
                    Feature swFeat;
                    swFeat = swBomFeature.GetFeature();
                    object[]           vTableArr = swBomFeature.GetTableAnnotations();
                    BomTableAnnotation tableAnn  = null;
                    foreach (BomTableAnnotation v in vTableArr)
                    {
                        tableAnn = (BomTableAnnotation)v;
                    }

                    if (tableAnn != null)
                    {
                        LerBOM(tableAnn, swModel);
                    }
                    else
                    {
                        Console.WriteLine("Não pegou a table annotation");
                    }
                    EscreveTXT(listaDeCodigos);
                    swApp.CloseAllDocuments(true);
                    Console.WriteLine(codigo);
                }
            }
            finally
            {
                EscreveTXT(listaDeCodigos);
            }
            Console.ReadLine();
        }
Beispiel #10
0
        /// <summary>
        /// 出工程图
        /// </summary>
        /// <param name="dicValues"></param>
        /// <param name="prtTemp"></param>
        /// <param name="compTemp"></param>
        /// <param name="bomPaths"></param>
        /// <param name="savePaths">保存路径</param>
        /// <param name="newPath">新路径</param>
        private void Drawing(List <string> dicValues, string prtTemp, string compTemp, string bomPaths, string savePaths, string newPath)
        {
            string          viewType   = string.Empty;
            bool            isometric  = false;
            bool            bom        = false;
            string          dimesion   = string.Empty;
            double          spaceX     = 0.06;                  //x方向留白区域
            double          scale      = 1;                     //定义比例初始值
            List <double[]> viewBox    = new List <double[]>(); //集合存放视图box
            List <double[]> viewOrigin = new List <double[]>(); //集合存放视图原点值

            double[] outLine = new double[4];                   //视图box值
            double[] postion = new double[2];                   //视图原点值
            _swApp = (SldWorks)ConnectSW.iSwApp;                //连接sw
            if (_swApp == null)
            {
                return;
            }
            foreach (string item in dicValues)
            {
                int    errors   = 0;
                int    warnings = 0;
                double view1X   = 0;
                double view1Y   = 0;
                string filePath = item;                                             //文件路径
                string fileEx   = filePath.Substring(filePath.LastIndexOf("."), 7); //获得后缀名
                string filename = filePath.Substring(filePath.LastIndexOf("\\") + 1, filePath.LastIndexOf(".") - filePath.LastIndexOf("\\") - 1);
                if (fileEx == ".SLDPRT")
                {
                    _swModelDoc = (ModelDoc2)_swApp.OpenDoc6(filePath, (int)swDocumentTypes_e.swDocPART, (int)swOpenDocOptions_e.swOpenDocOptions_Silent, "", ref errors, ref warnings);
                    __swDrawDoc = (DrawingDoc)_swApp.NewDrawing2((int)swDwgTemplates_e.swDwgTemplateCustom, prtTemp, (int)swDwgPaperSizes_e.swDwgPapersUserDefined, 0, 0);
                }
                if (fileEx == ".SLDASM")
                {
                    _swModelDoc = (ModelDoc2)_swApp.OpenDoc6(filePath, (int)swDocumentTypes_e.swDocASSEMBLY, (int)swOpenDocOptions_e.swOpenDocOptions_Silent, "", ref errors, ref warnings);
                    __swDrawDoc = (DrawingDoc)_swApp.NewDrawing2((int)swDwgTemplates_e.swDwgTemplateCustom, compTemp, (int)swDwgPaperSizes_e.swDwgPapersUserDefined, 0, 0);
                }
                _swModelEx = (ModelDocExtension)_swModelDoc.Extension;
                if (newPath != null)
                {
                    savePaths = newPath.Substring(0, newPath.LastIndexOf("\\"));
                }
                //新建工程图
                _swApp.SetUserPreferenceToggle((int)swUserPreferenceToggle_e.swAutomaticScaling3ViewDrawings, true); //自动缩放新工程图比例
                if (standarView == false && isometric)                                                               //如果只生成等轴测视图
                {
                    CreatIsometric(__swDrawDoc, filePath);
                    _currentSheet = (Sheet)__swDrawDoc.GetCurrentSheet();
                    __swDrawDoc.ActivateSheet(_currentSheet.GetName());
                    _swView = __swDrawDoc.GetFirstView();
                    _swView = _swView.GetNextView();
                    ChangeViewShow(tag, _swView);
                    _swApp.CloseDoc(_swModelDoc.GetTitle());//
                    ModelDoc2 tempDoc = (ModelDoc2)__swDrawDoc;
                    bool      ss0     = false;
                    if (newPath != null && IfDwg)
                    {
                        ss0 = tempDoc.Extension.SaveAs(newPath, (int)swSaveAsVersion_e.swSaveAsCurrentVersion, (int)swSaveAsOptions_e.swSaveAsOptions_Silent, null, ref errors, ref warnings);
                    }
                    else if (newPath != null && IfDwg == false)
                    {
                        ss0 = tempDoc.Extension.SaveAs(savePaths + "\\" + (_swModelDoc.GetTitle()).Substring(0, (_swModelDoc.GetTitle()).LastIndexOf(".")) + ".DWG", (int)swSaveAsVersion_e.swSaveAsCurrentVersion, (int)swSaveAsOptions_e.swSaveAsOptions_Silent, null, ref errors, ref warnings);
                    }
                    else if (newPath == null && IfDwg)
                    {
                        ss0 = tempDoc.Extension.SaveAs(savePaths + "\\" + (_swModelDoc.GetTitle()).Substring(0, (_swModelDoc.GetTitle()).LastIndexOf(".")) + ".DWG", (int)swSaveAsVersion_e.swSaveAsCurrentVersion, (int)swSaveAsOptions_e.swSaveAsOptions_Silent, null, ref errors, ref warnings);
                    }
                    else
                    {
                        ss0 = tempDoc.Extension.SaveAs(savePaths + "\\" + (_swModelDoc.GetTitle()).Substring(0, (_swModelDoc.GetTitle()).LastIndexOf(".")) + ".slddrw", (int)swSaveAsVersion_e.swSaveAsCurrentVersion, (int)swSaveAsOptions_e.swSaveAsOptions_Silent, null, ref errors, ref warnings);
                    }

                    bool isHidden = tempDoc.SetUserPreferenceToggle((int)swUserPreferenceToggle_e.swViewDisplayHideAllTypes, true); //隐藏所有类型
                    _swApp.CloseDoc(tempDoc.GetTitle());
                    _numSucess += 1;                                                                                                //转换成功的数量
                    sucessFile.Add(filePath);
                    return;
                }
                bool isCreate = false;
                #region 第三视角投影
                if (thirProject)
                {
                    isCreate = __swDrawDoc.Create3rdAngleViews2(filePath);//创建第三视角投影视图(视图位置有差别)
                    //调整视图位置
                    _swView = __swDrawDoc.GetFirstView();
                    while (_swView != null)
                    {
                        double[] vBox   = new double[] { };
                        double[] vPoint = new double[] { };
                        vBox   = (double[])_swView.GetOutline();
                        vPoint = (double[])_swView.Position;
                        viewBox.Add(vBox);
                        viewOrigin.Add(vPoint);
                        _swView = _swView.GetNextView();
                    }
                    //调整视图1、2位置
                    if (viewBox[0][3] > viewBox[0][2])//纵向
                    {
                        double[] posView1 = new double[] { viewBox[0][2] / 3.0, viewOrigin[1][1] };
                        _swView          = __swDrawDoc.GetFirstView();
                        _swView          = _swView.GetNextView();
                        _swView.Position = posView1;
                        double[] posView2 = new double[] { viewOrigin[2][0], viewOrigin[2][1] - (viewBox[2][1] - viewBox[1][3]) / 1.9 };//调整视图2位置
                        _swView          = _swView.GetNextView();
                        _swView.Position = posView2;
                    }
                    else
                    {
                        double[] posView1 = new double[] { viewBox[0][2] / 4.0, viewOrigin[1][1] };
                        _swView          = __swDrawDoc.GetFirstView();
                        _swView          = _swView.GetNextView();
                        _swView.Position = posView1;
                        double[] posView2 = new double[] { viewOrigin[2][0], viewOrigin[2][1] - (viewBox[2][1] - viewBox[1][3]) / 2.0 };//调整视图2位置
                        _swView          = _swView.GetNextView();
                        _swView.Position = posView2;
                    }
                    viewOrigin.Clear();
                    viewBox.Clear();
                    _swView = __swDrawDoc.GetFirstView();
                    while (_swView != null)
                    {
                        double[] vBox   = new double[] { };
                        double[] vPoint = new double[] { };
                        vBox   = (double[])_swView.GetOutline();
                        vPoint = (double[])_swView.Position;
                        viewBox.Add(vBox);
                        viewOrigin.Add(vPoint);
                        _swView = _swView.GetNextView();
                    }
                    if (isometric)//等轴测
                    {
                        _swView = (IView)__swDrawDoc.CreateDrawViewFromModelView3(filePath, "*等轴测", viewOrigin[3][0], viewOrigin[2][1], 0);
                        _swView = __swDrawDoc.GetFirstView();
                        double[] sca = new double[2];
                        sca                = _swView.ScaleRatio;//获取比例
                        _swView            = _swView.GetNextView();
                        _swView            = _swView.GetNextView();
                        _swView            = _swView.GetNextView();
                        _swView            = _swView.GetNextView();
                        _swView.ScaleRatio = sca;
                        double[] rePos = new double[] { viewOrigin[3][0] + 0.015, viewOrigin[2][1] };
                        _swView.Position = rePos;
                        ChangeViewShow(tag, _swView);                     //视图样式
                        AddDimension(dimesion, __swDrawDoc, _swModelDoc); //尺寸标注
                    }
                }
                #endregion
                #region 第一视角投影
                else
                {
                    isCreate = __swDrawDoc.Create1stAngleViews(filePath);//创建第一视角投影视图
                    //获取视图boundingbox
                    _swView = __swDrawDoc.GetFirstView();
                    while ((_swView != null))
                    {
                        outLine = (double[])_swView.GetOutline(); //(x,y坐标最值)
                        postion = (double[])_swView.Position;     //视图位置值
                        viewBox.Add(outLine);
                        viewOrigin.Add(postion);
                        _swView = _swView.GetNextView();
                    }

                    double newScale = CalcuScale(viewBox, __swDrawDoc, scale, spaceX, 3);
                    //调整视图位置(position)
                    if (viewBox[0][3] > viewBox[0][2])
                    {
                        view1X = viewBox[0][2] / 2.8;                  //视图1的X坐标放在图纸坐标的三分之一处
                        view1Y = viewBox[0][3] - viewBox[0][3] / 4.85; //视图1的Y坐标放在图纸坐标的五分之一处
                    }
                    else
                    {
                        view1X = viewBox[0][2] / 3.5;                 //视图1的X坐标放在图纸坐标的三分之一处
                        view1Y = viewBox[0][3] - viewBox[0][3] / 4.0; //视图1的Y坐标放在图纸坐标的四分之一处
                    }
                    double[] view1Pos = new double[] { view1X, view1Y };
                    _swView          = __swDrawDoc.GetFirstView(); //获取图纸
                    _swView          = _swView.GetNextView();      //获取第一个视图
                    _swView.Position = view1Pos;
                    bool isRebuild = _swModelDoc.EditRebuild3();
                    //viewBox.Clear();
                    List <double[]> tempBox = new List <double[]>();
                    viewOrigin.Clear();
                    while ((_swView != null))
                    {
                        ChangeViewShow(tag, _swView);                     //改变视图显示样式
                        AddDimension(dimesion, __swDrawDoc, _swModelDoc); //添加尺寸
                        outLine = (double[])_swView.GetOutline();         //(x,y坐标最值)
                        postion = (double[])_swView.Position;             //视图位置值
                        tempBox.Add(outLine);
                        viewOrigin.Add(postion);
                        _swView = _swView.GetNextView();
                    }
                    if (isometric)  //是否创建等轴测视图(非钣金)
                    {
                        double[] scalArry = new double[2];
                        _swView = (IView)__swDrawDoc.CreateDrawViewFromModelView3(filePath, "*等轴测", viewOrigin[2][0], viewOrigin[1][1], 0);
                        _swView = __swDrawDoc.GetFirstView(); //获取图纸
                        _swView = _swView.GetNextView();      //获取第一个视图
                        double sca = _swView.get_IScaleRatio();
                        if (sca == 1)                         //缩小比例
                        {
                            scalArry[0] = 1;
                            scalArry[1] = newScale;
                        }
                        else
                        {
                            scalArry[0] = sca;
                            scalArry[1] = 1;
                        }
                        _swView            = _swView.GetNextView();
                        _swView            = _swView.GetNextView();
                        _swView            = _swView.GetNextView();
                        _swView.ScaleRatio = scalArry;//调整轴测图比例
                        ChangeViewShow(tag, _swView);
                        _swModelDoc.EditRebuild3();
                    }
                    ////关掉文件(不保存)
                    //_swApp.CloseDoc(_swModelDoc.GetTitle());
                    if (fileEx == ".SLDASM" && bom)        //是否创建明细表
                    {
                        //viewBox.Clear();
                        //viewOrigin.Clear();
                        double[] outArry  = new double[4];
                        double[] posArry  = new double[2];
                        double[] posArry1 = null;
                        double[] posArry2 = null;
                        double[] posArry3 = null;
                        _currentSheet = (Sheet)__swDrawDoc.GetCurrentSheet();
                        __swDrawDoc.ActivateSheet(_currentSheet.GetName());
                        _swView        = __swDrawDoc.GetFirstView(); //获取图纸
                        _swView        = _swView.GetNextView();      //获取第一个视图
                        swBomTableAnno = (BomTableAnnotation)_swView.InsertBomTable4(true, 0.4, 0.1, (int)swBOMConfigurationAnchorType_e.swBOMConfigurationAnchor_BottomRight, (int)swBomType_e.swBomType_TopLevelOnly, "", bomPaths, false, 0, false);
                        TableAnnotation tableAnnotation = (TableAnnotation)swBomTableAnno;
                        tableAnnotation.GetAnnotation();
                        BomFeature bomFeature     = swBomTableAnno.BomFeature;
                        bool[]     array          = new bool[bomFeature.GetConfigurationCount(false)];
                        object     Visible        = array;
                        object     configurations = bomFeature.GetConfigurations(false, ref Visible);
                        array[0] = true;
                        bomFeature.SetConfigurations(true, array, configurations);
                        FeatureManager featureManager = _swModelDoc.FeatureManager;
                        featureManager.UpdateFeatureTree();
                        double num = 0.007;
                        tableAnnotation.SetRowHeight(-2, num, 0);
                        double totleHeight = num * tableAnnotation.RowCount; //计算总的tableBom高度
                        double heightSum   = totleHeight + 0.070;            //加上标题栏总高度
                        int    columCount  = tableAnnotation.ColumnCount;    //获取总的列数
                        double columWidth  = 0;
                        for (int i = 0; i < columCount; i++)
                        {
                            double wid = tableAnnotation.GetColumnWidth(i);
                            columWidth += wid;
                        }
                        _swView = _swView.GetNextView();
                        _swView = _swView.GetNextView();
                        outArry = (double[])_swView.GetOutline();
                        if (outArry[1] < heightSum)//有可能被遮挡
                        {
                            //__swView = _swDrawDoc.GetFirstView();
                            //double[] tempArry = new double[] { };
                            //tempArry=(double[])__swView.GetOutline();
                            //viewBox.Insert(0, tempArry);
                            scale = ((viewBox[1][2] - viewBox[1][0]) + (viewBox[3][2] - viewBox[3][0])) / (viewBox[0][2] - columWidth - 0.025);//计算X方向的比例
                            if (scale > 11)
                            {
                                double scaleCeil = System.Math.Ceiling(scale);
                                if (scaleCeil > 11 && scaleCeil < 16)
                                {
                                    scale = 20;
                                }
                                if (scaleCeil > 15 && scaleCeil < 21)
                                {
                                    scale = 25;
                                }
                                if (scaleCeil > 20 && scaleCeil < 26)
                                {
                                    scale = 30;
                                }
                                if (scaleCeil > 25 && scaleCeil < 34)
                                {
                                    scale = 40;
                                }
                                if (scaleCeil > 33 && scaleCeil < 45)
                                {
                                    scale = 50;
                                }
                                if (scaleCeil > 44 && scaleCeil < 55)
                                {
                                    scale = 60;
                                }
                            }
                            else if (scale > 5.8 && scale < 10.5)
                            {
                                double scaleCeil = System.Math.Ceiling(scale);
                                //scale = scaleCeil + 4.0;          //比例为10、11、12、13、14、15
                                if (scaleCeil > 5 && scaleCeil < 8)
                                {
                                    scale = 10;
                                }
                                if (scaleCeil > 7 && scaleCeil < 12)
                                {
                                    scale = 15;
                                }
                            }
                            _currentSheet = (Sheet)__swDrawDoc.GetCurrentSheet();
                            __swDrawDoc.ActivateSheet(_currentSheet.GetName());
                            bool isScale = _currentSheet.SetScale(1, scale, false, false); //设置视图和图纸比例
                            _swView = __swDrawDoc.GetFirstView();
                            _swView = _swView.GetNextView();                               //获取视图1
                            double[] pos1 = new double[2];
                            pos1             = _swView.Position;
                            posArry1         = new double[] { pos1[0] - columWidth / 3.45, pos1[1] };
                            _swView.Position = posArry1;              //重置视图1的位置
                            _swView          = _swView.GetNextView(); //获取视图2
                            double[] pos2 = new double[2];
                            pos2             = _swView.Position;
                            posArry2         = new double[] { pos2[0] - columWidth / 3.45, pos2[1] + 0.0015 };
                            _swView.Position = posArry2;              //设置视图2位置
                            _swView          = _swView.GetNextView(); //获取视图三
                            posArry          = (double[])_swView.Position;
                            posArry3         = new double[] { posArry[0] - columWidth / 3.5, posArry[1] };
                            _swView.Position = posArry3;//视图3坐标
                        }
                    }
                }//第一视角投影
                #endregion
                if (isCreate)
                {
                    _numSucess += 1;//转换成功的数量
                    sucessFile.Add(filePath);
                }
                ModelDoc2 tempModelDoc = (ModelDoc2)__swDrawDoc;                                                                    //获取到swDraw的父级(ModelDoc)
                _swApp.CloseDoc(_swModelDoc.GetTitle());
                bool isHiden = tempModelDoc.SetUserPreferenceToggle((int)swUserPreferenceToggle_e.swViewDisplayHideAllTypes, true); //隐藏所有类型

                _swModelDoc.ForceRebuild3(false);
                string saveName = (_swModelDoc.GetTitle()).Substring(0, (_swModelDoc.GetTitle()).LastIndexOf("."));
                bool   ss;
                if (newPath != null && IfDwg)
                {
                    ss = tempModelDoc.Extension.SaveAs(savePaths + "\\" + (_swModelDoc.GetTitle()) + ".DWG", (int)swSaveAsVersion_e.swSaveAsCurrentVersion, (int)swSaveAsOptions_e.swSaveAsOptions_Silent, null, ref errors, ref warnings);
                }
                else if (newPath != null && IfDwg == false)
                {
                    ss = tempModelDoc.Extension.SaveAs(savePaths + "\\" + (_swModelDoc.GetTitle()) + ".slddrw", (int)swSaveAsVersion_e.swSaveAsCurrentVersion, (int)swSaveAsOptions_e.swSaveAsOptions_Silent, null, ref errors, ref warnings);
                }
                else if (newPath == null && IfDwg)
                {
                    ss = tempModelDoc.Extension.SaveAs(savePaths + "\\" + (_swModelDoc.GetTitle()) + ".DWG", (int)swSaveAsVersion_e.swSaveAsCurrentVersion, (int)swSaveAsOptions_e.swSaveAsOptions_Silent, null, ref errors, ref warnings);
                }
                else
                {
                    ss = tempModelDoc.Extension.SaveAs(savePaths + "\\" + (_swModelDoc.GetTitle()) + ".slddrw", (int)swSaveAsVersion_e.swSaveAsCurrentVersion, (int)swSaveAsOptions_e.swSaveAsOptions_Silent, null, ref errors, ref warnings);
                }
                _swApp.CloseDoc(tempModelDoc.GetTitle());//关闭转换完成的文件
            }
        }
Beispiel #11
0
 public BomItemExtractor(BomTableAnnotation bom)
 {
     this.bom      = bom;
     columnIndices = new BomColumnIndices();
 }
        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;
        }
Beispiel #13
0
        public bool exportExcel(IEdmVault5 poVault, string selectFile, string saveFile)
        {
            WiseUtil    wiseUtil            = new WiseUtil();
            IEdmFolder5 templateExcelFolder = null;
            string      finalFilePath       = poVault.RootFolderPath + WiseUtil.templateExcelFilePath;
            IEdmFile5   templateExcelFile   = poVault.GetFileFromPath(finalFilePath, out templateExcelFolder);

            if (templateExcelFile == null)
            {
                System.Windows.Forms.MessageBox.Show("在PDM中找不到模板EXCEL:\n" + finalFilePath);
                return(false);
            }

            //string installLocation = wiseUtil.GetLocalMachineRegistryValue("SOFTWARE\\solidworks\\Applications\\PDMWorks Enterprise\\", "Location");
            //System.Console.WriteLine(installLocation);
            //if (installLocation == "")
            //{
            //   installLocation = "C:\\";
            //}
            //string excelTemplate = installLocation + "ExportTemplate\\template-list.xlsx";
            Workbook templateWb = null;

            try {
                templateWb = wiseUtil.OpenExcel(finalFilePath);
            }
            catch (Exception e) {
                System.Windows.Forms.MessageBox.Show("打开模板表格失败,请查看位置" + templateExcelFile + "的文件状态");
                return(false);
            }
            if (templateWb == null)
            {
                System.Windows.Forms.MessageBox.Show("打开模板表格失败");
                return(false);
            }
            SldWorks.SldWorks swApp = new SldWorks.SldWorks();
            int       longstatus    = 0;
            int       longwarnings  = 0;
            ModelDoc2 modelDoc      = swApp.OpenDoc6(selectFile, (int)swDocumentTypes_e.swDocDRAWING,
                                                     (int)(swOpenDocOptions_e.swOpenDocOptions_ReadOnly | swOpenDocOptions_e.swOpenDocOptions_Silent),
                                                     "", ref longstatus, ref longwarnings);

            if (modelDoc == null || longstatus > 0)
            {
                System.Windows.Forms.MessageBox.Show("打开二维图失败");
                swApp.ExitApp();
                templateWb.Close();
                return(false);
            }
            BomTableAnnotation bomTableAnno = null;
            string             configName   = "";
            string             topFileName  = "";

            try
            {
                wiseUtil.GetDrawingDocBOMTable(modelDoc, out bomTableAnno, out configName, out topFileName);
            }
            catch (Exception e)
            {
                System.Windows.Forms.MessageBox.Show("获取明细表信息出错" + e.StackTrace);
            }
            if (bomTableAnno == null)
            {
                System.Windows.Forms.MessageBox.Show("未找到明细表信息");
                swApp.ExitApp();
                templateWb.Close();
                return(false);
            }
            //modelDoc.Close();
            SldAsm asmPrd = wiseUtil.GetAsmIndoFromFile(poVault, topFileName);// new SldAsm();

            if (asmPrd == null)
            {
                System.Windows.Forms.MessageBox.Show("获取材料明细表关联产品失败");
                swApp.ExitApp();
                templateWb.Close();
                return(false);
            }
            //asmPrd.bzr = "hou";
            //asmPrd.bzsj = "2016/1/1";
            try
            {
                wiseUtil.ProcessTableAnn(poVault, bomTableAnno, configName, asmPrd);
            }
            catch (Exception e)
            {
                System.Windows.Forms.MessageBox.Show("解析明细表信息出错" + e.StackTrace);
            }
            //if (WiseUtil.errors > 0)
            //{
            //    System.Windows.Forms.MessageBox.Show("解析明细表信息出错" + WiseUtil.errorStr);
            //}
            wiseUtil.SaveBuyToWorkbook(templateWb, asmPrd);
            wiseUtil.SaveStdToWorkbook(templateWb, asmPrd);
            wiseUtil.SavePrtToWorkbook(templateWb, asmPrd);
            wiseUtil.SaveBspToWorkbook(templateWb, asmPrd);
            templateWb.SaveAs(saveFile);
            templateWb.Close();
            swApp.ExitApp();
            swApp = null;
            return(true);
        }