2 Replies Latest reply on Aug 19, 2016 4:33 AM by Lukas Najman

    C# add-in shows up in plug-in list but does nothing

    Lukas Najman

      Hi,

       

      because of a problem VSTA macros stopped working after WIN10 Anniversary update, I have decided to rewrite all our macros to C# add-ins. I followed up AngelSix tutorial on writing some simple add-in just to make sure they will work. The sample code did not work as it was registering the add-in in

      HKEY_LOCAL_MACHINE\SOFTWARE\WOW6432Node\SolidWorks\AddIns

      and not in

      HKEY_LOCAL_MACHINE\SOFTWARE\SolidWorks\AddIns.

      As my SW install is 64bit one, the add-in did not show up in available plugins. I rewrote the registering portion of the code and managed it to register itself into correct register, so it is displayed in the SW in available plugins. Problem is, the add-in, after enabling it does nothing. I guess there is still missing some step in the registration of the add-in or something?

       

      For completeness, I am using Visual Studio 2015 Community to develop the plugin. I have both "Make assembly COM visible" and "Register for COM interop" options checked.

       

      Here is the source code of the add-in.

      using System;
      using System.Collections.Generic;
      using System.Linq;
      using System.Text;
      using System.Runtime.InteropServices;
      using Microsoft.Win32;
      using SolidWorks.Interop.sldworks;
      using SolidWorks.Interop.swcommands;
      using SolidWorks.Interop.swconst;
      using SolidWorks.Interop.swpublished;
      using SolidWorksTools;
      
      
      namespace ClassLibrary1
      {
      
      
          [Guid("1fbff20b-cf23-40dc-949a-d89c3f9b74e0"),ComVisible(true)]
          [SwAddin(Description ="MyAddin desc", Title ="My fisrt title")]
          public class SWFirstTestAddin : ISwAddin 
      
      
          {
      
      
              [ComRegisterFunction()]
              private static void ComRegister(Type t)
              {
                  string keyPath = "SOFTWARE\\SolidWorks\\AddIns\\1fbff20b-cf23-40dc-949a-d89c3f9b74e0}";
      
      
      
      
                  RegistryKey baseKey = RegistryKey.OpenBaseKey(RegistryHive.LocalMachine, RegistryView.Registry64);
      
      
                  RegistryKey rk = baseKey.CreateSubKey(keyPath);
                  rk.SetValue(null, 1); // Load at startup
                  rk.SetValue("Title", "My SwAddin"); // Title
                  rk.SetValue("Description", "All your pixels are belong to us"); // Description
                  
              }
      
      
              [ComUnregisterFunction()]
              private static void ComUnregister(Type t)
              {
                  RegistryKey baseKey = RegistryKey.OpenBaseKey(RegistryHive.LocalMachine, RegistryView.Registry64);
                  RegistryKey rk = baseKey.OpenSubKey("SOFTWARE\\SolidWorks\\AddIns");
                  rk.DeleteSubKey("{1fbff20b-cf23-40dc-949a-d89c3f9b74e0}");
              }
      
      
      
      
      
      
              public SldWorks mSwApplication;
              private int mSWCookie;
      
      
              private TaskpaneView mTaskPaneView;
              private SWTaskPaneHost mTaskPaneHost;
      
      
              public bool ConnectToSW(object ThisSW, int Cookie)
              {
                  mSwApplication = (SldWorks)ThisSW;
                  mSWCookie = Cookie;
      
      
                  //Set-up add-in callback function
                  bool result = mSwApplication.SetAddinCallbackInfo2(0, this, Cookie);
                  
                  mSwApplication.SendMsgToUser("Working?");
                  //this.UISetup();
                  return true;
              }
      
      
              public bool DisconnectFromSW()
              {
                  //this.UITeradown();   
                  return true;         
              }
      
      
              private void UISetup()
              {
                  mTaskPaneView = mSwApplication.CreateTaskpaneView2(String.Empty, "Magic task pane!");
                  mTaskPaneHost = (SWTaskPaneHost)mTaskPaneView.AddControl(SWTaskPaneHost.SWTASKPANE_PROGID, "");
              }
      
      
              private void UITeradown()
              {
                  mTaskPaneHost = null;
                  mTaskPaneView.DeleteView();
                  Marshal.ReleaseComObject(mTaskPaneView);
                  mTaskPaneView = null;
      
      
              }
          }
      }
      

       

      Could you please help me to get the add-in working?

       

      Lukas