3 Replies Latest reply on Aug 2, 2016 1:07 AM by Brian Bollmann

    GetLocalVersionNo Returns -1

    Brian Bollmann

      Greetings!

      I've copied/written the code below which works fine on a VMware 64-Bit 'full-machine' w/ SolidWorks Explorer installed.

      When I copy the program over to a VMware 64-Bit Virtual Sierver w/ Solidworks Explorer installed, the GetLocalVersionNo command returns a -1 and the code fails.

       

      Can you point me in the right direction?

       

       

                          IEdmVault5 vault1 = new EdmVault5();
                          if (vault1 == null)
                          {
                              vault1 = new EdmVault5();
                          }
                          if (!vault1.IsLoggedIn)
                          {
                              //Log into selected vault as the current user
                              vault1.LoginAuto("SLMP-Sparta", Handle.ToInt32());
                          }
      
      
                          string rootPath1 = vault1.RootFolderPath;
      
      
                          // Get the File
                          IEdmVault7 vault2 = null;
                          if (vault1 == null)
                          {
                              vault1 = new EdmVault5();
                          }
                          vault2 = (IEdmVault7)vault1;
                          if (!vault1.IsLoggedIn)
                          {
                              //Log into selected vault as the current user
                              vault1.LoginAuto("SLMP-Sparta", Handle.ToInt32());
                          }
      
      
                          string rootPath2 = vault2.RootFolderPath;
      
      
      
      
                          // Get a Handle on the File
                          IEdmFile9 aFile = default(IEdmFile9);
                          IEdmFolder5 ppoRetParentFolder;
                      
                          string strPartNumber = readMATRIX["ITEM_CODE"].ToString();
                      
                          // For Debugging
                          strPartNumber = "32061-0348.pdf";
      
      
                          aFile = (IEdmFile9)vault2.GetFileFromPath(rootPath1 
                              + @"\Material Inventory Prints\" + strPartNumber, out ppoRetParentFolder);
      
      
                          
                          // If the file was found, continue
                          if (aFile != null)
                          {
                              string saveFileName = @"C:\Temp\" + aFile.Name;
      
      
                              // Delete the C:\Temp\ version if it exists
                              if (System.IO.File.Exists(saveFileName))
                              {
                                  System.IO.File.Delete(saveFileName);
                              }
      
      
                              // Find the latest version and save it to C:\Temp\
                              IEdmEnumeratorVersion5 verEnum;
                              verEnum = (IEdmEnumeratorVersion5)aFile;
                              
                              int intVersion = 0;
                              intVersion = aFile.GetLocalVersionNo(ppoRetParentFolder.ID);
                              
                              IEdmVersion5 ver;
                              
                              ver = verEnum.GetVersion(intVersion);
                              ver.GetFileCopy(Handle.ToInt32(), saveFileName, 0);
      

       

      Thanks!

        • Re: GetLocalVersionNo Returns -1
          Amen Allah Jlili

          This would help. Check is ppoRetParentFolder is ended with a \ 2015 SOLIDWORKS API Help - GetLocalVersionNo Method (IEdmFile5)

          • Re: GetLocalVersionNo Returns -1
            Lee CS Young

            GetLocalVersionNo() will return -1 if it's not in the local cache. You'll need to do GetFileCopy before the GetLocalVersionNo.

            • Re: GetLocalVersionNo Returns -1
              Brian Bollmann

              The code below seems to be working as desired.  I have to believe there's a more elegant method...

               

                                  // ====================================================================================================
                                  // Locate, extract, and save the drawing file with the same name as the Part Number
                                  // ====================================================================================================
                                  IEdmVault5 vault1 = new EdmVault5();
                                  if (vault1 == null)
                                  {
                                      vault1 = new EdmVault5();
                                  }
                                  if (!vault1.IsLoggedIn)
                                  {
                                      //Log into selected vault as the current user
                                      vault1.LoginAuto("SLMP-Sparta", Handle.ToInt32());
                                  }
              
              
                                  string rootPath1 = vault1.RootFolderPath;
              
              
                                  // Get the File
                                  IEdmVault7 vault2 = null;
                                  if (vault1 == null)
                                  {
                                      vault1 = new EdmVault5();
                                  }
                                  vault2 = (IEdmVault7)vault1;
                                  if (!vault1.IsLoggedIn)
                                  {
                                      //Log into selected vault as the current user
                                      vault1.LoginAuto("SLMP-Sparta", Handle.ToInt32());
                                  }
              
              
                                  string rootPath2 = vault2.RootFolderPath;
              
              
                                  // Get the Part Number from the input SQL
                                  string strPartNumber = readMATRIX["ITEM_CODE"].ToString();
              
              
                                  // Get a handle on the file in PDM (if it exists)
                                  IEdmFile9 aFile = default(IEdmFile9);
                                  IEdmFolder5 ppoRetParentFolder;
                                  aFile = (IEdmFile9)vault2.GetFileFromPath(rootPath1 
                                      + @"\Material Inventory Prints\" + strPartNumber, out ppoRetParentFolder);
              
              
                                  // If the file was found, continue
                                  if (aFile != null)
                                  {
                                      string saveFileName = @"C:\Temp\" + aFile.Name;
              
              
                                      // Delete the C:\Temp\ version if it exists
                                      if (System.IO.File.Exists(saveFileName))
                                      {
                                          System.IO.File.Delete(saveFileName);
                                      }
              
              
                                      // Loop through the version numbers to find the last 
                                      IEdmFile5 file = aFile;
                                      // file = aFile;
                                      // IEdmEnumeratorVersion5 enumVersion;
                                      IEdmEnumeratorVersion5 enumVersion = (IEdmEnumeratorVersion5)file;
                                      IEdmPos5 pos = default(IEdmPos5);
                                      pos = enumVersion.GetFirstVersionPosition();
                                      IEdmVersion5 version = default(IEdmVersion5);
                                      while (!pos.IsNull)
                                      {
                                          version = enumVersion.GetNextVersion(pos);
                                      }
                                      version.GetFileCopy(Handle.ToInt32(), saveFileName, 0);