예제 #1
0
        private bool ConnectToSolidEdge()
        {
            ComPtr pApplication = IntPtr.Zero;

            try
            {
                if (MarshalEx.Succeeded(MarshalEx.GetActiveObject("SolidEdge.Application", out pApplication)))
                {
                    _application = pApplication.TryGetUniqueRCW <SolidEdgeFramework.Application>();
                    _connectionPointController.AdviseSink <SolidEdgeFramework.ISEApplicationEvents>(_application);

                    commandBrowser.ActiveEnvironment = _application.GetActiveEnvironment();
                    globalParameterBrowser.RefreshGlobalParameters();

                    objectBrowser.Connect();

                    // Older versions of Solid Edge don't have the ProcessID property.
                    try
                    {
                        processBrowser.ProcessId = _application.ProcessID;
                    }
                    catch
                    {
                    }

                    return(true);
                }
            }
            catch
            {
                GlobalExceptionHandler.HandleException();
            }
            finally
            {
                pApplication.Dispose();
            }

            return(false);
        }