Solidworks PDM API 更新参考错误

Solidworks PDM API update reference error

我正在尝试通过 Api 在 solidworks ePDM 中的两个文件之间添加和删除引用。根据帮助中的示例,这就是我在 c# 中执行此操作的方式。你能告诉我我做错了什么吗?

using EPDM.Interop.epdm;
using EPDM.Interop.EPDMResultCode;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.IO;
using Microsoft.VisualStudio.TestTools.UnitTesting;

namespace Service.EPDM.Data.Test
{
    [TestClass]
    public class Class1
    {

        private EdmVault5 _Vault1 = null;
        private IEdmVault15 _Vault2 = null;

        [TestMethod]
        public void Run()
        {
            try
            {
                _Vault1 = new EdmVault5();
                _Vault1.LoginAuto("MyVault", 32);
                _Vault2 = (IEdmVault15)_Vault1;

                var file1 = "99-Test\OFTEST1\test1.lnk.cvd";
                var file2 = "99-Test\OFTEST1\test2.lnk.cvd";

                UpdateReferences(file1, new List<string>() { file2 }, null);
            }
            catch (Exception ex)
            {
                throw ex;
            }          
        }

        private void UpdateReferences(string iFilePath, List<string> iAddReferenceFilePath, List<string> iRemoveReferenceFilePath)
        {
            if (iAddReferenceFilePath != null && iRemoveReferenceFilePath != null)
                throw new Exception("La liste des références à créer et supprimer est vide");

            var rootPath = _Vault2.RootFolderPath;

            IEdmFolder5 ppoRetParentFolder;
            var theFile = _Vault2.GetFileFromPath(rootPath + "\" + iFilePath, out ppoRetParentFolder);
            var itemFile = (IEdmItem)theFile;

            EdmItemRef[] addRefs = null;

            addRefs = new EdmItemRef[iAddReferenceFilePath.Count];

            int addCounter = 0;
            foreach (var item in iAddReferenceFilePath)
            {
                IEdmFolder5 folder = null;
                var file = _Vault2.GetFileFromPath(rootPath + "\" + item, out folder);
                addRefs[addCounter].moNamePathOrID = rootPath + "\" + item;
                addRefs[addCounter].mlEdmRefFlags = (int)EdmRefFlags.EdmRef_Static + (int)EdmRefFlags.EdmRef_File;
                addRefs[addCounter].moParentNamePathOrItemID = itemFile.ID;
                addCounter++;
            }

            EdmItemRef[] removeRefs = null;
            removeRefs = null;

            itemFile.UpdateReferences(addRefs, removeRefs);
        }

    }
}

这是 itemFile.UpdateReferences(addRefs, removeRefs) 方法的错误。

"Incorrect parameter, hresult : 0x80070057 (E_INVALIDARG)"

我没有用好方法。这是怎么做的:

private void AddReferences(string iFilePath, List iReferenceFile)
{
if (iReferenceFile.IsNullOrEmpty())
throw new Exception("La liste des références à créer est vide");

var rootFolder = (IEdmFolder8)_Vault2.RootFolder;

IEdmFolder5 parentFolder;
var theFile = _Vault2.GetFileFromPath(iFilePath, out parentFolder);

if (theFile == null)
throw new Exception("Le fichier '{0}' n'existe pas".FormatString(iFilePath));

var customReferences = (IEdmEnumeratorCustomReference6)theFile;

foreach(var iFilePathItem in iReferenceFile)
{
IEdmFolder5 parentFolderItem;
var theFileItem = _Vault2.GetFileFromPath(rootFolder.LocalPath + "\" + iFilePathItem, out parentFolderItem);
customReferences.AddReference2(theFileItem.ID, parentFolderItem.ID, 1);
}
}

private void RemoveAllReferences(string iFilePath)
{
IEdmFolder5 parentFolder;
var theFile = _Vault2.GetFileFromPath(iFilePath, out parentFolder);

if (theFile == null)
throw new Exception("Le fichier '{0}' n'existe pas".FormatString(iFilePath));

var customReferences = (IEdmEnumeratorCustomReference6)theFile;
var customReferencePos = customReferences.GetFirstRefPosition();

while (!customReferencePos.IsNull)
{
int refFileId = 0;
int refFolderId = 0;
string path = null;
int quantity = 0;
customReferences.GetNextRef2(customReferencePos, out refFileId, out refFolderId, out path, out quantity);
customReferences.RemoveReference(refFileId, refFolderId);
}
}

对于那些潜伏的人,请确保在 EdmLib 上将 'Embed Interop Types' 设置为 false。