26 Replies Latest reply on Sep 22, 2017 6:04 PM by Amen Allah Jlili

    Using a hook across multiple classes

    Tara Campese

      I'm not sure if what I want is possible. If it is not possible, I will just create two separate add-ins.

       

      Here's what I want my program to do:

      When a user adds a new document to the vault with this add-in, the add-in assigns necessary data card info, checks in the new document, checks out a "Table of Contents" document, populates the ToC Doc, then checks in the ToC Doc.

       

      Everything works great when there are breakpoints. The issue I'm having is that the check-in command does not wait for the document to get added to the vault and thus fails when there are no breakpoints and I am not sure how to do this without an add hook. Is there a way to access the add hook from outside of OnCmd? Or a way to call OnCmd from another class? Or is there an easier way to do this?

       

      I tried Class1.OnCmd(EdmCmdType.EdmCmd_PostAdd, dFile) where dFile is defined as the new file (iedmfile5). But I keep getting the error that EdmCmdType.EdmCmd_PostAdd is an enumerator and not a EdmCmdType. However, this help file is what I get when I search for EdmCmdType. I really don't know what to put as the OnCmd variables to pass.

       

      If I break this project into 2 add-ins (one that creates the new file and one that fills out the ToC Doc), it creates a lot of duplicate work getting the variables all over again. It's not a big deal; I am just wondering if there is a more elegant solution.

       

      For reference, I am using PDM Professional 2017 SP3 and VB.Net.

       

      Thanks,

      Tara

        • Re: Using a hook across multiple classes
          Amen Allah Jlili

          What method are you using to check the file in?

          • Re: Using a hook across multiple classes
            Amen Allah Jlili

            The method here
            2014 SOLIDWORKS API Help - UnlockFile Method (IEdmFile5)

            exposes a callback parameter of type IEdmRefCallback5 (interface), although it's optional. This object that provides notification will be consumed by the method. This is the hook you are looking for.

            You'll need to construct a class than implements this interface and pass an object implementing the interface to that method later on. The interface exposes event handlers that will fire at the start and the end of the check-in process. Add implementations to those event handlers and you should be good.


            If you're familiar with PropertyManagerPages in SOLIDWORKS, this should be fairly easy.

             

            Best,
            Amen
            CADHERO consulting SUARL – CAD Design Automation & Training – SOLIDWORKS API

            Reference:

             

            public class CallBackObject : IEdmRefCallback5
                {
                    #region IEdmRefCallback5 Members

             

                    public int GetFlags(IEdmVault5 poVault)
                    {
                        int flags = (int)EdmRefCbFlag.EdmRefCb_GetRefInfo;
                        return flags;
                    }

             

                    public bool GetRefInfo(ref EdmRefInfo poRefInfo, ref EdmRefState poRefState, int hParentWnd, IEdmVault5 poVault)
                    {
                        if (poRefInfo.mbsRefFilePath.ToLower().Contains("sldprt"))
                        {
                            poRefState.mbSkipFile = 1;
                        }
                        return false;
                    }

             

                    public bool HandleError(int hParentWnd, int lErrorCode, EdmSelectionList5 poFiles, IEdmVault5 poVault)
                    {
                        return true;
                    }

             

                   public void OnEndCommand(int hParentWnd, IEdmVault5 poVault)
                    {
                    }

             

                    public bool OnPostFile(int lFileID, int lParentFileID, int lFolderID, string bsFilePath, int hParentWnd, IEdmVault5 poVault)
                    {
                        return true;
                    }

             

                    public bool OnPreFile(int lFileID, int lParentFileID, int lFolderID, string bsFilePath, int hParentWnd, IEdmVault5 poVault)
                    {
                        return true;
                    }

             

                    public bool OnStartCommand(int hParentWnd, IEdmVault5 poVault)
                    {
                        return true;
                    }

             

                    #endregion

                }
            }

              • Re: Using a hook across multiple classes
                Tara Campese

                Thank you for your help. That seems to be what I'm looking for. However, I'm using VB.Net. I am not quite sure how to translate that.

                  • Re: Using a hook across multiple classes
                    Amen Allah Jlili

                    There you go Miss Tara

                    Public Class CallBackObject
                    Implements IEdmRefCallback5
                    
                    
                    
                    
                    Public Function GetFlags(poVault As IEdmVault5) As Integer
                    
                    
                    End Function
                    
                    
                    Public Function GetRefInfo(ByRef poRefInfo As EdmRefInfo, ByRef poRefState As EdmRefState, hParentWnd As Integer, poVault As IEdmVault5) As Boolean
                    
                    
                    End Function
                    
                    
                    Public Function HandleError(hParentWnd As Integer, lErrorCode As Integer, poFiles As EdmSelectionList5, poVault As IEdmVault5) As Boolean
                    
                    
                    End Function
                    
                    
                    Public Sub OnEndCommand(hParentWnd As Integer, poVault As IEdmVault5)
                    End Sub
                    
                    
                    Public Function OnPostFile(lFileID As Integer, lParentFileID As Integer, lFolderID As Integer, bsFilePath As String, hParentWnd As Integer, poVault As IEdmVault5) As Boolean
                    Return True
                    End Function
                    
                    
                    Public Function OnPreFile(lFileID As Integer, lParentFileID As Integer, lFolderID As Integer, bsFilePath As String, hParentWnd As Integer, poVault As IEdmVault5) As Boolean
                    Return True
                    End Function
                    
                    
                    Public Function OnStartCommand(hParentWnd As Integer, poVault As IEdmVault5) As Boolean
                    Return True
                    End Function
                    
                    
                    
                    
                    
                    
                    End Class
                    
                      • Re: Using a hook across multiple classes
                        Tara Campese

                        Thanks, Amen!

                        I tried it out, but I'm still having issues.

                         

                        For:

                        Public Function OnPostFile(lFileID As Integer, lParentFileID As Integer, lFolderID As Integer, bsFilePath As String, hParentWnd As Integer, poVault As IEdmVault5) As Boolean 

                        Return True 

                        End Function

                         

                        What is the difference between IFileID and IParentFileID? Also, what is hParentWnd?

                         

                        How do I pass the FileID if there isn't one yet since the file has not been added?  Or are these return values?

                         

                         

                         

                          • Re: Using a hook across multiple classes
                            Amen Allah Jlili

                            Can you try

                            UnlockFiles Method (IEdmBatchUnlock)

                            and

                            IEdmUnlockOpCallback as the callback instead.

                             

                            Let me know if this is easier.

                              • Re: Using a hook across multiple classes
                                Tara Campese

                                I tried the UnlockFiles Method from the IEdmBatchUnlock and added it as a sub routine. But it fails on this line:

                                 

                                fileList.Items.Add(FileName)

                                with the error message:

                                items.JPG

                                 

                                 Private Sub BatchUnlock()
                                        Dim batchUnlocker As IEdmBatchUnlock2 = v8.CreateUtility(EdmUtility.EdmUtil_BatchUnlock)
                                        Dim ppoSelection() As EdmSelItem = Nothing
                                        Dim fileList As IEdmSelectionList6 = Nothing
                                        Dim aFile As IEdmFile5
                                        Dim aFolder As IEdmFolder5
                                        Dim aPos As IEdmPos5
                                        Dim retVal As Boolean
                                
                                
                                        Try
                                
                                
                                            If Not IsNothing(batchUnlocker) Then
                                                Dim nbrFiles As Integer = 0
                                                nbrFiles = openFileDialog1.FileNames.Count()
                                                Array.Resize(ppoSelection, nbrFiles)
                                
                                
                                                batchUnlocker.CreateTree(Me.Handle.ToInt32(), EdmUnlockBuildTreeFlags.Eubtf_ShowCloseAfterCheckinOption + EdmUnlockBuildTreeFlags.Eubtf_MayUnlock)
                                                batchUnlocker.AddSelection(v8, ppoSelection)
                                
                                
                                                batchUnlocker.Comment = "Updates"
                                                fileList = batchUnlocker.GetFileList(EdmUnlockFileListFlag.Euflf_GetUnlocked + EdmUnlockFileListFlag.Euflf_GetUndoLocked + EdmUnlockFileListFlag.Euflf_GetUnprocessed)
                                
                                
                                                Dim i As Integer = 0
                                                For Each FileName As String In openFileDialog1.FileNames
                                                    fileList.Items.Add(FileName)
                                                    aFile = v8.GetFileFromPath(FileName)
                                                    aPos = aFile.GetFirstFolderPosition
                                                    aFolder = aFile.GetNextFolder(aPos)
                                                    ppoSelection(i) = New EdmSelItem
                                                    ppoSelection(i).mlDocID = aFile.ID
                                                    ppoSelection(i).mlProjID = aFolder.ID
                                                    i = i + 1
                                                Next
                                                aPos = fileList.GetHeadPosition()
                                
                                
                                                Dim str As String = ""
                                                Dim filecount As Integer = 0
                                                Dim poSel As EdmSelectionObject = Nothing
                                
                                
                                                str = "Getting " & fileCount & " files: "
                                                While Not (aPos.IsNull())
                                                    fileList.GetNext2(aPos, poSel)
                                                    str = str + vbLf + poSel.mbsPath
                                                End While
                                
                                
                                                MsgBox(Str)
                                
                                
                                                retVal = batchUnlocker.ShowDlg(Me.Handle.ToInt32())
                                
                                
                                                Dim statuses As Object
                                                If (retVal) Then
                                                    batchUnlocker.UnlockFiles(Me.Handle.ToInt32(), Nothing)
                                                    statuses = batchUnlocker.GetStatus(EdmUnlockStatusFlag.Eusf_CloseAfterCheckinFlag)
                                
                                
                                                    MsgBox("Close Files after Check In selected? " & statuses)
                                
                                
                                                End If
                                
                                
                                            End If
                                
                                
                                        Catch ex As System.Runtime.InteropServices.COMException
                                            MessageBox.Show("HRESULT = 0x" + ex.ErrorCode.ToString("X") + " " + ex.Message)
                                        Catch ex As Exception
                                            MessageBox.Show(ex.Message)
                                        End Try
                                    End Sub
                                
                      • Re: Using a hook across multiple classes
                        Amen Allah Jlili

                        I think you can let VS implement the interface for you. No need to copy paste code.
                        Just declare the class name and then write implements the interface. A light bulb should show asking if you want to implement the interface implicity or explicity.

                         

                        Cheers,
                        Amen

                        CADHERO consulting SUARL – CAD Design Automation & Training – SOLIDWORKS API

                          • Re: Using a hook across multiple classes
                            Tara Campese

                            I'm pretty sure this is what I need, but I don't know what to pass it as sender or e.

                            Public Sub AddFiles_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles AddFiles.Click
                                    Try
                            
                                        Dim vault2 As IEdmVault7 = Nothing
                                        If vault1 Is Nothing Then
                                            vault1 = New EdmVault5()
                                        End If
                                        vault2 = DirectCast(vault1, IEdmVault7)
                                        If Not vault1.IsLoggedIn Then
                                            'Log into selected vault as the current user
                                            vault1.LoginAuto(VaultsComboBox.Text, Me.Handle.ToInt32())
                                        End If
                            
                                        If Not ListBox.Items.Count = 3 Then
                                            MessageBox.Show("Please click three files that are not in the vault.")
                                            Exit Sub
                                        End If
                            
                                        Dim aFile As IEdmFile6
                            
                                        ' Add selected files to the root folder of the vault
                                        Dim Folder As IEdmFolder6
                                        Folder = vault2.RootFolder
                            
                                        Dim Files() As EdmAddFileInfo
                                        ReDim Files(ListBox.Items.Count - 1)
                            
                                        Dim FileNames(2) As String
                                        Dim Index As Integer = 0
                                        Dim fileStr = ""
                                        For Each FileName In ListBox.Items
                                            fileStr = FileName.ToString()
                                            FileNames(Index) = fileStr.Substring(fileStr.LastIndexOf("\"))
                                            Index = Index + 1
                                        Next
                            
                                        Dim Path As String
                                        Index = 0
                                        For Each FileName In ListBox.Items
                                            Path = FileName
                                            Files(Index).mbsPath = Path
                                            Files(Index).mlEdmAddFlags = EdmAddFlag.EdmAdd_Simple
                                            Files(Index).mlFileID = 0
                                            Files(Index).mlSrcDocumentID = 0
                                            Files(Index).mlSrcProjectID = 0
                                            Files(Index).mbsNewName = ""
                            
                                            Index = Index + 1
                                        Next
                            
                                        Folder.AddFiles(Me.Handle.ToInt32(), Files, Me)
                            
                                        ' Check in the files
                                        Dim arrFiles(3) As IEdmFile6
                                        Index = 0
                                        For Each FileName In FileNames
                                            aFile = vault2.GetFileFromPath(Folder.LocalPath + "\" + FileName)
                                            aFile.UnlockFile(Me.Handle.ToInt32(), "")
                                            arrFiles(Index) = aFile
                            
                                            Index = Index + 1
                                        Next
                            
                                        ' Create \temp\files path in the root folder
                                        Folder.CreateFolderPath("\temp\files", Me.Handle.ToInt32())
                            
                                        ' Move one of the files to the \temp\files subfolder
                                        Dim dest As IEdmFolder5
                                        dest = vault2.GetFolderFromPath(Folder.LocalPath + "\temp\files")
                                        aFile = arrFiles(0)
                                        aFile.Move(Me.Handle.ToInt32(), Folder.ID, dest.ID, 0)
                            
                                        ' Copy one of the files to the temp subfolder
                                        aFile = arrFiles(1)
                                        aFile.GetFileCopy(Me.Handle.ToInt32(), "", Folder.LocalPath + "\temp\")
                            
                                        ' Change the state of one of the files to Waiting for Approval
                                        aFile = arrFiles(2)
                                        aFile.ChangeState("Waiting for Approval", Folder.ID, "The file is waiting for approval.", Me.Handle.ToInt32(), EdmStateFlags.EdmState_Simple)
                            
                                    Catch ex As System.Runtime.InteropServices.COMException
                                        MessageBox.Show("HRESULT = 0x" + ex.ErrorCode.ToString("X") + " " + ex.Message)
                                    Catch ex As Exception
                                        MessageBox.Show(ex.Message)
                                    End Try
                                End Sub
                            
                          • Re: Using a hook across multiple classes
                            Jim Sculley

                            If your code is adding the file to the vault, you should use IEdmBatchAdd2 to add it.  The associated CommitAdd  call doesn't return until the files are actually added, at which point you can check them in.  For what its worth, I use the batch operations for everything, even if there is only one file involved.  The batch calls give you a lot more control over what happens and a lot more information.

                              • Re: Using a hook across multiple classes
                                Tara Campese

                                This is still giving me the same issue and I've been trying all day to get it to work.

                                 

                                The problem is, I need it to add AND check-in all the files. If I use the Batch Add Files and Folders Example, the files get added and not checked in. If I then use the Batch Unlock Files Example, it still triggers before the batch add is complete and tells me that my file is not set to an instance of an object. This only works (as far as I can tell) when I add breakpoints and wait long enough for the file to get added before proceeding.

                                  • Re: Using a hook across multiple classes
                                    Amen Allah Jlili

                                    Can you take to the api support? Surely, there is some sort of bug.

                                    • Re: Using a hook across multiple classes
                                      Jim Sculley

                                      When you call CommitAdd, is the return value correct?  It should be the number of files added.  Also, is the empty array passed in to CommitAdd correctly populated by EPDM with the EdmFileInfo for the file(s)?

                                       

                                      I have an add-in that uses batch add and it has been used with thousands of files that were added and then checked in with no problems.  I add the file with batch add, make some changes to the data card of the added file with batch update and then check it in with batch unlock.  So, the API calls work.  It is either something in your code, or possibly (but I doubt it) some sort of latency problem in your network between the database and archive server.

                                       

                                      Have you tried distilling your code down to the simplest example that displays the bad behavior?  If you can post a complete, simple example, it would be easier to determine if there is a problem with your code.

                                        • Re: Using a hook across multiple classes
                                          Tara Campese

                                          I can try. But it might take me awhile. Is there any way you can post an example of your code that does both batch add and batch unlock?

                                           

                                          The commitAdd value is correct. And when I run with breakpoints, everything works perfectly. When I run without breakpoints, the new file v8.getfilefrompath(NewPath) always returns nothing, unless I manually wait for the commitadd to complete. I must be doing something wrong on the batch add then, but I don't know what. This even happens when I attempt to combine the batch add and batch unlock examples scripts. Although, the examples contain a few errors, so maybe my fixes are not correct.

                                           

                                          To further complicate things, I'm trying to do this without batchAdder.ShowDlg as I want these to add to the vault silently.

                                            • Re: Using a hook across multiple classes
                                              Jim Sculley

                                              My code is part of a much larger add-in, written in C#.  Hopefully you can follow it and do something similar in VB.NET.

                                               

                                              publishedFile = Utilities.addFileToVault(parentWindowHandle, vault, publishFolder.LocalPath + "\\" + publishedFileName);
                                              if (publishedFile == null)
                                              {
                                                  throw new PDMException("Failed to add file to the vault: " + publishedFileName);
                                              }
                                              updateVariableData(publishedFile, data);
                                              if (!checkIn(publishedFile, "New document created"))
                                              {
                                                  throw new PDMException("Failed to check-in newly generated PDF: " + publishedFile.Name);
                                              }
                                              a
                                              

                                               

                                              The addFileToVault in my Utilities class looks like this:

                                               

                                              public static IEdmFile12 addFileToVault(int parentWindowHandle, IEdmVault18 vault, string filePath)
                                              {
                                                   IEdmFile12 addedFile = null;
                                                   IEdmFolder5 folder;
                                                   addedFile = (IEdmFile12)vault.GetFileFromPath(filePath, out folder);
                                                   if (addedFile == null)
                                                   {
                                                        IEdmBatchAdd2 batchAdder = (IEdmBatchAdd2)vault.CreateUtility(EdmUtility.EdmUtil_BatchAdd);
                                                        string folderPath = Path.GetDirectoryName(filePath);
                                                        batchAdder.AddFileFromPathToPath(filePath, folderPath, 0, "", (int)(EdmAddFlag.EdmAdd_GetInterface | EdmAddFlag.EdmAdd_Refresh));
                                                        Array fileInfo = new EdmFileInfo[1];
                                                        int addedFileCount = batchAdder.CommitAdd(parentWindowHandle, ref fileInfo, (int)EdmBatchAddFlag.EdmBaf_Nothing, null);
                                                        if (addedFileCount == 1)
                                                        {
                                                             EdmFileInfo info = ((EdmFileInfo[])fileInfo)[0];
                                                             addedFile = (IEdmFile12)info.mpoObject;
                                                        }
                                                   }
                                                   return addedFile;
                                              }
                                                   
                                              
                                              

                                               

                                              The checkIn method calls a more generic checkIn method that accepts a list of files to check in all at once.  It looks like this:

                                               

                                              protected bool checkInFiles(IEnumerable<IEdmFile12> files, string comment)
                                              {
                                                   if (!files.Any())
                                                   {
                                                        return true;
                                                   }
                                                   bool checkInSucceeded = true;
                                                   Array fileArray = Array.CreateInstance(typeof(EdmSelItem), files.Count());
                                                   int index = 0;
                                                   foreach (IEdmFile12 f in files)
                                                   {
                                                        fileArray.SetValue(getFileData(f), index++);
                                                   }
                                                   IEdmBatchUnlock batchUnlock = (IEdmBatchUnlock)vault.CreateUtility(EdmUtility.EdmUtil_BatchUnlock);
                                                   batchUnlock.Comment = comment;
                                                   batchUnlock.AddSelection((EdmVault5)vault, ref fileArray);
                                                   batchUnlock.CreateTree(parentWindowHandle, (int)(
                                                        EdmUnlockBuildTreeFlags.Eubtf_MayUndoLock |
                                                        EdmUnlockBuildTreeFlags.Eubtf_MayUnlock |
                                                        EdmUnlockBuildTreeFlags.Eubtf_RefreshFileListing), null);
                                                   try
                                                   {
                                                        int options = (int)(EdmUnlockFileListFlag.Euflf_GetUnlocked | EdmUnlockFileListFlag.Euflf_GetUndoLocked);
                                                        IEdmSelectionList6 selList = (IEdmSelectionList6)batchUnlock.GetFileList(options);
                                                        if (selList.Count != 0)
                                                        {
                                                             batchUnlock.UnlockFiles(parentWindowHandle, null);
                                                        }
                                                   }
                                                   catch (COMException cex)
                                                   {
                                                        /* If an attempt is made to check in a file that is open in another application, 
                                                        * a COMException will be thrown.  We catch it here and consider 
                                                        * the check in as having failed
                                                        */
                                                        Utilities.notifyAdministratorsOfException(cex, vault);
                                                        checkInSucceeded = false;
                                                    }
                                                   return checkInSucceeded;
                                              }
                                              
                                              
                                              
                                              
                                              
                                                • Re: Using a hook across multiple classes
                                                  Tara Campese

                                                  Hi Jim,

                                                  Thanks for posting that. I'll look through to see if I can decipher it. In the meantime, I was able to create a basic script that demonstrates this issue.

                                                   

                                                  This script uses the Form1.Designer.vb from the Batch Add Files Example, but with the FileList2 and CopyFromVault removed. You will have to replace Form1.vb with the following: (For reference, it fails on aPos = aFile.GetFirstFolderPosition in the aBatchUnlock() routine because aFile is nothing.

                                                  Imports System.Windows.Forms
                                                  Imports EdmLib
                                                  
                                                  
                                                  Public Class Form1
                                                  
                                                  
                                                      Private vault1 As IEdmVault5 = Nothing
                                                      Dim batchUnlocker As IEdmBatchUnlock2
                                                      Dim batchAdder As IEdmBatchAdd2
                                                      Dim fileList As IEdmSelectionList6 = Nothing
                                                      Dim poSel As EdmSelectionObject = Nothing
                                                      Public ppoSelection() As EdmSelItem
                                                      Dim fileCount As Integer = 0
                                                      Dim aFilePath As String
                                                      Dim aFile As IEdmFile5
                                                      Dim aFolder As IEdmFolder5
                                                      Dim aPos As IEdmPos5
                                                      Dim str As String
                                                      Dim retVal As Boolean
                                                      Dim newFolder As String
                                                      Public Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
                                                  
                                                  
                                                          Try
                                                              Dim vault1 As IEdmVault5 = New EdmVault5()
                                                              Dim vault As IEdmVault8 = DirectCast(vault1, IEdmVault8)
                                                              Dim Views As EdmViewInfo() = Nothing
                                                  
                                                  
                                                              vault.GetVaultViews(Views, False)
                                                              VaultsComboBox.Items.Clear()
                                                              For Each View As EdmViewInfo In Views
                                                                  VaultsComboBox.Items.Add(View.mbsVaultName)
                                                              Next
                                                              If VaultsComboBox.Items.Count > 0 Then
                                                                  VaultsComboBox.Text = DirectCast(VaultsComboBox.Items(0), String)
                                                              End If
                                                          Catch ex As System.Runtime.InteropServices.COMException
                                                              MessageBox.Show("HRESULT = 0x" + ex.ErrorCode.ToString("X") + " " + ex.Message)
                                                          Catch ex As Exception
                                                              MessageBox.Show(ex.Message)
                                                          End Try
                                                      End Sub
                                                  
                                                  
                                                      Public Sub CopyToVault_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles CopyToVault.Click
                                                          Try
                                                  
                                                  
                                                              Dim vault2 As IEdmVault7 = Nothing
                                                              If vault1 Is Nothing Then
                                                                  vault1 = New EdmVault5()
                                                              End If
                                                              vault2 = DirectCast(vault1, IEdmVault7)
                                                  
                                                  
                                                              If Not vault1.IsLoggedIn Then
                                                                  vault1.LoginAuto(VaultsComboBox.Text, Me.Handle.ToInt32())
                                                              End If
                                                  
                                                  
                                                              'Set the initial directory in the Select File dialog
                                                              SelectFileDialog.InitialDirectory = vault1.RootFolderPath
                                                              SelectFileDialog.Multiselect = False
                                                  
                                                  
                                                              'Show the Select File dialog
                                                              Dim DialogResult As System.Windows.Forms.DialogResult = Nothing
                                                              DialogResult = SelectFileDialog.ShowDialog()
                                                              'If the user did not click Open, exit this subroutine
                                                              If Not (DialogResult = System.Windows.Forms.DialogResult.OK) Then
                                                                  Return
                                                              End If
                                                  
                                                  
                                                              batchAdder = vault2.CreateUtility(EdmUtility.EdmUtil_BatchAdd)
                                                  
                                                  
                                                              ' Add Form Folder to the batch 
                                                              newFolder = vault1.RootFolderPath + "\Projects\Test\rbt-qms-FRM-001"
                                                              aFolder = vault1.GetFolderFromPath(newFolder)
                                                              If aFolder Is Nothing Then
                                                                  batchAdder.AddFolderPath(newFolder, 0, EdmBatchAddFolderFlag.Ebaff_Nothing)
                                                              End If
                                                  
                                                  
                                                              For Each FileName As String In SelectFileDialog.FileNames
                                                  
                                                  
                                                                  FileList1.Items.Add(FileName)
                                                  
                                                  
                                                                  ' Add each selected file to the batch
                                                                  'batchAdder.AddFileFromPathToPath(FileName, newFolder, 0)
                                                                  batchAdder.AddFileFromPath(FileName, aFolder.ID, 0, "1235685")
                                                                  aFilePath = newFolder & "\" & "1235685.pdf"
                                                  
                                                  
                                                              Next
                                                          Catch ex As System.Runtime.InteropServices.COMException
                                                              MessageBox.Show("HRESULT = 0x" + ex.ErrorCode.ToString("X") + " " + ex.Message)
                                                          Catch ex As Exception
                                                              MessageBox.Show(ex.Message)
                                                          End Try
                                                      End Sub
                                                  
                                                  
                                                      Public Sub BatchAdd_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles BatchAdd.Click
                                                          Try
                                                  
                                                  
                                                              Dim vault2 As IEdmVault7 = Nothing
                                                              If vault1 Is Nothing Then
                                                                  vault1 = New EdmVault5()
                                                              End If
                                                              vault2 = DirectCast(vault1, IEdmVault7)
                                                              If Not vault1.IsLoggedIn Then
                                                                  vault1.LoginAuto(VaultsComboBox.Text, Me.Handle.ToInt32())
                                                              End If
                                                  
                                                  
                                                              ' Show all of the items in the batch
                                                              'batchAdder.ShowDlg(Me.Handle.ToInt32(), EdmAddFileDlgFlag.Eafdf_Nothing, "Files and folders in the batch:", "Batch Items")
                                                  
                                                  
                                                              Dim ppoAddedFiles() As EdmFileInfo = Nothing
                                                  
                                                  
                                                              ' Commit all of the items in the batch to the vault
                                                              batchAdder.CommitAdd(Me.Handle.ToInt32(), ppoAddedFiles)
                                                  
                                                  
                                                              aBatchUnlock()
                                                  
                                                  
                                                          Catch ex As System.Runtime.InteropServices.COMException
                                                              MessageBox.Show("HRESULT = 0x" + ex.ErrorCode.ToString("X") + " " + ex.Message)
                                                          Catch ex As Exception
                                                              MessageBox.Show(ex.Message)
                                                          End Try
                                                  
                                                  
                                                      End Sub
                                                      Public Sub aBatchUnlock()
                                                          Try
                                                  
                                                  
                                                              Dim i As Integer = 0
                                                              'For Each FileName As String In FileList1.Items
                                                              aFile = vault1.GetFileFromPath(aFilePath)
                                                  
                                                  
                                                              aPos = aFile.GetFirstFolderPosition
                                                              aFolder = aFile.GetNextFolder(aPos)
                                                              ppoSelection(i) = New EdmSelItem
                                                              ppoSelection(i).mlDocID = aFile.ID
                                                              ppoSelection(i).mlProjID = aFolder.ID
                                                              i = i + 1
                                                              'Next
                                                              ' Add selections to the batch of files to check in
                                                              batchUnlocker.AddSelection(vault1, ppoSelection)
                                                              'End If
                                                  
                                                  
                                                              If Not IsNothing(batchUnlocker) Then
                                                  
                                                  
                                                                  batchUnlocker.CreateTree(Me.Handle.ToInt32(), EdmUnlockBuildTreeFlags.Eubtf_ShowCloseAfterCheckinOption + EdmUnlockBuildTreeFlags.Eubtf_MayUnlock)
                                                  
                                                  
                                                                  batchUnlocker.Comment = "Updates"
                                                                  fileList = batchUnlocker.GetFileList(EdmUnlockFileListFlag.Euflf_GetUnlocked + EdmUnlockFileListFlag.Euflf_GetUndoLocked + EdmUnlockFileListFlag.Euflf_GetUnprocessed)
                                                  
                                                  
                                                                  aPos = fileList.GetHeadPosition()
                                                  
                                                  
                                                                  str = "Getting " & fileCount & " files: "
                                                                  While Not (aPos.IsNull())
                                                                      fileList.GetNext2(aPos, poSel)
                                                                      str = str + vbLf + poSel.mbsPath
                                                                  End While
                                                  
                                                  
                                                                  MsgBox(str)
                                                  
                                                  
                                                                  retVal = batchUnlocker.ShowDlg(Me.Handle.ToInt32())
                                                  
                                                  
                                                                  Dim statuses As Object
                                                                  If (retVal) Then
                                                                      batchUnlocker.UnlockFiles(Me.Handle.ToInt32(), Nothing)
                                                                      statuses = batchUnlocker.GetStatus(EdmUnlockStatusFlag.Eusf_CloseAfterCheckinFlag)
                                                  
                                                  
                                                                      MsgBox("Close Files after Check In selected? " & statuses)
                                                                  End If
                                                  
                                                  
                                                              End If
                                                  
                                                  
                                                          Catch ex As System.Runtime.InteropServices.COMException
                                                              MessageBox.Show("HRESULT = 0x" + ex.ErrorCode.ToString("X") + " " + ex.Message)
                                                          Catch ex As Exception
                                                              MessageBox.Show(ex.Message)
                                                          End Try
                                                          FileList1.Items.Clear()
                                                      End Sub
                                                  
                                                  
                                                  End Class
                                                  
                                                  
                                                    • Re: Using a hook across multiple classes
                                                      Jim Sculley

                                                      The code you posted does not work.  At first glance, the aBatchUnlock subroutine has two problems.  First, the ppoSelection variable is never initialized and is 'Nothing' and the following line will fail:

                                                       

                                                      ppoSelection(i) = New EdmSelItem

                                                       

                                                      Second, the batchUnlocker is also not initialized so this line will fail:

                                                       

                                                      batchUnlocker.AddSelection(vault1, ppoSelection)