Beispiel #1
0
        static void Main(string[] args)
        {
            SolidEdgeFramework.Application application = null;

            try
            {
                OleMessageFilter.Register();
                application = SolidEdgeUtils.Connect();
                var assemblyDocument = application.GetActiveDocument <SolidEdgeAssembly.AssemblyDocument>(false);

                // Optional settings you may tweak for performance improvements. Results may vary.
                application.DelayCompute   = true;
                application.DisplayAlerts  = false;
                application.Interactive    = false;
                application.ScreenUpdating = false;

                if (assemblyDocument != null)
                {
                    var rootItem = new DocumentItem();
                    rootItem.FileName = assemblyDocument.FullName;

                    // Begin the recurisve extraction process.
                    PopulateDocumentItems(assemblyDocument.Occurrences, rootItem);

                    // Write each DocumentItem to console.
                    foreach (var documentItem in rootItem.AllDocumentItems)
                    {
                        Console.WriteLine(documentItem.FileName);
                    }

                    // Demonstration of how to save the BOM to various formats.

                    // Convert the document items to JSON.
                    string json = Newtonsoft.Json.JsonConvert.SerializeObject(rootItem, Newtonsoft.Json.Formatting.Indented);
                }
            }
            catch (System.Exception ex)
            {
                Console.WriteLine(ex.Message);
            }
            finally
            {
                if (application != null)
                {
                    application.DelayCompute   = false;
                    application.DisplayAlerts  = true;
                    application.Interactive    = true;
                    application.ScreenUpdating = true;
                }

                OleMessageFilter.Unregister();
            }
        }
