Ejemplo n.º 1
0
        private static void AddRelations(IpfcAsyncConnection AsyncConnection, string FileFullName, string[] rels)
        {
            IpfcModelDescriptor      descmodel;
            IpfcRetrieveModelOptions options;
            IpfcModel         model;
            Cstringseq        relations = new Cstringseq();
            IpfcRelationOwner relationOwner;
            Cstringseq        originrels;

            Console.WriteLine("打开" + FileFullName + "...");
            try
            {
                Console.WriteLine("开始添加" + FileFullName + "关系...");
                descmodel                = (new CCpfcModelDescriptor()).Create((int)EpfcModelType.EpfcMDL_PART, "", null);
                descmodel.Path           = FileFullName;
                options                  = (new CCpfcRetrieveModelOptions()).Create();
                options.AskUserAboutReps = false;
                model = ((IpfcBaseSession)(AsyncConnection.Session)).RetrieveModelWithOpts(descmodel, options);
                ((IpfcBaseSession)(AsyncConnection.Session)).CreateModelWindow(model);
            }
            catch
            {
                Console.WriteLine("无法打开" + FileFullName + "...");
                return;
            }


            relationOwner = (IpfcRelationOwner)model;
            originrels    = relationOwner.get_Relations();
            try
            {
                for (int i = 0; i <= originrels.Count - 1; i++)
                {
                    relations.Append(originrels[i]);
                }

                foreach (string line in rels)
                {
                    relations.Append(line);
                }
                relationOwner.set_Relations(relations);
                model.Save();
            }
            catch
            {
                Console.WriteLine("无法添加" + FileFullName + "关系...");
                return;
            }

            Console.WriteLine(FileFullName + "关系添加完毕...");

            try
            {
                ((IpfcBaseSession)(AsyncConnection.Session)).EraseUndisplayedModels();
                model.EraseWithDependencies();
            }
            catch
            {
            }
        }
Ejemplo n.º 2
0
        private static void GetTableData()
        {
            IpfcBaseSession CreoSession;

            CreoSession = (IpfcBaseSession)asyncConnection.Session;

            IpfcModel CreoModel;

            CreoModel = CreoSession.CurrentModel;

            if (CreoModel == null)
            {
                Console.WriteLine("Could not get active model!");
                return;
            }

            lastModelName = CreoModel.FullName;

            Console.WriteLine("Current File:     {0}", CreoModel.FileName);
            Console.WriteLine("Current Model:    {0}", lastModelName);

            try
            {
                FileInfo fi = new FileInfo(CreoModel.Origin);
                lastModelDirectory = fi.Directory.FullName;
            }
            catch (Exception ex)
            {
                //Console.WriteLine(ex.Message);
                //Console.WriteLine("\n\nCould not get file directory!");
                //return;
            }

            Console.WriteLine("Model Directory:  {0}", lastModelDirectory);

            pfcls.IpfcTableOwner TableObj = (pfcls.IpfcTableOwner)CreoModel;

            CpfcTables table_list = TableObj.ListTables();

            if (table_list.Count == 0)
            {
                Console.WriteLine("Could not find any tables!");
                return;
            }

            // [===========================================]
            Console.WriteLine("Gathering data...");


            bool   boolFoundTable = false;
            string strOutput      = "";

            for (int i = 0; i < table_list.Count; i++)
            {
                if (table_list[i].GetRowCount() > 1)
                {
                    // if the table was already found... exit outer loop
                    if (boolFoundTable)
                    {
                        break;
                    }

                    IpfcTable table = table_list[i];


                    int RowCount    = table.GetRowCount();
                    int ColumnCount = table.GetColumnCount();

                    for (int j = 1; j <= RowCount; j++)
                    {
                        //Has multiple rows.. check to see if Row 0 matches our test string
                        string rowData  = "";
                        bool   validRow = false;

                        for (int k = 1; k <= ColumnCount; k++)
                        {
                            CCpfcTableCell tableCellCreate = new CCpfcTableCell();
                            IpfcTableCell  tableCell       = tableCellCreate.Create(j, k);

                            string ItemValue = "";
                            try
                            {
                                Cstringseq stringSeq = table.GetText(tableCell, 0);

                                //Console.WriteLine("stringSeq.Count = {0}", stringSeq.Count);
                                for (int x = 0; x < stringSeq.Count; x++)
                                {
                                    ItemValue += stringSeq[x].ToString();
                                    //Console.WriteLine(stringSeq(x).ToString());
                                }
                            }
                            catch (Exception ex)
                            {
                                //Console.WriteLine(ex.Message);
                            }

                            //If this is the FIRST column of the FIRST row..
                            //see if the text matches our search string
                            //DON'T include it in the output though...
                            if (j == 1 && k == 1)
                            {
                                if (ItemValue.Contains("AUTO BOM"))
                                {
                                    boolFoundTable = true;
                                }
                                else
                                {
                                    break;
                                }
                            }
                            else
                            {
                                if (!validRow)
                                {
                                    if (!String.IsNullOrEmpty(ItemValue.Trim()))
                                    {
                                        validRow = true;
                                    }
                                }

                                if (validRow)
                                {
                                    //Console.Write(ItemValue + ",");
                                    rowData += "\"" + ItemValue + "\"";
                                    if (k < ColumnCount)
                                    {
                                        rowData += ",";
                                    }
                                }
                            }
                        }
                        if (validRow)
                        {
                            strOutput += rowData + "\r\n";
                            Console.WriteLine(rowData);
                        }


                        if (!boolFoundTable)
                        {
                            break;
                        }

                        //progress update?
                    }
                }
            }

            if (!boolFoundTable)
            {
                Console.WriteLine("Could not find AUTO BOM table!");
            }

            if (string.IsNullOrEmpty(strOutput))
            {
                Console.WriteLine("No data to save!");
                return;
            }


            //Save file
            string strFilename;

            if (!string.IsNullOrEmpty(outputDirectory) && System.IO.Directory.Exists(outputDirectory))
            {
                strFilename = outputDirectory + "\\" + lastModelName + ".csv";
            }
            else
            {
                strFilename = lastModelDirectory + "\\" + lastModelName + ".csv";
            }
            //= lastModelDirectory + "\\" + lastModelName + ".csv";

            try
            {
                File.WriteAllText(strFilename, strOutput);

                Console.WriteLine("Done!");
                Console.WriteLine("Saved to: {0}", strFilename);
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.Message);
                Console.WriteLine("\n\nCould not save CSV file.  Is it open?");
            }
        }