AnsweredAssumed Answered

Macro Chek-in to the vault

Question asked by Alexander Volkov on Feb 24, 2020
Latest reply on Feb 26, 2020 by Alexander Volkov

Hi, everybody!

I'm using macro to check-in to the vault an assembly file. But in process an error occurs at runtime. It is works correctly when i check-in a part file.

 

---------------------------

---------------------------
HRESULT = 0x8004020B
An attempt was made to access a file that is exclusively opened by another application..
---------------------------
ОК
---------------------------

 

 

public void CheckIn()
{
string UserName;

IEdmUserMgr5 UserMgr;
IEdmUser5 User;
IEdmVault5 vault = new EdmVault5();
IEdmVault7 vault1 = null;
IEdmBatchUnlock2 batchUnlocker;

try
{

if (vault == null)
{
vault = new EdmVault5();
}

vault1 = (IEdmVault7)vault;

UserMgr = (IEdmUserMgr5)vault1;

vault1.LoginAuto("vault name", 0);

User = UserMgr.GetLoggedInUser();
UserName = User.Name;

var model = ((ModelDoc2)(BaseObject.ActiveDoc));
var FileName = model.GetPathName();

IEdmFile5 FileObj;
var ppoSelection = new EdmSelItem[11];

FileObj = vault.GetFileFromPath(FileName, out var retfold);

IEdmFolder5 aFolder;
IEdmPos5 aPos;

aPos = FileObj.GetFirstFolderPosition();
aFolder = FileObj.GetNextFolder(aPos);

ppoSelection[0].mlDocID = FileObj.ID;
ppoSelection[0].mlProjID = retfold.ID;


batchUnlocker = (IEdmBatchUnlock2)vault1.CreateUtility(EdmUtility.EdmUtil_BatchUnlock);
batchUnlocker.AddSelection((EdmVault5)vault1, ref ppoSelection);

bool retVal;
IEdmSelectionList6 fileList = null;

batchUnlocker.CreateTree(0, (int)EdmUnlockBuildTreeFlags.Eubtf_ShowCloseAfterCheckinOption + (int)EdmUnlockBuildTreeFlags.Eubtf_MayUnlock + (int)EdmUnlockBuildTreeFlags.Eubtf_SkipOpenFileChecks);

batchUnlocker.Comment = "Updates";

fileList = (IEdmSelectionList6)batchUnlocker.GetFileList((int)EdmUnlockFileListFlag.Euflf_GetUnlocked + (int)EdmUnlockFileListFlag.Euflf_GetUndoLocked + (int)EdmUnlockFileListFlag.Euflf_GetUnprocessed);
retVal = batchUnlocker.ShowDlg(0);

object statuses = null;
if ((retVal))
{
batchUnlocker.UnlockFiles(0, null);
statuses = batchUnlocker.GetStatus((int)EdmUnlockStatusFlag.Eusf_CloseAfterCheckinFlag);
model.ReloadOrReplace(false, model.GetPathName(), false);
}
}
catch (System.Runtime.InteropServices.COMException ex)
{
System.Windows.MessageBox.Show("HRESULT = 0x" + ex.ErrorCode.ToString("X") + "\n" + ex.Message);
}
catch (Exception ex)
{
System.Windows.MessageBox.Show(ex.Message);
}
}

Outcomes