14 Replies Latest reply on Jan 11, 2017 6:12 AM by Christoph Engelhardt

    API C# Property Manager Page: macro terminates after initialisation

    Christoph Engelhardt

      Hi there,

       

      I am currentyl tyring to implement a property manager page with C#. I use Visual Studio Express 2015, Solidworks 2016 SP5, on a Windows 7 Enterprise 64 bit OS.

       

      When I launch the code inside Visual Studio, the property manager page appears correctly in Solidworks. Though as soon as the property manager page is created, the macro exits. Events from the property manager page are not handled. When I close the property manager page, Solidworks kind of freezes. All functions are greyed out and I have to use the task manager to close Solidworks.

       

      It seems to me, that the macro exits after the pmPage.Show() command instead of waiting for user input...

       

      I would be glad if someone could give me a hint how to solve this issues.

       

      Thanks in advance!

       

      Best

      Chris

       

       

       

       

             
             
             

       

             

       

       

       

       

       

       

        • Re: API C# Property Manager Page: macro terminates after initialisation
          Nilesh Patel

          Hi Chris,

           

          Could you attach your macro?

           

          Regards,

            • Re: API C# Property Manager Page: macro terminates after initialisation
              Christoph Engelhardt

              Hi Nilesh,

               

              here is the code I am using. The macro should connect to SldWorks and open a property manager page with a message.

               

              main class:

               

                   namespace PMPmacro

                   {

                       static class Program

                       {

                           [STAThread]

                           static void Main()

                           {

                               Debug.Print(" :: Connect to SldWorks");

                               try { swApp = (SldWorks.SldWorks)Marshal.GetActiveObject("SldWorks.Application"); }

                               catch { MessageBox.Show(" ERROR connecting to SldWorks "); return; }

               

                               PMP myPMP = new PMP();

                               myPMP.Start(swApp);

                           }

                       }

                   }

               

              and the pmp class:

               

                   namespace PMPmacro

                   {

                       class PMP : PropertyManagerPage2Handler9

                       {

                           PropertyManagerPage2 pmPage;

               

                           public void Start(SldWorks.SldWorks swApp)

                           {

                               int pageoptions = (int)(swPropertyManagerPageOptions_e.swPropertyManagerOptions_OkayButton |                          swPropertyManagerPageOptions_e.swPropertyManagerOptions_LockedPage);

               

                               int iErrors = 0;

               

                               pmPage = (PropertyManagerPage2)swApp.CreatePropertyManagerPage("TJSL Parametrisierung", pageoptions, null, ref                          iErrors);

               

                               if (iErrors != (int)swPropertyManagerPageStatus_e.swPropertyManagerPage_Okay)

                               {

                                   MessageBox.Show("Failed to create page: " + ((swPropertyManagerPageStatus_e)iErrors).ToString());

                                   return;

                               }

               

                               pmPage.SetMessage3("Welcome to my first PMP", (int)swPropertyManagerPageMessageVisibility.swImportantMessageBox,                                         (int)swPropertyManagerPageMessageExpanded.swMessageBoxMaintainExpandState, "My Caption");

               

                               pmPage.Show();

                           }

               

                      // generated code with functions to implement interface

               

              Sorry for the bad formatting, couldn't find a way to highlight code better...

               

              Best
              Chris