7 Replies Latest reply on Apr 20, 2017 12:07 PM by Tim Webb

    IEdmBatchUnlock2 Don't check in ref files

    Joe Pickens

      i am using IEdmBatchUnlock2 to check in some files (shown in the code below) The issue i am having is that when i run this code it also try's to check in any of my selected items checked out reference files. The only files I want checked in are the ones i have listed in my EdmSelItem Array.

       

      How do i not select the reference files?        

       

      EdmSelItem[] ppoSelection = BatchSelect(FileNames, Vault);          

      // Add selections to the batch of files to check in          

      IEdmBatchUnlock2 batchUnlocker = (IEdmBatchUnlock2)vault2.CreateUtility(EdmUtility.EdmUtil_BatchUnlock);          

      batchUnlocker.AddSelection((EdmVault5)Vault, ref ppoSelection);          

      if ((batchUnlocker != null))           

      {                              

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

           batchUnlocker.Comment = "Addin Updates";              

           IEdmSelectionList6 fileList = (IEdmSelectionList6)batchUnlocker.GetFileList((int)EdmUnlockFileListFlag.Euflf_GetUnlocked);               

           IEdmPos5 aPos =      fileList.GetHeadPosition();               

           EdmSelectionObject poSel;              

       

           while (!(aPos.IsNull))              

            {                  

                fileList.GetNext2(aPos, out poSel);              

           }              

         

           bool retVal = batchUnlocker.ShowDlg(0);              

           object statuses = null;              

           if ((retVal))              

           {                  

                batchUnlocker.UnlockFiles(0, null);                  

                statuses = batchUnlocker.GetStatus((int)EdmUnlockStatusFlag.Eusf_CloseAfterCheckinFlag);                  

                Interaction.MsgBox("Close Files after Check In selected? " + statuses);              

           }          

      }

        • Re: IEdmBatchUnlock2 Don't check in ref files
          Jim Sculley

          See the IEdmRefItemContainer interface.  You can cast your IEdmBatchUnlock to this and then use SetProperty in conjunction with EdmRefItemProperty.Edmrip_CheckUnlock to clear any files that you don't want to check in.

            • Re: IEdmBatchUnlock2 Don't check in ref files
              Joe Pickens

              The program was working beautifully and i was testing it under different scenarios and now it quit working.

               

              Here is some screen shots. so right now I have the program set so the it prompts me the check in file dialog. The background of the program is it is a solidworks addin  and from events in solidworks it completes PDM tasks automatically namely adding info to engineering change order (ECO) forms. what i am running here is i am saving a new part into the vault. my program has added the new document to the ECO form as a reference and is checking in the ECO form to update its references. As you can see im only trying to check in the form and none of the solidworks components. originally yesterday it was funtioning the way i wanted it to then I started getting the "file that is exclusively opened by another application" error. Any help on this is very much appreciated.

               

               

                    

                        public static void CheckInFiles(string[] FileNames, EdmVault5 Vault = null)

                      {

                          #region Log into Vault

                          if (Vault == null || !Vault.IsLoggedIn)

                          {

                              Vault = VaultAPI.LogIntoVault();

                          }

               

                          IEdmVault7 vault2 = null;

                          vault2 = (IEdmVault7)Vault;

               

                          EdmSelItem[] ppoSelection = BatchSelect(FileNames, Vault);

                          IEdmBatchUnlock2 batchUnlocker = (IEdmBatchUnlock2)vault2.CreateUtility(EdmUtility.EdmUtil_BatchUnlock);

                          batchUnlocker.AddSelection((EdmVault5)Vault, ref ppoSelection);

               

                          if ((batchUnlocker != null))

                          {

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

               

                              batchUnlocker.Comment = "Addin Updates";

                              IEdmSelectionList6 fileList = (IEdmSelectionList6)batchUnlocker.GetFileList((int)EdmUnlockFileListFlag.Euflf_GetUnlocked);

                              IEdmPos5 aPos = fileList.GetHeadPosition();

                              EdmSelectionObject poSel;

                              while (!(aPos.IsNull))

                              {

                                  fileList.GetNext2(aPos, out poSel);

                              }

                              IEdmRefItemContainer container = null;

                              container = (IEdmRefItemContainer)batchUnlocker;

                              object[] items = null;

                              container.GetItems(EdmRefItemType.Edmrit_All, out items);

                              int j = 0;

                              foreach (IEdmRefItem Item in items)

                              {

                                  object value = null;

                                  bool boolstat = Item.GetProperty(EdmRefItemProperty.Edmrip_FileName, out value);

                                  string FileName = (string)value;

                                  foreach (string filename in FileNames)

                                  {

                                      if (FileName == Path.GetFileName(filename))

                                      {

                                          value = null;

                                          Item.SetProperty(EdmRefItemProperty.Edmrip_CheckLock, value);

                                      }

                                      else

                                      {

                                          value = null;

                                          Item.SetProperty(EdmRefItemProperty.Edmrip_CheckUnlock, value);

                                      }

                                  }

                              }

                          bool retVal = batchUnlocker.ShowDlg(0);

                          object statuses = null;

                          batchUnlocker.UnlockFiles(0, null);

                          statuses = batchUnlocker.GetStatus((int)EdmUnlockStatusFlag.Eusf_CloseAfterCheckinFlag);

                          }

                      }

                • Re: IEdmBatchUnlock2 Don't check in ref files
                  Jim Sculley

                  First, use Process Explorer to determine what process is holding on to the xlsm file and then go from there.  You may have a rogue Excel process that wasn't terminated properly.  Use the 'Find....File Handle or DLL' menu item in Process Explorer, enter the file name and click the Search button.

                    • Re: IEdmBatchUnlock2 Don't check in ref files
                      Joe Pickens

                      I downloaded the Process Explorer and now the code is working again with nothing changed. But i still added i loop to force release all the users solidworks files before checking in the ECO form and then running another loop to do the ReloadOrReplace to reload the solidworks files.

                       

                      im using these two functions in my loops

                       

                      iReleases[i] = SWModel.ForceReleaseLocks();

                       

                      and

                       

                      iReleases[i] = SWModel.ReloadOrReplace(false, SWModel.GetPathName(), false);

                        • Re: IEdmBatchUnlock2 Don't check in ref files
                          Tim Webb

                          Glad it's working but if you don't know what fixed it, sounds like you'll be visiting this again BUT if you just added swDoc.ForceReleaseLocks, that should do the trick. It's the call to use to release the locks on the SW file while it's open but there are some caveats to using that.

                           

                          Yes, you answered my question. You aren't changing the file data card so that wouldn't cause your error.

                           

                          Tim CEPA

                          Believe in The Q!

                      • Re: IEdmBatchUnlock2 Don't check in ref files
                        Tim Webb

                        Joe,

                        That "exclusively opened" message is consistent with updating a PDM data card and not releasing the file. With regard to your statement:

                         

                        "...adding info to engineering change order (EVO) forms..."

                         

                        Are you updating the excel or any other file's data card?

                         

                        If so, are you using Closefile() method on your variable enumerator?

                          • Re: IEdmBatchUnlock2 Don't check in ref files
                            Joe Pickens

                            I am attaching the SW file as a reference to the ECO file this is done while the user is working on the SW file and generally has the SW file checked out of pdm while this process is being completed. So the user is working on the SW file and the program is taking ques from actions from the user working to programmaticly Update the ECO contents.

                             

                            I hope that answers your question on what i am doing