我正在尝试通过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)
方法上的错误。
“参数错误,结果: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);
}
}
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句