Beispiel #1
0
        /// <summary>
        /// Called when SolidWorks has loaded our add-in and wants us to do our connection logic
        /// </summary>
        /// <param name="ThisSW">The current SolidWorks instance</param>
        /// <param name="Cookie">The current SolidWorks cookie Id</param>
        /// <returns></returns>
        public bool ConnectToSW(object ThisSW, int Cookie)
        {
            // Setup IoC
            IoCContainer.Ensure();

            // Store a reference to the current SolidWorks instance
            // Initialize SolidWorks (SolidDNA class)
            SolidWorks = new SolidWorksApplication((SldWorks)ThisSW, Cookie);

            // Setup plug-in app domain
            PlugInIntegration.Setup(SolidWorks);

            // Any pre-load steps
            PreLoadPlugIns();

            // Perform any plug-in configuration
            PlugInIntegration.ConfigurePlugIns();

            // Call the application startup function for an entry point to the application
            ApplicationStartup();

            // Inform listeners
            ConnectedToSolidWorks();

            // And plug-in domain listeners
            PlugInIntegration.ConnectedToSolidWorks();

            // Return ok
            return(true);
        }
Beispiel #2
0
        /// <summary>
        /// Attempts to set the SolidWorks property to the active SolidWorks instance
        /// </summary>
        /// <returns></returns>
        public bool ConnectToActiveSolidWork()
        {
            try
            {
                // Clean up old one
                TearDown();

                // Try and get the active SolidWorks instance
                SolidWorks = new SolidWorksApplication((SldWorks)Marshal.GetActiveObject("SldWorks.Application"), 0);

                // Log it
                Logger.LogDebugSource($"Aquired active instance SolidWorks in Stand-Alone mode");

                // Return if successful
                return(SolidWorks != null);
            }
            // If we failed to get active instance...
            catch (COMException)
            {
                // Log it
                Logger.LogDebugSource($"Failed to get active instance of SolidWorks in Stand-Alone mode");

                // Return failure
                return(false);
            }
        }
Beispiel #3
0
        /// <summary>
        /// Must be called to setup the PlugInIntegration application domain
        /// </summary>
        public static void Setup(SolidWorksApplication solidWorks)
        {
            // Make sure we resolve assemblies in this domain, as it seems to use this domain to resolve
            // assemblies not the appDomain when crossing boundaries
            AppDomain.CurrentDomain.AssemblyResolve += PlugInIntegrationMarshal.AppDomain_AssemblyResolve;

            PlugInAppDomain = AppDomain.CreateDomain("SolidDnaPlugInDomain", null, new AppDomainSetup
            {
                // Use plug-in folder for resolving plug-ins
                ApplicationBase = PlugInFolder,
            });

            // Make sure we load our own marshal
            AssembliesToResolve.Add(typeof(PlugInIntegrationMarshal).Assembly.FullName);

            // Run code on new app-domain to configure
            mCrossDomain = (PlugInIntegrationMarshal)PlugInAppDomain.CreateInstanceAndUnwrap(typeof(PlugInIntegrationMarshal).Assembly.FullName, typeof(PlugInIntegrationMarshal).FullName);
            mCrossDomain.SetupAppDomain(AddInIntegration.SolidWorks.SolidWorksVersion.RevisionNumber, solidWorks.SolidWorksCookie);
        }