Esempio n. 1
0
        public BomItem[] GetBomItems()
        {
            // Dictionary to hold BomItem(s).  Key is the full path to the SolidEdgeDocument.
            Dictionary <string, BomItem> bomItems = new Dictionary <string, BomItem>();

            SolidEdgeFramework.Application     application      = null;
            SolidEdgeFramework.Documents       documents        = null;
            SolidEdgeAssembly.AssemblyDocument assemblyDocument = null;

            OleMessageFilter.Register();

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

                // Get a reference to the Documents collection.
                documents = application.Documents;

                // Make sure a document is open and that it's an AssemblyDocument.
                if ((documents.Count > 0) && (application.ActiveDocumentType == SolidEdgeFramework.DocumentTypeConstants.igAssemblyDocument))
                {
                    // Get a reference to the AssemblyDocument.
                    assemblyDocument = (SolidEdgeAssembly.AssemblyDocument)application.ActiveDocument;

                    // Start walking the assembly tree.
                    ProcessAssembly(0, assemblyDocument, bomItems);
                }
                else
                {
                    throw new System.Exception("No assembly open.");
                }
            }
            catch (System.Runtime.InteropServices.COMException ex)
            {
                if (ex.ErrorCode == -2147221021 /* MK_E_UNAVAILABLE */)
                {
                    throw new System.Exception("Solid Edge is not running.");
                }
                else
                {
                    throw;
                }
            }
            catch
            {
                throw;
            }
            finally
            {
            }

            return(bomItems.Values.ToArray());
        }
 private void MainForm_Load(object sender, EventArgs e)
 {
     // Register with OLE to handle concurrency issues on the current thread.
     OleMessageFilter.Register();
 }