This topic shows how to create a
debug add-in using Visual C# in Microsoft Visual Studio.
NOTE:
Because SOLIDWORKS PDM Professional cannot force a reload of
add-ins if they are written in .NET, all client machines must be restarted to ensure that the latest version of the add-in is used.
Replace:
public class Class1
with:
[Guid(""),
ComVisible(true)]
public class Class1 : IEdmAddIn5
public void GetAddInInfo(ref EdmAddInInfo poInfo, IEdmVault5 poVault, IEdmCmdMgr5 poCmdMgr)
{
//Specify
information to display in the add-in's Properties dialog box
poInfo.mbsAddInName = "C# Add-in";
poInfo.mbsCompany = "My Company";
poInfo.mbsDescription = "Menu add-in that shows a message box.";
poInfo.mlAddInVersion = 1;
//Specify
the minimum required version of SolidWorks PDM
Professional
poInfo.mlRequiredVersionMajor = 6;
poInfo.mlRequiredVersionMinor = 4;
// Register a menu command
poCmdMgr.AddCmd(1, "C# Add-in", (int)EdmMenuFlags.EdmMenu_Nothing);
}
public void OnCmd(ref EdmCmd poCmd, ref EdmCmdData[] ppoData)
{
// Handle the menu command
if (poCmd.meCmdType == EdmCmdType.EdmCmd_Menu)
{
if (poCmd.mlCmdID == 1) {
System.Windows.Forms.MessageBox.Show("C# Add-in");
}
}
}
using System;
using System.Collections.Generic;
using System.Text;
using System.Windows.Forms;
namespace Addin_CSharp
{
//Wrapper class to use SOLIDWORKS PDM Professional as the parent window
class WindowHandle : IWin32Window
{
private IntPtr mHwnd;
public WindowHandle(int hWnd)
{
mHwnd = new IntPtr(hWnd);
}
public IntPtr Handle
{
get { return mHwnd; }
}
}
}Your add-in uses the new wrapper in the menu command handler to show the message box by calling System.Windows.Forms.MessageBox.Show in Class1::OnCmd in Class1.cs.
//Class1.cs
using System;
using System.Collections;
using System.Collections.Generic;
using System.Data;
using System.Diagnostics;
using System.Windows.Forms;
using System.Runtime.InteropServices;
using EPDM.Interop.epdm;
[Guid(""), ComVisible(true)] // See step 14 above to create the GUID
public class Class1 : IEdmAddIn5
{
public void GetAddInInfo(ref EdmAddInInfo poInfo, IEdmVault5 poVault, IEdmCmdMgr5 poCmdMgr)
{
poInfo.mbsAddInName = "C# Add-in";
poInfo.mbsCompany = "My Company";
poInfo.mbsDescription = "Menu add-in that shows a message box.";
poInfo.mlAddInVersion = 1;
poInfo.mlRequiredVersionMajor = 6;
poInfo.mlRequiredVersionMinor = 4;
poCmdMgr.AddCmd(1, "C# Add-in", (int)EdmMenuFlags.EdmMenu_Nothing);
}
public void OnCmd(ref EdmCmd poCmd, ref EdmCmdData[] ppoData)
{
if (poCmd.meCmdType == EdmCmdType.EdmCmd_Menu)
{
if (poCmd.mlCmdID == 1)
{
System.Windows.Forms.MessageBox.Show("C# Add-in");
}
}
}
}//WindowHandle.cs
using System;
using System.Collections.Generic;
using System.Text;
using System.Windows.Forms;
namespace Addin_CSharp
{
class WindowHandle : IWin32Window
{
private IntPtr mHwnd;
public WindowHandle(int hWnd)
{
mHwnd = new IntPtr(hWnd);
}
public IntPtr Handle
{
get { return mHwnd; }
}
}
}