4 Replies Latest reply on Sep 2, 2014 10:17 PM by Adam Hoffman

    Is There A Configuration Change Notify Event

    Adam Hoffman

      I'm wondering if there is a notify event for an active configuration change in the open document?

      I have an add-in I'm working on that creates a new taskpane view that has some buttons and a

      listbox on it. I populate the listbox with all of the configuration names whenever the active document

      changes with:

       

      Private Function swApp_ActiveModelDocChangeNotify() As Integer Handles swApp.ActiveModelDocChangeNotify

      Thank You Ivana Kolin!

       

      I then set the selected item of the listbox as whatever the active configuration is. But I don't know if there is a

      similar event for an active configuration change. Any help would be appreciated. Thanks.

        • Re: Is There A Configuration Change Notify Event
          Daniel Andersson

          Yes there is such events.  But it has to be handled for each document type. Please see the namespace for sldworks. At the bottom of the page you find all events that is possible to use.

           

          http://help.solidworks.com/2013/English/api/sldworksapi/SolidWorks.Interop.sldworks~SolidWorks.Interop.sldworks_namespace.html

           

          Please mark my answer as correct if it helped you.

          //Daniel

            • Re: Is There A Configuration Change Notify Event
              Adam Hoffman

              I'm still trying to learn how to write add-ins properly and I seem to be having issues with doing this correctly. I'm used to writing my macros in a windows form app as a stand alone exe. So in my SWTaskPaneAddIn.vb class I put the change notify functions, but how do I go about accessing the part, assembly, and model document objects from my user control class?

               

              To clarify, I have a sub in my usercontrol class called FillConfigListBox. All of my notify events in my add-in class work correctly(I used a message box for extensive testing). But I can't seem to call this sub from there. In a stand alone app, all I had to do was call it a Public Sub and I could access that sub from any form I wanted. But in the add-in I can't seem to do this the same way. How would I go about accessing subs and objects on my user control from my SWTaskPaneAddIn.vb add in class?

                • Re: Is There A Configuration Change Notify Event
                  Daniel Andersson

                  I'm not sure if I really follow what you are trying to do. Have you created the add-in with templates from the SDK package or written the add-in from scratch. (it really doesn't matter for how to solve things, but it is good to know what you have in your project). All code below is in vb.net.

                   

                  1) Access part, drawing etc..

                  I would use global variables to access the part, assembly,etc that is defined by to events. Using global ("Public Shared...") variables gives you the possibility to access them from where ever you want.

                  To create global variables, add a new class (prefered to call it GlobalVariables) to your project

                   

                  The code could look something like this, note the Imports function at the top

                   

                  Imports SolidWorks.Interop.sldworks
                  Public Class GlobalVariable
                       Public Shared WithEvents gl_swPart As PartDoc
                       Public Shared WithEvents gl_swAssembly As AssemblyDoc
                       Public Shared WithEvents gl_swDrawing As DrawingDoc
                  End Clas
                  
                  
                  
                  
                  
                  
                  
                  
                  
                  

                  Now you can import this class to what ever class (object) you like. You can set and get values to them. You import it by adding "Imports 'Your Project Name'.GlobalVariables".

                  In your case you would import them to SWTaskPaneAddIn and to the code of the user control. By doing that, you would have variables gl_swPart as PartDoc type etc, etc accessible at both locations.

                  The big boys (real programmers and software developers) knows more about this at StackOverflow.com. A very good site to look for answers at.

                   

                  The other way around is to declare these in the user control once they are needed. Which could simply be done using the ActiveDoc function if you are just looking for doing actions with the active document. This is a easier way and not that messy as doing global variables.

                   

                  In the end, it depends on what functions or methods you write and how they should use information from the events that would be the things that tells which solution that is the best one.

                   

                  2) You can access the functions. methods and objects in the user control as follow.

                  Somewhere in your code you most likely create the taskpane object and create it. I guess that in the SwVBAddin class (If you have used the SDK template, the SwVBAddin is the default name) you have something like

                   

                  Dim myTaskPaneView as New TaskpaneView
                  Dim myTaskPaneHost as New SWTaskPaneAddIn
                  
                  
                  
                  
                  
                  
                  
                  
                  
                  

                  You might also have something very similar to this as well in the SwVBAddin (yours SWTaskPaneAddIn?).

                   

                  Public Sub AddTaskPane() 'This function is used to add the task pane once the add in is launched.
                  myTaskPaneView = SwApp.CreateTaskpaneView2("", "swEventTesting")
                  myTaskPaneHost = myTaskPaneView.AddControl("swEventTesting.UserControl1", "")
                  myTaskPaneHost.getSwApp(SwApp)
                  End Sub
                  
                  
                  
                  
                  
                  
                  

                  The Dim statement and the actions going on in the Sub tells us that you can acces your taskpane objects with e.g myTaskPaneHost.Label1.Text.

                   

                  So in the event functions, just go for myTaskPaneHost. and you will get the list of all objects, functions and methods that you can use.

                  Please let me know if you do not regognize the Dim statements above and reply how you implement your user control.

                   

                  Please mark this answer as correct if it helped you.

                  // Daniel