Exemple #1
0
        /// <summary>
        /// 【6】pdm库内复制文件,返回pdm中文件全路径(包含文件名)
        /// </summary>
        /// <param name="oldFile">旧文件位置</param>
        /// <param name="newFolder">新文件夹位置</param>
        public static string CopyFile(string oldFile, string newFolder)
        {
            IEdmVault5 vault1 = new EdmVault5();

            vault1.Login(LogName, PWD, VaultName);
            IEdmVault7 vault2 = null;

            vault2 = (IEdmVault7)vault1;
            IEdmFile10  file = default(IEdmFile10);
            IEdmFolder5 ppoRetParentFolder;

            file = (IEdmFile11)vault2.GetFileFromPath(oldFile, out ppoRetParentFolder);
            IEdmFolder5 destFolder1 = default(IEdmFolder5);

            destFolder1 = vault2.GetFolderFromPath(newFolder);//新文件夹位置
            IEdmFolder8 destFolder = (IEdmFolder8)destFolder1;
            int         FileID     = 0;
            int         copyFileStatus;

            FileID = destFolder.CopyFile2(file.ID, ppoRetParentFolder.ID, new Control().Handle.ToInt32(), out copyFileStatus, "", (int)EdmCopyFlag.EdmCpy_Simple);
            return(destFolder1.LocalPath + "\\" + file.Name.Substring(file.Name.LastIndexOf('\\') + 1));
        }
Exemple #2
0
        private void btnOK_Click(object sender, EventArgs e)
        {
            // Make sure the user has selected at least one file
            if (!GetSelectedFiles())
            {
                MessageBox.Show("You must select a file");
                return;
            }
            // Make sure the user has entered and ECO Number
            if (tbECONumber.Text == "")
            {
                MessageBox.Show("You must enter an ECO Number");
                tbECONumber.Focus();
                return;
            }

            Inventor.TranslationContext transContext;
            transContext      = invApp.TransientObjects.CreateTranslationContext();
            transContext.Type = Inventor.IOMechanismEnum.kFileBrowseIOMechanism;
            Inventor.NameValueMap oOptions;
            oOptions = invApp.TransientObjects.CreateNameValueMap();
            oOptions.set_Value("Sheet_Range", Inventor.PrintRangeEnum.kPrintAllSheets);
            Inventor.DataMedium oData;
            oData    = invApp.TransientObjects.CreateDataMedium();
            pdfAddin = (Inventor.TranslatorAddIn)invApp.ApplicationAddIns.get_ItemById("{0AC6FD96-2F4D-42CE-8BE0-8AEA580399E4}");
            Inventor.DrawingDocument drawingDoc;

            IEdmBatchUpdate2 Update = default(IEdmBatchUpdate2);

            Update = (IEdmBatchUpdate2)vault7.CreateUtility(EdmUtility.EdmUtil_BatchUpdate);
            IEdmVariableMgr5 varMgr = default(IEdmVariableMgr5);
            IEdmFile5        File;
            IEdmFolder8      Folder = (IEdmFolder8)vault7.GetFolderFromPath(PDFfilePath);

            EdmAddFileInfo[] Files = new EdmAddFileInfo[1];
            int addFileStatus;
            int ECONumberID = 0;
            int RevisionID  = 0;

            EdmBatchError2[] Errors = null;
            int errorSize           = 0;

            foreach (ReferenceDoc rd in referenceDocs)
            {
                foreach (string sd in selectedDrawings)
                {
                    if (rd.DrawingName == sd)
                    {
                        rd.IsSelected = true;
                    }
                }

                if (rd.IsSelected)
                {
                    drawingDoc = (Inventor.DrawingDocument)invApp.Documents.Open(rd.DrawingPath, true);
                    if (!System.IO.File.Exists(PDFfilePath + rd.PDFName))
                    {
                        oData.FileName = PDFfilePath + rd.PDFName;
                        pdfAddin.SaveCopyAs(drawingDoc, transContext, oOptions, oData);
                        Files[0].mbsPath         = PDFfilePath + rd.PDFName;
                        Files[0].mlEdmAddFlags   = (int)EdmAddFlag.EdmAdd_Simple;
                        Files[0].mlFileID        = 0;
                        Files[0].mlSrcDocumentID = 0;
                        Files[0].mlSrcProjectID  = 0;
                        Files[0].mbsNewName      = "";
                        Folder.AddFile2(this.Handle.ToInt32(), Files[0].mbsPath, out addFileStatus, "", Files[0].mlEdmAddFlags);
                        File        = Folder.GetFile(rd.PDFName);
                        varMgr      = (IEdmVariableMgr5)File.Vault;
                        ECONumberID = varMgr.GetVariable("ECO Number").ID;
                        RevisionID  = varMgr.GetVariable("Revision").ID;
                        Update.SetVar(File.ID, ECONumberID, tbECONumber.Text, "", (int)EdmBatchFlags.EdmBatch_Nothing);
                        Update.SetVar(File.ID, RevisionID, "--" + rd.Revision, "", (int)EdmBatchFlags.EdmBatch_Nothing);
                        errorSize = Update.CommitUpdate(out Errors, null);
                        File.UnlockFile(this.Handle.ToInt32(), "");
                        drawingDoc.Close();
                    }
                    else
                    {
                        MessageBox.Show("File: " + rd.PDFName + " is already checked into EPDM", "File Exist", MessageBoxButtons.OK, MessageBoxIcon.Information);
                    }
                }
            }

            referenceDocs.Clear();
            selectedDrawings.Clear();
            drawingListView.Clear();
            tbECONumber.Clear();
            btnOK.Enabled = false;
            invApp.Quit();
        }