예제 #1
0
        private void SolidWorksMacro_Startup(object sender, EventArgs e)
        {
            this.swApp = (SldWorks)this.SolidWorksApplication;
            SolidWorks.RunMacroResult runResult = RunMacro();

            if (runResult == SolidWorks.RunMacroResult.NoneSpecified)
            {
                try
                {
                    SwMacroSetup();
                }
                catch (Exception ex) { System.Diagnostics.Debug.WriteLine(ex.ToString()); }
                Main();
                try
                {
                    SwMacroCleanup();
                }
                catch (Exception ex) { System.Diagnostics.Debug.WriteLine(ex.ToString()); }
            }
        }
예제 #2
0
        private void SolidWorksMacro_Startup(object sender, EventArgs e)
        {
            bool proxyFailed = false;

            try
            {
                this.swApp = (SldWorks)this.SolidWorksApplication;
            }
            catch (Exception ex)
            {
                proxyFailed = true;
            }

            if (!proxyFailed)
            {
                SolidWorks.RunMacroResult runResult = RunMacro();

                if (runResult == SolidWorks.RunMacroResult.NoneSpecified)
                {
                    try
                    {
                        SwMacroSetup();
                    }
                    catch (Exception ex) { System.Diagnostics.Debug.WriteLine(ex.ToString()); }
                    Main();
                    try
                    {
                        SwMacroCleanup();
                    }
                    catch (Exception ex) { System.Diagnostics.Debug.WriteLine(ex.ToString()); }
                }

                return;
            }



            try
            {
                Process sldProc = GetParentProcess(Process.GetCurrentProcess());

                while (sldProc != null)
                {
                    if (String.Compare(sldProc.ProcessName, "sldworks", true) == 0)
                    {
                        break;
                    }
                    else
                    {
                        sldProc = GetParentProcess(sldProc);
                    }
                }

                System.Runtime.InteropServices.ComTypes.IRunningObjectTable rot;
                System.Runtime.InteropServices.ComTypes.IMoniker            ppmk;

                CreateItemMoniker(null, "SolidWorks_PID_" + sldProc.Id.ToString(), out ppmk);

                GetRunningObjectTable(0, out rot);

                object swAppObj = null;


                rot.GetObject(ppmk, out swAppObj);


                if (swAppObj != null)
                {
                    this.swApp = (SldWorks)swAppObj;
                }
            }
            catch (Exception ex)
            {
                throw ex;
            }

            Main();
        }