无法将SetVar与PostAdd或PreAdd挂钩PDM Api一起使用

时间:2018-07-18 13:54:18

标签: c# solidworks

我正在使用 SolidWorks PDM 2017 SP5

您好,我正在使用一个插件,当将文档添加到Vault时必须修改变量,问题是PreAddPostAdd都返回一个错误文件没有被我签出( 0x080040210 ),显然文件尚未注册

这是我的代码

public void GetAddInInfo(ref EdmAddInInfo poInfo, IEdmVault5 poVault, IEdmCmdMgr5 poCmdMgr)

        {

            poInfo.mbsAddInName = "Titulo C# Add-In";

            poInfo.mbsCompany = "ARTRANS S.A.";

            poInfo.mbsDescription = "Renombra los títulos de las obras de epdm.";

            poInfo.mlAddInVersion = 1;

            poInfo.mlRequiredVersionMajor = 17;

            poInfo.mlRequiredVersionMinor = 5;

           //Create PreAdd hook (with PostAdd i have the same result)

            poCmdMgr.AddHook(EdmCmdType.EdmCmd_PreAdd);

        }

public void OnCmd(ref EdmCmd poCmd, ref Array ppoData)

{
 switch (poCmd.meCmdType)    
 {    
        case EdmCmdType.EdmCmd_PreAdd:    

            IEdmVault5 _Vault = (IEdmVault5)poCmd.mpoVault;

            IEdmFile5 archivo = default(IEdmFile5);

            var varManager = default(IEdmEnumeratorVariable8);    

            foreach (EdmCmdData fila in ppoData)

            {

                archivo = (IEdmFile5)_Vault.GetObject(EdmObjectType.EdmObject_File, fila.mlObjectID1);

                varManager = (IEdmEnumeratorVariable8)archivo.GetEnumeratorVariable();

                varManager.SetVar("Title", "", "Example"));

                varManager.CloseFile(true);

            }

            break;   
    }    
}

有人知道该怎么做吗?我真的没主意了!

非常感谢

2 个答案:

答案 0 :(得分:1)

我找到了有关 EdmCmdData Structure 的文档,其中包含每个钩子上EdmCmdData结构的行为,因此,以我为例,使用PostAdd

我知道了

父文件夹 EdmCmdData.mlObjectID1

中的ID

本地文件路径 EdmCmdData.mbsStrData1

并使用所需的数据替换以下行:

archivo = (IEdmFile5)_Vault.GetObject(EdmObjectType.EdmObject_File, fila.mlObjectID1);

为此

IEdmFolder5 carpeta = (IEdmFolder5)_Vault.GetObject(EdmObjectType.EdmObject_Folder, fila.mlObjectID1);
archivo = _Vault.GetFileFromPath(fila.mbsStrData1,out carpeta);

答案 1 :(得分:1)

您需要处理PostAdd,并确保文件已由您在计算机上签出。

IEdmVault12 _Vault = (IEdmVault12)poCmd.mpoVault;
// Get our userId
var userId = _Vault.GetLoggedInWindowsUserID(_Vault.Name);
IEdmFile5 archivo = default(IEdmFile5);
var varManager = default(IEdmEnumeratorVariable8);
foreach (EdmCmdData fila in ppoData)
{
    archivo = (IEdmFile5)_Vault.GetObject(EdmObjectType.EdmObject_File, fila.mlObjectID1);
    // Make sure we're the user with the file checked out and it's checked out on this machine.
    if (archivo.LockedByUserID != userId || archivo.LockedOnComputer != Environment.MachineName)
        continue;

    varManager = (IEdmEnumeratorVariable8)archivo.GetEnumeratorVariable();
    varManager.SetVar("Title", "", "Example"));
    varManager.CloseFile(true);

}