AnsweredAssumed Answered

File Save Fails With Warning

Question asked by Eric Drake on May 11, 2020

I'm writing a macro to batch check out several selected files, open and save the files, and check them back in. My checks verify that the selected files have been checked out, but the File Explorer window doesn't show that the files were checked out. The save check indicates that my files weren't saved. A warning with the value of either 2 or 130 is shown. What am I doing wrong?


private void FileSelectBtn_Click(object sender, EventArgs e)
                IEdmPos5 docPos = default(IEdmPos5);
                bool status = false;


                //Create a file vault interface and log into a vault
                IEdmVault5 vault = new EdmVault5();
                IEdmVault8 vault8 = (IEdmVault8)vault;
                vault.LoginAuto("EngineeringSandbox", this.Handle.ToInt32());


                    MessageBox.Show("You are not logged into the EngineeringSandbox vault");


                //display the Open dialog box and allow the user to select multiple files
                OpenFileDialog dialog = new OpenFileDialog();
                dialog.Multiselect = true;
                DialogResult dialogResult;


                dialog.InitialDirectory = vault.RootFolderPath;
                dialogResult = dialog.ShowDialog();
                if (!(dialogResult == DialogResult.OK))
                    MessageBox.Show("You didn't select anything");


                //Convert the selected files to an
                //array of EdmSelItem structs
                int nbrFiles = 0;
                nbrFiles = dialog.FileNames.Count();
                Array.Resize(ref ppoSelection, nbrFiles);


                //prepare a list of selected files for batchCheckOut
                int index = 0;
                foreach (string FileName in dialog.FileNames)
                    IEdmFolder5 parentFolder = null;
                    IEdmFile5 doc = vault.GetFileFromPath(FileName, out parentFolder);
                    docPos = doc.GetFirstFolderPosition();
                    IEdmFolder5 folder = doc.GetNextFolder(docPos);


                    ppoSelection[index] = new EdmSelItem();
                    ppoSelection[index].mlDocID = doc.ID;
                    ppoSelection[index].mlProjID = folder.ID;
                    ModelDoc2 file = this.swApp.OpenDoc6(FileName, (int)swDocumentTypes_e.swDocDRAWING, (int)swOpenDocOptions_e.swOpenDocOptions_Silent, "", ref errors, ref warnings);


                //run batchCheckOut to check out all of the selected files
                batchCheckOut = (IEdmBatchGet)vault8.CreateUtility(EdmUtility.EdmUtil_BatchGet);
                batchCheckOut.AddSelection((EdmVault5)vault, ref ppoSelection);
                batchCheckOut.CreateTree(this.Handle.ToInt32(), (int)EdmGetCmdFlags.Egcf_SkipOpenFileChecks);
                //batchCheckOut.CreateTree(this.Handle.ToInt32(), (int)EdmGetCmdFlags.Egcf_IncludeAutoCacheFiles);

                status = batchCheckOut.ShowDlg(this.Handle.ToInt32());
                if (status)
                    batchCheckOut.GetFiles(this.Handle.ToInt32(), null);
                    Debug.Print("The selected file(s) were checked out");
                } else
                    Debug.Print("The selected files weren't checked out.");


                this.swFrame = (Frame)this.swApp.Frame();
                this.modelWindows = (object[])swFrame.ModelWindows;
                foreach(object obj in modelWindows)
                    swModelWindow = (ModelWindow)obj;
                    //Get the model document in this model window
                    this.file = swModelWindow.ModelDoc;
                    Debug.Print("Opening " + this.file.GetPathName());
                    //Rebuild the document
                    status = this.file.EditRebuild3();
                    if (status)
                        Debug.Print("Rebuild succeeded");
                    } else
                        Debug.Print("Rebuild failed");
                    status = this.file.Save3((int)swSaveAsOptions_e.swSaveAsOptions_Silent, this.errors, this.warnings);
                    if (!status)
                        Debug.Print(this.file.GetPathName() + " was not saved");
                        Debug.Print("Errors: " + this.errors.ToString());
                        Debug.Print("Warnings: " + this.warnings.ToString());
                    this.file = null;
                    //Show the model window
                    //Get and print the model window handle
                    HWnd = swModelWindow.HWnd;


                batchCheckIn = (IEdmBatchUnlock2)vault8.CreateUtility(EdmUtility.EdmUtil_BatchUnlock);
                batchCheckIn.AddSelection((EdmVault5)vault, ref ppoSelection);
                batchCheckIn.Comment = "MOD_DIAM fix";
                //status = batchCheckIn.ShowDlg(this.Handle.ToInt32());
                object statuses = null;
                if (status)
                    batchCheckIn.UnlockFiles(this.Handle.ToInt32(), null);
                    statuses = batchCheckIn.GetStatus((int)EdmUnlockStatusFlag.Eusf_CloseAfterCheckinFlag);


            catch (System.Runtime.InteropServices.COMException ex)
                MessageBox.Show("Function: FileSelectBtn_Click HRESULT = 0x" + ex.ErrorCode.ToString("X") + "\n" + ex.Message + " Link: " + ex.HelpLink + " StackTrace: " + ex.StackTrace);
            catch (Exception ex)