2 Replies Latest reply on Apr 16, 2010 1:06 PM by Jim Sculley

    API CommitUpdate fails

    Jim Sculley

      I  am attempting to pop up a user form in response to a state transition  so that the user can enter some data that will be used to set variables  on the file.  I have added a hook for EdmCmdType.EdmCmd_PreState and in OnCmd the code looks like this:

       

      EdmCmdData[] cmdData = (EdmCmdData[])ppoData;
      int sourceStateID = cmdData[0].mlLongData1;
      IEdmState6 sourceState = (IEdmState6)vault.GetObject(EdmObjectType.EdmObject_State, sourceStateID);
      if (sourceState.Name.Equals("Acquiring Oracle Number"))
          {

              int fileID = cmdData[0].mlObjectID1;
              OracleData data = new OracleData();
              OracleNumberEntryForm form = new OracleNumberEntryForm(data);
              DialogResult result = form.ShowDialog();
              object obj = vault.CreateUtility(EdmUtility.EdmUtil_BatchUpdate);
              IEdmBatchUpdate2 updateUtility = (IEdmBatchUpdate2)obj;
              IEdmVariableMgr6 varMgr = (IEdmVariableMgr6)vault;
              object oraNumVarName = "ORACLE_ITEM_NUMBER";
              object oraDescVarName = "PART_DESCRIPTION";
              IEdmVariable5 oraNumVar = varMgr.GetVariable(ref oraNumVarName);
              IEdmVariable5 oraDescVar = varMgr.GetVariable(ref oraDescVarName);
              object oraNumVal = data.Number;
              object oraDescVal = data.Description;
              updateUtility.SetVar(fileID, oraNumVar.ID, ref oraNumVal, "", (int)EdmBatchFlags.EdmBatch_Nothing);
              updateUtility.SetVar(fileID, oraDescVar.ID, ref oraDescVal, "", (int)EdmBatchFlags.EdmBatch_Nothing);
              EdmBatchError2[] errors = new EdmBatchError2[10];
              Array errArray = (Array)errors;
              int errCount = updateUtility.CommitUpdate(out errArray, null);
              if (errCount != 0)
              {
                  handleCommitErrors(errArray);
              }
      }


      If I select a checked in file and move it through the transition, the OnCmd is called as expected, the form pops up and all is well until the CommitUpdate method is called.  The call fails with one error being returned. My handleCommitErrors method shows the following details:

       

      access-error.png

       

      Using ProcessMonitor I don't see any other process other than SolidWorks trying to access the file:

      ===================================================

      61348    10:25:20.4206792 AM    sldworks.exe    5676    CreateFile                                C:\_EPDM\Part1.SLDPRT    SUCCESS   
      61349    10:25:20.4207313 AM    sldworks.exe    5676    ReadFile                                  C:\_EPDM\Part1.SLDPRT    SUCCESS   
      61350    10:25:20.4207621 AM    sldworks.exe    5676    CloseFile                           C:\_EPDM\Part1.SLDPRT    SUCCESS   
      61351    10:25:20.4208332 AM    sldworks.exe    5676    CreateFile                           C:\_EPDM\Part1.SLDPRT    SUCCESS   
      61352    10:25:20.4209103 AM    sldworks.exe    5676    QueryStandardInformationFile    C:\_EPDM\Part1.SLDPRT    SUCCESS   
      61353    10:25:20.4209281 AM    sldworks.exe    5676    QueryBasicInformationFile    C:\_EPDM\Part1.SLDPRT    SUCCESS   
      61354    10:25:20.4209485 AM    sldworks.exe    5676    LockFile            C:\_EPDM\Part1.SLDPRT    SUCCESS   
      61355    10:25:20.4209704 AM    sldworks.exe    5676    QueryStandardInformationFile    C:\_EPDM\Part1.SLDPRT    SUCCESS   
      61356    10:25:20.4209856 AM    sldworks.exe    5676    QueryBasicInformationFile    C:\_EPDM\Part1.SLDPRT    SUCCESS   
      61357    10:25:20.4210029 AM    sldworks.exe    5676    ReadFile            C:\_EPDM\Part1.SLDPRT    SUCCESS   
      61358    10:25:20.4210323 AM    sldworks.exe    5676    ReadFile            C:\_EPDM\Part1.SLDPRT    SUCCESS   
      61360    10:25:20.4210731 AM    sldworks.exe    5676    ReadFile            C:\_EPDM\Part1.SLDPRT    SUCCESS   
      61362    10:25:20.4211096 AM    sldworks.exe    5676    ReadFile            C:\_EPDM\Part1.SLDPRT    SUCCESS   
      61371    10:25:20.4218840 AM    sldworks.exe    5676    QueryStandardInformationFile    C:\_EPDM\Part1.SLDPRT    SUCCESS   
      61372    10:25:20.4219014 AM    sldworks.exe    5676    QueryBasicInformationFile    C:\_EPDM\Part1.SLDPRT    SUCCESS   
      61373    10:25:20.4219399 AM    sldworks.exe    5676    UnlockFileSingle        C:\_EPDM\Part1.SLDPRT    SUCCESS   
      61376    10:25:20.4220413 AM    sldworks.exe    5676    CloseFile            C:\_EPDM\Part1.SLDPRT    SUCCESS   
      128305    10:25:58.5716653 AM    sldworks.exe    5676    QueryDirectory            C:\_EPDM\Part1.SLDPRT    SUCCESS   
      129047    10:25:58.8298369 AM    sldworks.exe    5676    QueryOpen            C:\_EPDM\Part1.SLDPRT    FAST IO
      129048    10:25:58.8298872 AM    sldworks.exe    5676    CreateFile            C:\_EPDM\Part1.SLDPRT    SUCCESS   
      129049    10:25:58.8299147 AM    sldworks.exe    5676    QueryBasicInformationFile    C:\_EPDM\Part1.SLDPRT    SUCCESS   
      129050    10:25:58.8299280 AM    sldworks.exe    5676    CloseFile            C:\_EPDM\Part1.SLDPRT    SUCCESS   
      129052    10:25:58.8300246 AM    sldworks.exe    5676    CreateFile            C:\_EPDM\Part1.SLDPRT    SUCCESS   
      129053    10:25:58.8300603 AM    sldworks.exe    5676    ReadFile            C:\_EPDM\Part1.SLDPRT    SUCCESS   
      129054    10:25:58.8300845 AM    sldworks.exe    5676    CloseFile            C:\_EPDM\Part1.SLDPRT    SUCCESS   
      129055    10:25:58.8301479 AM    sldworks.exe    5676    CreateFile            C:\_EPDM\Part1.SLDPRT    ACCESS DENIED

      ==============================

       

      SW successfully opens, closes, locks and unlocks the file prior to the CommitUpdate command.  At that point, the ACCESS DENIED occurs.

       

      I added a bit of code to check the LockedByUser property of the file and it reports that the file is locked by my user.

       

      Do I need to programmatically check out the file in order to call SetVar and CommitUpdate?

       

      Jim S.