Hello.
I bought the SolidWorks Connect, and I would like to make some Add-ins for SolidWorks.
I previously succesfully made an Add-in, at my work using a Standard SolidWorks license.
I now succesfully made the add-in display a message-box on startup, but my Taskpane does not show. But now it seems like I can't get it working. I am still not a good programmer, and do not undertand all that COM stuff etc., so I have been following AngelSix' tutorials on YouTube. This is also what I did the last time, so I am wondering if SolidWorks Connect even allows the use of Add-ins?
I do see my Add-ins name in the Tools -> Add-ins but even though it should be set to start-up automatically, it does not. And if I check either of the boxes in the Add-ins window, nothing happens.
To get the template files, and compare their code to mine, I tried installing the SolidWorks API SDK.msi which I found in \win_b64\resources\MSI\ as the help-page suggested. But I do not seem to be able to find the .zip files with the temlpates. The help.page states: Double-click apisdk.exe or SolidWorks API SDK.msi to run the API SDK InstallShield Wizard. If you have multiple Visual Studio versions, you may need to manually install the templates into the proper template folders. Locate and copy the zip files into the c:\Users\Documents\Visual Studio 20xx\Templates\ProjectTemplates\VisualBasic or Visual C#.
The template files are not visible for me in Visual Studio 2022, and I can't find the .zip files anywhere. Any ideas what to do?
Edit:
If anybody would want to take some time and look at my code, please do so.
Here is my code, if anybody would take a look:
TaskpaneIntegration.cs :
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Runtime.InteropServices;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using SolidWorks.Interop.sldworks;
using SolidWorks.Interop.swpublished;
namespace TaskpaneTemplate
{
///
/// A SolidWorks ColourLibary
///
public class TaskpaneIntegration : ISwAddin
{
#region Private Members
///
/// The cookie to the current instane of SolidWorks we are running in.
///
private int mSwCookie;
///
/// The TaskpaneView for our add-in.
///
private TaskpaneView mTaskpaneView;
///
/// The UI control that is going to be inside the SolidWorks taskpane view.
///
private TaskpaneHostUI mTaskpaneHost;
///
/// The current instance of the SolidWorks application.
///
private SldWorks mSolidWorksApplication;
#endregion
#region Public Members
///
/// The unique Id to the taskpane uased for COM registration.
///
public const string SWTASKPANE_PROGID = "letters-and-numbers";
#endregion
#region SolidWorks Add-in Callbacks
///
/// Called when SolidWorks has loaded our add-in and wants us to do our connection logic.
///
/// The current SolidWorks instance
/// The current SolidWorks cookie Id
///
///
public bool ConnectToSW(object ThisSW, int Cookie)
{
// Show a simple message box
MessageBox.Show("Connected to SolidWorks");
// Store a reference to the current SolidWorks instance.
mSolidWorksApplication = (SldWorks)ThisSW;
// Store cookie Id
mSwCookie = Cookie;
// Setup callback info.
var ok = mSolidWorksApplication.SetAddinCallbackInfo2(0, this, mSwCookie);
// Create our UI.
LoadUI();
// Return OK.
return true;
}
///
/// Called when SolidWorks is about to unload our add-in and wants us to do our disconnection logic.
///
///
///
public bool DisconnectFromSW()
{
// Clean up our UI.
UnloadUI();
// Return OK.
return true;
}
#endregion
#region Create UI
///
/// Create the Taskpane and inject host UI.
///
private void LoadUI()
{
MessageBox.Show("Loading UI");
// Find the location to the taskpane icon.
var imagePath = Path.Combine(Path.GetDirectoryName(typeof(TaskpaneIntegration).Assembly.CodeBase).Replace(@"file:\", ""), "colourlibary.png");
// Create the Taskpane.
mTaskpaneView = mSolidWorksApplication.CreateTaskpaneView3(imagePath, "Test123");
// Load the UI into the Taskpane.
mTaskpaneHost = (TaskpaneHostUI)mTaskpaneView.AddControl(TaskpaneIntegration.SWTASKPANE_PROGID, string.Empty);
}
///
/// Clean up the taskpane when we disconnect.
///
///
private void UnloadUI()
{
mTaskpaneHost = null;
// Remove TaskpaneView.
mTaskpaneView.DeleteView();
// Release COM reference and clean up memory.
Marshal.ReleaseComObject(mTaskpaneView);
mTaskpaneView = null;
}
#endregion
#region COM Registration
///
/// The COM registration call to add the registry entries in SolidWorks add-in registry.
///
///
[ComRegisterFunction()]
private static void ComRegister(Type t)
{
var keyPath = string.Format(@"SOFTWARE\SolidWorks\Addins\{0:b}", t.GUID);
// Create the registry folder for the add-in.
using (var rk = Microsoft.Win32.Registry.LocalMachine.CreateSubKey(keyPath))
{
// Load Add-in when SolidWorks opens.
rk.SetValue(null, 1);
// Set the TITLE and DESCRIPTION.
rk.SetValue("Title", "Colour Libary Add-in");
rk.SetValue("Description", "An Add-in");
}
}
///
/// The COM unregister call to remove the custom entries added in the COM register function.
///
///
[ComUnregisterFunction()]
private static void ComUnregister(Type t)
{
var keyPath = string.Format(@"SOFTWARE\SolidWorks\Addins\{0:b}", t.GUID);
// Remove the registry entry
Microsoft.Win32.Registry.LocalMachine.DeleteSubKeyTree(keyPath);
}
#endregion
}
}
and
TaskpaneHostUI.cs :
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Runtime.InteropServices;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace TaskpaneTemplate
{
[ProgId(TaskpaneIntegration.SWTASKPANE_PROGID)]
public partial class TaskpaneHostUI : UserControl
{
public TaskpaneHostUI()
{
InitializeComponent();
}
}
}
When hovering over the private TaskpaneHostUI mTaskpaneHost; variable, Visual Studio displays this:
Kind regards
Marco