7 Replies Latest reply on Apr 14, 2017 2:27 AM by Ross John

    VB.NET Addin: How to stop addin command?

    Ross John

      Hello Forum,

       

      I am using standard VB.NET Addin and want to add some lines into SwAddin.vb file, so the Addin command could be stopped, if some criterien are not satisfied.

       

      For example I have such lines in a function of SwAddin.vb...

       

              If 3 <> 4 Then

                  MsgBox("Error! Run this addin again!")

                  ' What should I write here to stop Addin and quit?

              End If

       

      Thanks!

       

      Update: I only want to quit the Addin command, not the SolidWorks.

        • Re: VB.NET Addin: How to stop addin command?
          Nilesh Patel

          Hi John,

           

          Use ' Return' to end the sub or function.

           

          Regards,

          • Re: VB.NET Addin: How to stop addin command?
            Christian Chu

            Ross,

            As Nilesh recommended, you can use "return" in a function call to exit the addin

            you can declare function as integer with return 1 to keep addin running or return 0 to exit the addin

             

            Public Function AddinCheck() As Integer
                If 3<> 4 then 
                       MsgBox("Error! Run this addin again!")
                      Return 0
                end if
                Return 1                                                                               
            End Function
            
              • Re: VB.NET Addin: How to stop addin command?
                Ross John

                Thanks Christian!

                But it does not work as I expect. Actually it continue runs and nothing's happened.

                 

                The function AddinCheck() is fired from PMPHandler.vb, when the button is clicked. Do I also need to add some lines there, to get the return value from AddinCheck()? Here is the codes from PMPHandler.vb...

                 

                Sub OnButtonPress(ByVal id As Integer) Implements PropertyManagerPage2Handler9.OnButtonPress

                        userAddin.AddinCheck()

                        ' Is it necessary to write some lines here?

                End Sub

                  • Re: VB.NET Addin: How to stop addin command?
                    Christian Chu

                    Ross,

                    "Stop" is not really clear here. The return in function call here is more like do/don't action. if you want to exit (stop) a running command, it'd better using exit sub

                    By the way, it's hard to say without seeing your code as I copied 3<>4 from your code while it doesn't mean much to me

                    • Re: VB.NET Addin: How to stop addin command?
                      Matthew Cempa

                      John,

                      I'm not clear on if you want to just not do anything with the button press.  If so you could just do something like this:

                      Sub OnButtonPress(ByVal id As Integer) Implements PropertyManagerPage2Handler9.OnButtonPress

                              dim iCheck as integer

                              iCheck = userAddin.AddinCheck()

                              if iCheck <> 0 then

                                     ' do your work here

                              end if              

                      End Sub

                       

                      if you want to disable the addin command then you can do that with the ICommandGroup.AddCommandItem2 method.  It calls the enable method that you specify and in that you can disable the command based on whatever you wish.

                       

                      If you want to close the property manager page of the addin then you could call the IPropertyMangerPage2.Close method.

                       

                      On a side note I prefer to use the ISldWorks.SendMessageToUser2 instead of a message box.

                        • Re: VB.NET Addin: How to stop addin command?
                          Ross John

                          Hello Matthew,

                           

                          Thanks for your comments and codes. I actually have never thought about that there could be so many different meanings of my question. Sorry for the unclearness.

                           

                          After reading your reply I would say, I want to close the property manager page. And go back to SolidWorks working environment. To be more exactly, I want to go back to such situation, as if the Addin-Button was NOT clicked. But, if I would, the Addin-Button should be run again.

                           

                          So I think the IPropertyMangerPage2.Close is what I am looking for. BTW, I did not find it, do you mean the PropertyManagerPage2Handler9.OnClose method?

                           

                          I would like ask for your further help. How to "activate" the OnClose method into your code...

                          Sub OnButtonPress(ByVal id As Integer) Implements PropertyManagerPage2Handler9.OnButtonPress

                                  dim iCheck as integer

                                  iCheck = userAddin.AddinCheck()

                                  if iCheck <> 0 then

                                         ' do your work here  ---How to write the code here and get the job done?

                                  end if             

                          End Sub

                           

                          Thanks,

                          Ross