此示例展示如何使用Visual C#编写的Add-ins为文件数据卡生成序列号。
注意事项:
SOLIDWORKS PDM Professional无法强制重新加载用.NET编写的Add-ins,必须重新启动所有客户端计算机,以确保使用Add-ins的最新版本。
SOLIDWORKS PDM Professional建议使用内置格式字符串或列表生成序列号。它们提供了比Add-ins生成的序列号或文件序列号更好的性能。仅当内置格式字符串或列表不足时,才编写Add-ins以生成序列号。
序列号编码器与其他类型挂钩的区别在于:
在IEdmAddIn5::GetAddInInfo方法中注册你的钩子。在IEdmAddIn5::OnCmd方法中编写内容。
启动VS。新建项目,选择类库。![](https://img-blog.csdnimg.cn/42856734832c4150ad6e7fd9a72d52ee.png) 在“解决方案资源管理器”中右键单击项目名称 ,然后单击添加引用。
单击 COM 在 左侧面板,单击PDMWorks Enterprise 2019 Type Library,然后单击添加。![](https://img-blog.csdnimg.cn/7fb072c5b0724ee99b6f05a8940dad3d.png) 如果需要,引入相关的程序集。设置Interop.EdmLib的嵌入互操作类型为False。 在“解决方案资源管理器”中右击项目名称,然后单击“属性”。
“应用程序>程序集信息”。 取消勾选“使程序集 COM 可见(M)”。 修改Class1.cs。这里修改类名为MySerial.cs。
添加和创建GUID。![](https://img-blog.csdnimg.cn/7c60e9affa0546cc89ea61dc471b4589.png) 修改代码 using System;
using System.Runtime.InteropServices;//添加
using EdmLib;//添加
namespace Creating_Serial_Numbers
{
[Guid("90C81B4A-560D-4FBF-9F08-E670D4ABB892"), ComVisible(true)]
public class MySerial:IEdmAddIn5
{
}
}
实现 IEdmAddIn5::GetAddInInfo 和IEdmAddIn5::OnCmd using System;
using System.Runtime.InteropServices;//添加
using EdmLib;//添加
namespace Creating_Serial_Numbers
{
[Guid("90C81B4A-560D-4FBF-9F08-E670D4ABB892"), ComVisible(true)]
public class MySerial:IEdmAddIn5
{
public void GetAddInInfo(ref EdmAddInInfo poInfo, IEdmVault5 poVault, IEdmCmdMgr5 poCmdMgr)
{
//Return information about this add-in to the Administrate Add-ins dialog
poInfo.mbsAddInName = "My serial number generator";
poInfo.mbsCompany = "The name of my company";
poInfo.mbsDescription = "Implements serial numbers";
poInfo.mlAddInVersion = 1;
poInfo.mlRequiredVersionMajor = 5;
poInfo.mlRequiredVersionMinor = 2;
//Notify that a serial number needs to be generated
poCmdMgr.AddHook(EdmCmdType.EdmCmd_SerialNo);
}
public void OnCmd(ref EdmCmd poCmd, ref Array ppoData)
{
//Check the upper and lower bounds of the array
int Index = ppoData.GetLowerBound(0);//获取数组中指定维度第一个元素的索引。
int last = ppoData.GetUpperBound(0);//获取数组中指定维度最后一个元素的索引。
if (Index 文件卡 -> Text Card,选择Title后面的Textbox,在右侧窗口选择序列号,我的序列号,保存数据卡。 在库中新建text文件。
打包:https://download.csdn.net/download/hd51cc/87887157
|