Beispiel #2
0
 /// <summary>
 /// Loads the Solid Edge Instance
 /// </summary>
 /// <param name="OpenNewAppInstance"></param>
 internal void LoadSolidEdgeApplication(bool OpenNewAppInstance)
 {
     try
     {
         CustomEvents.OnProgressChanged("Launching Solid Edge");
         OleMessageFilter.Register();
         _application = SolidEdgeUtils.Connect(OpenNewAppInstance, true);
     }
     catch
     {
     }
 }
        private void frmCacheManager_Load(object sender, EventArgs e)
        {
            this.comboBox1.KeyPress += new System.Windows.Forms.KeyPressEventHandler(CheckKeyPress);
            this.KeyPress           += new System.Windows.Forms.KeyPressEventHandler(CheckKeyPress);

            try
            {
                OleMessageFilter.Register();
                app = SolidEdgeUtils.Connect(false, true);
            }
            catch (System.Exception ex)
            {
                Console.WriteLine(ex.Message);
                throw;
            }

            bool tcMode = false;

            if (app != null)
            {
                app.SolidEdgeTCE.GetTeamCenterMode(out tcMode);

                if (tcMode == false)
                {
                    return;
                }

                string keyname = app.RegistryPath + @"\General";
                key = RegistryKey.OpenBaseKey(Microsoft.Win32.RegistryHive.CurrentUser, RegistryView.Registry64);
                key = key.OpenSubKey(keyname, true);
                string seecPath  = key.GetValue(@"SEEC cache").ToString();
                string currentWS = key.GetValue(@"SEEC_Active_Project").ToString();
                prefixWorkspaces = currentWS.Substring(0, currentWS.Length - (currentWS.Split('\\').Last().Length + 1)) + @"\";

                workspaceFolder = Directory.GetParent(seecPath + @"\" + currentWS).FullName;

                string[] workspaces = Directory.GetDirectories(workspaceFolder)
                                      .OrderByDescending(Directory.GetLastWriteTime)
                                      .Select(Path.GetFileName)
                                      .ToArray();

                comboBox1.Items.AddRange(workspaces);
                comboBox1.Text = currentWS.Split('\\').Last();
            }
        }
Beispiel #4
0
        private void MainForm_Load(object sender, EventArgs e)
        {
            try
            {
                // Register with OLE to handle concurrency issues on the current thread.
                OleMessageFilter.Register();

                PreloadTypeLibraries();

                ComTypeManager.Instance.ComTypeLibrarySelected += Instance_ComTypeLibrarySelected;
                ComTypeManager.Instance.ComTypeInfoSelected    += Instance_ComTypeInfoSelected;
            }
            catch
            {
                GlobalExceptionHandler.HandleException();
            }

            SetupToolStripManager();
        }
Beispiel #5
0
 private void MainForm_Load(object sender, EventArgs e)
 {
     OleMessageFilter.Register();
 }
Beispiel #6
0
        static void Main()
        {
            SolidEdgeFramework.Application application = null;


            try
            {
                OleMessageFilter.Register();

                // Connect to a running instance of Solid Edge.
                application = SolidEdgeUtils.Connect();

                // Connect to the active assembly document.
                var assemblyDocument = application.GetActiveDocument <SolidEdgeAssembly.AssemblyDocument>(false);

                // Optional settings you may tweak for performance improvements. Results may vary.
                application.DelayCompute   = true;
                application.DisplayAlerts  = false;
                application.Interactive    = false;
                application.ScreenUpdating = false;

                Microsoft.Office.Interop.Excel.Application xlApp = new Microsoft.Office.Interop.Excel.Application();

                if (xlApp == null)
                {
                    Console.WriteLine("EXCEL could not be started. Check that your office installation and project references are correct.");
                    return;
                }
                xlApp.Visible = true;

                // Open workbook
                Workbook wb = xlApp.Workbooks.Open("Y:\\Common\\Engineering\\001_Vraagbaak\\gijs\\BOM.xlsx");

                // Open worksheet
                Worksheet ws = (Worksheet)wb.Worksheets[2];

                if (ws == null)
                {
                    Console.WriteLine("Worksheet could not be created. Check that your office installation and project references are correct.");
                }

                int      i          = 2;
                string   sRow       = "";
                object[] oBomValues = new Object[1];

                sRow = i.ToString();

                oBomValues[0] = "Keywords";
                Range aRange = ws.get_Range("C" + sRow);
                aRange.GetType().InvokeMember("Value", BindingFlags.SetProperty, null, aRange, oBomValues);

                oBomValues[0] = "Document Number";
                aRange        = ws.get_Range("D" + sRow);
                aRange.GetType().InvokeMember("Value", BindingFlags.SetProperty, null, aRange, oBomValues);

                oBomValues[0] = "Title";
                aRange        = ws.get_Range("E" + sRow);
                aRange.GetType().InvokeMember("Value", BindingFlags.SetProperty, null, aRange, oBomValues);

                oBomValues[0] = "Quantity";
                aRange        = ws.get_Range("F" + sRow);
                aRange.GetType().InvokeMember("Value", BindingFlags.SetProperty, null, aRange, oBomValues);

                i++;

                if (assemblyDocument != null)
                {
                    var rootBomItem = new BomItem();
                    rootBomItem.FileName = assemblyDocument.FullName;

                    // Write Name of rootBomItem to excel
                    oBomValues[0] = assemblyDocument.DisplayName;
                    aRange        = ws.get_Range("A1");
                    aRange.GetType().InvokeMember("Value", BindingFlags.SetProperty, null, aRange, oBomValues);

                    // Begin the recurisve extraction process.
                    PopulateBom(0, assemblyDocument, rootBomItem);

                    // Write each BomItem to console.
                    foreach (var bomItem in rootBomItem.AllChildren)
                    {
                        Console.WriteLine("{0}\t{1}\t{2}\t{3}\t{4}", bomItem.Level, bomItem.DocumentNumber, bomItem.Revision, bomItem.Title, bomItem.Quantity);
                        sRow = i.ToString();

                        oBomValues[0] = bomItem.Level;
                        aRange        = ws.get_Range("C" + sRow);
                        aRange.GetType().InvokeMember("Value", BindingFlags.SetProperty, null, aRange, oBomValues);

                        oBomValues[0] = bomItem.DocumentNumber;
                        aRange        = ws.get_Range("D" + sRow);
                        aRange.GetType().InvokeMember("Value", BindingFlags.SetProperty, null, aRange, oBomValues);

                        oBomValues[0] = bomItem.Title;
                        aRange        = ws.get_Range("E" + sRow);
                        aRange.GetType().InvokeMember("Value", BindingFlags.SetProperty, null, aRange, oBomValues);

                        oBomValues[0] = bomItem.Quantity;
                        aRange        = ws.get_Range("F" + sRow);
                        aRange.GetType().InvokeMember("Value", BindingFlags.SetProperty, null, aRange, oBomValues);

                        i++;
                    }

                    // Demonstration of how to save the BOM to various formats.

                    // Define the Json serializer settings.
                    var jsonSettings = new JsonSerializerSettings
                    {
                        NullValueHandling = NullValueHandling.Ignore
                    };

                    // Convert the BOM to JSON.
                    string json = Newtonsoft.Json.JsonConvert.SerializeObject(rootBomItem, Newtonsoft.Json.Formatting.Indented, jsonSettings);

                    wb.RefreshAll();
                    wb.SaveAs(assemblyDocument.Path + "\\_BOM.xlsx");
                }
            }
            catch (System.Exception ex)
            {
                Console.WriteLine(ex.Message);
            }
            finally
            {
                if (application != null)
                {
                    application.DelayCompute   = false;
                    application.DisplayAlerts  = true;
                    application.Interactive    = true;
                    application.ScreenUpdating = true;
                }

                OleMessageFilter.Unregister();
            }
        }
Beispiel #7
0
        static void Main(string[] args)
        {
            string            folder         = ConfigurationManager.AppSettings.Get("saveFolder");
            Application       application    = null;
            SolidEdgeDocument activeDocument = null;

            try
            {
                // See "Handling 'Application is Busy' and 'Call was Rejected By Callee' errors" topic.
                OleMessageFilter.Register();

                // Attempt to connect to a running instance of Solid Edge.
                application = (Application)Marshal.GetActiveObject("SolidEdge.Application");
                //get active document
                activeDocument = (SolidEdgeDocument)application.ActiveDocument;

                //execute different behaviour for different documet type
                switch (GetDocumentType(application.ActiveDocument)) //grab document type form active document
                {
                case DocumentTypeConstants.igDraftDocument:
                    Console.WriteLine("Grabbed draft document");
                    SaveAsExtension(activeDocument, folder, "dxf");                        //save the active document on the specified folder as dxf
                    SaveAsExtension(activeDocument, folder, "pdf");                        //save the active document on the specified folder as pdf
                    DraftDocument activeDraft = (DraftDocument)application.ActiveDocument; //cast the active document as a draftDocument to access the model link

                    foreach (ModelLink modelLink in activeDraft.ModelLinks)                //loop for all model links found in the model link
                    {
                        if (GetDocumentType((SolidEdgeDocument)modelLink.ModelDocument) == DocumentTypeConstants.igPartDocument)
                        {
                            SaveAsExtension((SolidEdgeDocument)modelLink.ModelDocument, folder, "stp");     // cast the individual modelLlink.ModelDocument as a model document and save it
                            break;
                        }

                        if (GetDocumentType((SolidEdgeDocument)modelLink.ModelDocument) == DocumentTypeConstants.igAssemblyDocument)
                        {
                            SolidEdgeDocument asmDocument = (SolidEdgeDocument)modelLink.ModelDocument; // cast the individual modelLlink.ModelDocument as a model document

                            if (asmDocument.Name.Contains("MPF"))                                       // quick string check if contains the letters MPF
                            {
                                Console.WriteLine("Found MPF named document: " + asmDocument.Name);
                                SaveAsExtension((SolidEdgeDocument)modelLink.ModelDocument, folder, "stp");     //save the model link document on the specified folder as stp
                                break;
                            }
                            else
                            {
                                Console.WriteLine("Found an non MPF asembly document: " + asmDocument.Name);     // found nothing here
                            }
                        }
                    }
                    break;

                case DocumentTypeConstants.igPartDocument:
                    Console.WriteLine("Grabbed part document");
                    SaveAsExtension(activeDocument, folder, "stp");     // save the part document in the specified folder as stp
                    break;

                default:
                    Console.WriteLine("No valid document");     // found nothing here
                    break;
                }
                Console.WriteLine("Todo ha salido a pedir de Milhouse");
                Console.ReadKey();
            }
            catch (Exception e)
            {
                Console.WriteLine(e.Message);
                throw;
            }
            finally
            {
                OleMessageFilter.Unregister(); // unlink application after completion
            }
        }
Beispiel #8
0
        static void Main(string[] args)
        {
            SolidEdgeFramework.Application application = null;

            try
            {
                OleMessageFilter.Register();

                // Connect to a running instance of Solid Edge.
                application = SolidEdgeUtils.Connect();

                // Connect to the active assembly document.
                var assemblyDocument = application.GetActiveDocument <SolidEdgeAssembly.AssemblyDocument>(false);

                // Optional settings you may tweak for performance improvements. Results may vary.
                application.DelayCompute   = true;
                application.DisplayAlerts  = false;
                application.Interactive    = false;
                application.ScreenUpdating = false;

                if (assemblyDocument != null)
                {
                    var rootBomItem = new BomItem();
                    rootBomItem.FileName = assemblyDocument.FullName;

                    // Begin the recurisve extraction process.
                    PopulateBom(0, assemblyDocument, rootBomItem);

                    // Write each BomItem to console.
                    foreach (var bomItem in rootBomItem.AllChildren)
                    {
                        Console.WriteLine("{0}\t{1}\t{2}\t{3}\t{4}", bomItem.Level, bomItem.DocumentNumber, bomItem.Revision, bomItem.Title, bomItem.Quantity);
                    }

                    // Demonstration of how to save the BOM to various formats.

                    // Define the Json serializer settings.
                    var jsonSettings = new JsonSerializerSettings
                    {
                        NullValueHandling = NullValueHandling.Ignore
                    };

                    // Convert the BOM to JSON.
                    string json = Newtonsoft.Json.JsonConvert.SerializeObject(rootBomItem, Newtonsoft.Json.Formatting.Indented, jsonSettings);
                }
            }
            catch (System.Exception ex)
            {
                Console.WriteLine(ex.Message);
            }
            finally
            {
                if (application != null)
                {
                    application.DelayCompute   = false;
                    application.DisplayAlerts  = true;
                    application.Interactive    = true;
                    application.ScreenUpdating = true;
                }

                OleMessageFilter.Unregister();
            }
        }