8 Replies Latest reply on Nov 9, 2017 1:43 AM by Mr Omkar Deshpande

    Add-In in two sessions of SolidWorks

    Mr Omkar Deshpande

      Hi,

       

      I have developed an add-in in VB.NET. It works fine and as intended. But when i open a second session of SW, i get this message>

       

      If i say 'Run' it will open sldim.exe and

      if i say 'Cancel', it will open second session of SW, in list of add-ins, my add-in will be shown loaded, but i cannot see my toolbar.

       

      Any help on this is appreciated.

       

      Thanks in advance

       

      Omkar

        • Re: Add-In in two sessions of SolidWorks
          Alex Burnett

          Some detail would be helpful. Is your Add-In a standalone program that the user will launch separately? Or, is it a taskpane Add-In that shows up on the right hand toolbar?

           

          Edit: I thought of another question. Are you wanting your single add-in to recognize multiple sessions of SW or do you want one add-in for each session?

            • Re: Add-In in two sessions of SolidWorks
              Mr Omkar Deshpande

               

              Edit: I thought of another question. Are you wanting your single add-in to recognize multiple sessions of SW or do you want one add-in for each session?

              I want my add-in toolbar in each session of SW should be working freely from each other.

                • Re: Add-In in two sessions of SolidWorks
                  Deepak Gupta

                  Did you register it properly?

                    • Re: Add-In in two sessions of SolidWorks
                      Mr Omkar Deshpande

                      This is what i used for registering and deregistering

                      <ComRegisterFunction()> Public Shared Sub RegisterFunction(ByVal t As Type)

                       

                         
                          Dim attributes() As Object
                          Dim SWattr As SwAddinAttribute = Nothing

                       

                          attributes = System.Attribute.GetCustomAttributes(GetType(TmxBOMAddin), GetType(SwAddinAttribute))

                       

                          If attributes.Length > 0 Then
                              SWattr = DirectCast(attributes(0), SwAddinAttribute)
                          End If
                          Try
                              Dim hklm As Microsoft.Win32.RegistryKey = Microsoft.Win32.Registry.LocalMachine
                              Dim hkcu As Microsoft.Win32.RegistryKey = Microsoft.Win32.Registry.CurrentUser

                       

                              Dim keyname As String = "SOFTWARE\SolidWorks\Addins\{" + t.GUID.ToString() + "}"
                              Dim addinkey As Microsoft.Win32.RegistryKey = hklm.CreateSubKey(keyname)
                              addinkey.SetValue(Nothing, 0)
                              addinkey.SetValue("Description", SWattr.Description)
                              addinkey.SetValue("Title", SWattr.Title)

                       

                              keyname = "Software\SolidWorks\AddInsStartup\{" + t.GUID.ToString() + "}"
                              addinkey = hkcu.CreateSubKey(keyname)
                              addinkey.SetValue(Nothing, SWattr.LoadAtStartup, Microsoft.Win32.RegistryValueKind.DWord)
                          Catch nl As System.NullReferenceException
                              Console.WriteLine("There was a problem registering this dll: SWattr is null.\n " & nl.Message)
                              System.Windows.Forms.MessageBox.Show("There was a problem registering this dll: SWattr is null.\n" & nl.Message)
                          Catch e As System.Exception
                              Console.WriteLine("There was a problem registering this dll: " & e.Message)
                              System.Windows.Forms.MessageBox.Show("There was a problem registering this dll: " & e.Message)
                          End Try
                      End Sub

                       

                      <ComUnregisterFunction()> Public Shared Sub UnregisterFunction(ByVal t As Type)
                          Try
                              Dim hklm As Microsoft.Win32.RegistryKey = Microsoft.Win32.Registry.LocalMachine
                              Dim hkcu As Microsoft.Win32.RegistryKey = Microsoft.Win32.Registry.CurrentUser

                       

                              Dim keyname As String = "SOFTWARE\SolidWorks\Addins\{" + t.GUID.ToString() + "}"
                              hklm.DeleteSubKey(keyname)

                       

                              keyname = "Software\SolidWorks\AddInsStartup\{" + t.GUID.ToString() + "}"
                              hkcu.DeleteSubKey(keyname)
                          Catch nl As System.NullReferenceException
                              Console.WriteLine("There was a problem unregistering this dll: SWattr is null.\n " & nl.Message)
                              System.Windows.Forms.MessageBox.Show("There was a problem unregistering this dll: SWattr is null.\n" & nl.Message)
                          Catch e As System.Exception
                              Console.WriteLine("There was a problem unregistering this dll: " & e.Message)
                              System.Windows.Forms.MessageBox.Show("There was a problem unregistering this dll: " & e.Message)
                          End Try

                       

                      End Sub