我试图通过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)
方法的错误。
&#34;参数不正确,hresult:0x80070057(E_INVALIDARG)&#34;
答案 0 :(得分:1)
我没有使用好方法。这是怎么做的:
{{1}}
答案 1 :(得分:1)
对于那些潜伏的人,请确保在EdmLib上将“嵌入互操作类型”设置为false。