1 Reply Latest reply on Jan 7, 2017 3:47 PM by Norbert Gal

    VB.NET set CommandInProgress fails

    Norbert Gal

      Hi,

      I tried to use CommandInProgress property, but I have issues with it.

      2010 SOLIDWORKS API Help - CommandInProgress Property (ISldWorks)

       

      I'd like to set this property to True before my app begins to work, and like to set to False when it ends, like the link said above.

       

      I have this Modules /Classes:

      Public Class MainForm

          Public Sub MainForm_Load... 'This runs first

      SwxConnectModule.SwxConnect()

      ...

       

      Public Module SwxConnectModule

      Public swApp As SldWorks.SldWorks

      ....

       

      Public Class myForm

      Public Sub myForm_Load...

      ...

      Public Sub myForm_FormClosed...

      ...

       

      I tried this many ways seen below, but seems I couldn't set this property.

       

      Method 1

      Public Module SwxConnectModule

      Public swApp As SldWorks.SldWorks

      ....

       

      Public Class myForm

      ...

      Public Sub myForm_FormClosed..

      swApp.CommandInProgress = False

      Debug.Print(swApp.CommandInProgress) '--This prints True

      ...

       

      Method 2

      Public Module SwxConnectModule

      Public swApp As SldWorks.SldWorks

      Public swIApp As SldWorks.ISldWorks '--ISldworks Interface

      ....

       

      Public Class myForm

      ...

      Public Sub myForm_FormClosed...

      swIApp.CommandInProgress = False '--This occurs: Exception thrown: 'System.NullReferenceException' in SWXapp.exe

      Debug.Print(swApp.CommandInProgress)

      ...

      Method 3

      Public Module SwxConnectModule

      Public swApp As SldWorks.SldWorks

      ....

       

      Public Class myForm

          Public swIApp As SldWorks.ISldWorks '--ISldworks Interface inside myForm Class

      ...

      Public Sub myForm_FormClosed...

      swIApp.CommandInProgress = False '--This occurs: Exception thrown: 'System.NullReferenceException' in SWXapp.exe

      Debug.Print(swApp.CommandInProgress)

      ...

      Method 4

      Public Module SwxConnectModule

      Public swApp As SldWorks.SldWorks

      ....

       

      Public Class myForm

         

      ...

      Public Sub myForm_FormClosed...

         Dim swIApp As SldWorks.ISldWorks '--ISldworks Interface inside closing Sub

      swIApp.CommandInProgress = False '--This occurs: Exception thrown: 'System.NullReferenceException' in SWXapp.exe

      Debug.Print(swApp.CommandInProgress)

      ...

       

      Anybody has any idea?

      Thank you

        • Re: VB.NET set CommandInProgress fails
          Norbert Gal

          After lots of tries, I've recognised Solidworks creates unwanted things (unavailable menu items, unclosable documents etc..), so I guess while I was tried to figure out how my code works well, I called swApp.CommandInProgress=true "too many times".

          After I restarted Solidworks and fixed errorhandling in my app.. voila this works, and my app runs fast as a rocket

           

          Public Class myForm

              Public swApp As SldWorks.SldWorks

          ...

          Public Sub myForm_Load..

          swApp.CommandInProgress = True

          ...

           

          Public Sub myForm_FormClosed..

          swApp.CommandInProgress = False

          Debug.Print(swApp.CommandInProgress) '--Now this prints False