Пример #1
0
        public void BrowseButton_Click(System.Object sender, System.EventArgs e)
        {
            try
            {
                //Set the initial directory in the Select a file dialog
                OpenFileDialog1.InitialDirectory = vault1.RootFolderPath;
                //Show the Select a file dialog
                System.Windows.Forms.DialogResult DialogResult;
                DialogResult = OpenFileDialog1.ShowDialog();

                if (!(DialogResult == System.Windows.Forms.DialogResult.OK))
                {
                    // Do nothing
                }
                else
                {
                    // Browse for a file whose serial number to set
                    // File's data card must have a Part Number associated
                    // with a serial number generator and must be checked out
                    string fileName = OpenFileDialog1.FileName;
                    FileListBox.Items.Add(fileName);
                    IEdmFolder5 retFolder = default(IEdmFolder5);
                    aFile = vault1.GetFileFromPath(fileName, out retFolder);
                }
            }
            catch (System.Runtime.InteropServices.COMException ex)
            {
                MessageBox.Show("HRESULT = 0x" + ex.ErrorCode.ToString("X") + " " + ex.Message);
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
        }
Пример #2
0
        public bool GetAsmIndoFromFile(IEdmVault5 poVault, string filePath, SldAsm asmPrd)
        {
            IEdmFolder5             opParentFolder;
            IEdmFile5               poFile  = poVault.GetFileFromPath(filePath, out opParentFolder);
            IEdmEnumeratorVariable5 enumVar = poFile.GetEnumeratorVariable();

            if (filePath == "")
            {
                return(false);
            }
            asmPrd.path = filePath;
            //
            object tmpVar;

            if (enumVar.GetVar("代号", "@", out tmpVar))
            {
                asmPrd.number = tmpVar.ToString();
                asmPrd.ztdm   = asmPrd.number.Substring(0, asmPrd.number.IndexOf("."));
                asmPrd.zjdm   = asmPrd.number.Substring(asmPrd.number.IndexOf(".") + 1);
            }
            if (enumVar.GetVar("名称", "@", out tmpVar))
            {
                asmPrd.name = tmpVar.ToString();
            }
            if (enumVar.GetVar("设计", "@", out tmpVar))
            {
                asmPrd.bzr = tmpVar.ToString();
            }
            if (enumVar.GetVar("设计日期", "@", out tmpVar))
            {
                asmPrd.bzsj = ((DateTime)tmpVar).ToString("%y/%m/%d");
            }
            if (enumVar.GetVar("批准", "@", out tmpVar))
            {
                asmPrd.pzr = tmpVar.ToString();
            }
            if (enumVar.GetVar("批准日期", "@", out tmpVar))
            {
                asmPrd.pzsj = ((DateTime)tmpVar).ToString("%y/%m/%d");
            }
            if (enumVar.GetVar("阶段标记", "@", out tmpVar))
            {
                asmPrd.jdbj = tmpVar.ToString();
            }

            if (enumVar.GetVar("设备型号", "@", out tmpVar))
            {
                asmPrd.sbxh = tmpVar.ToString();
            }
            if (enumVar.GetVar("Project Name", "@", out tmpVar))
            {
                asmPrd.projName = tmpVar.ToString();
            }
            return(true);
        }
Пример #3
0
 private void GetCardList()
 {
     notBusy = false;
     try {
         vault = new EdmVault5();
         vault.LoginAuto(selectedVault, 0);
         if (vault.IsLoggedIn)
         {
             IEdmFile5        file         = vault.GetFileFromPath(selectedFile, out IEdmFolder5 folder);
             IEdmCard5        card         = folder.GetCard(Path.GetExtension(selectedFile).Substring(1));
             Object           variableName = selectedVariable;
             IEdmCardControl7 cardControl  = (IEdmCardControl7)card.GetControl(card.GetControlID(ref variableName));
             if (cardControl.GetControlVariableList(file.ID, out String[] cardListStrings))
Пример #4
0
        public SldBsp GetSldPrdInfoFromFile(IEdmVault5 poVault, string filePath)
        {
            SldBsp      bspPrt = null;
            IEdmFolder5 opParentFolder;
            //bspPrt = new SldBuy();
            IEdmFile5 poFile = poVault.GetFileFromPath(filePath, out opParentFolder);

            if (poFile == null)
            {
                bspPrt      = new SldPrt();
                bspPrt.type = 1;
                return(bspPrt);
            }
            IEdmEnumeratorVariable5 enumVar = poFile.GetEnumeratorVariable();

            if (enumVar == null)
            {
                return(null);
            }

            object tmpVar;
            string partType = "";

            if (enumVar.GetVar("Part Type", "@", out tmpVar))
            {
                partType = tmpVar.ToString();
            }
            if (partType == "自制件")
            {
                bspPrt      = new SldPrt();
                bspPrt.type = 1;
                SldPrt prt = (SldPrt)bspPrt;
                if (enumVar.GetVar("工艺路线", "@", out tmpVar))
                {
                    prt.route = tmpVar.ToString();
                }
            }
            else if (partType == "标准件")
            {
                bspPrt      = new SldStd();
                bspPrt.type = 2;
            }
            else
            {
                bspPrt      = new SldBuy();
                bspPrt.type = 3;
            }
            bspPrt.path = filePath;
            return(bspPrt);
        }
Пример #5
0
        public void SelectFiles_Click(System.Object sender, System.EventArgs e)
        {
            try
            {
                File1List.Items.Clear();

                IEdmVault7 vault2 = null;
                if (vault1 == null)
                {
                    vault1 = new EdmVault5();
                }
                vault2 = (IEdmVault7)vault1;

                if (!vault1.IsLoggedIn)
                {
                    vault1.LoginAuto(VaultsComboBox.Text, this.Handle.ToInt32());
                }

                //Set the initial directory in the Select File dialog
                OpenFileDialog1.InitialDirectory = vault1.RootFolderPath;

                //Show the Select File dialog
                System.Windows.Forms.DialogResult DialogResult;
                DialogResult = OpenFileDialog1.ShowDialog();

                if (!(DialogResult == System.Windows.Forms.DialogResult.OK))
                {
                    // do nothing
                }
                else
                {
                    IEdmFolder5 ppoRetParentFolder;
                    foreach (string FileName in OpenFileDialog1.FileNames)
                    {
                        File1List.Items.Add(FileName);
                        aFile = (IEdmFile7)vault1.GetFileFromPath(FileName, out ppoRetParentFolder);
                    }
                }
            }
            catch (System.Runtime.InteropServices.COMException ex)
            {
                MessageBox.Show("HRESULT = 0x" + ex.ErrorCode.ToString("X") + " " + ex.Message);
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
        }
Пример #6
0
        public void GetReferencedFiles(IEdmReference10 Reference, string FilePath, int Level, string ProjectName, ref Dictionary <string, string> RefFilesDictionary)
        {
            try
            {
                bool Top = false;
                if (Reference == null)
                {
                    //This is the first time this function is called for this
                    //reference tree; i.e., this is the root
                    Top = true;
                    //Add the top-level file path to the dictionary
                    RefFilesDictionary.Add(FilePath, Level.ToString());
                    IEdmFile5   File         = null;
                    IEdmFolder5 ParentFolder = null;
                    File = vault1.GetFileFromPath(FilePath, out ParentFolder);
                    //Get the reference tree for this file
                    Reference = (IEdmReference10)File.GetReferenceTree(ParentFolder.ID);
                    GetReferencedFiles(Reference, "", Level + 1, ProjectName, ref RefFilesDictionary);
                }
                else
                {
                    //Execute this code when this function is called recursively;
                    //i.e., this is not the top-level IEdmReference in the tree

                    //Recursively traverse the references
                    IEdmPos5        pos        = default(IEdmPos5);
                    IEdmReference10 Reference2 = (IEdmReference10)Reference;
                    pos = Reference2.GetFirstChildPosition3(ProjectName, Top, true, (int)EdmRefFlags.EdmRef_File, "", 0);
                    IEdmReference10 @ref = default(IEdmReference10);
                    while ((!pos.IsNull))
                    {
                        @ref = (IEdmReference10)Reference.GetNextChild(pos);
                        RefFilesDictionary.Add(@ref.FoundPath, Level.ToString());
                        GetReferencedFiles(@ref, "", Level + 1, ProjectName, ref RefFilesDictionary);
                    }
                }
            }
            catch (System.Runtime.InteropServices.COMException ex)
            {
                MessageBox.Show("HRESULT = 0x" + ex.ErrorCode.ToString("X") + " " + ex.Message);
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
        }
Пример #7
0
        private static bool GetFileFromPath(IEdmVault5 vault, string filePath, out IEdmFile5 file, out IEdmFolder5 parentFolder)
        {
            file         = null;
            parentFolder = null;

            if (vault == null)
            {
                return(false);
            }

            try
            {
                file = vault.GetFileFromPath(filePath, out parentFolder);
                return(file != null && parentFolder != null);
            }
            catch (Exception ex)
            {
                return(false);
            }
        }
Пример #8
0
        /// <summary>
        /// 【10】获取文件版本
        /// </summary>
        /// <param name="path">文件在PDM中路径</param>
        /// <returns></returns>
        public static int GetDrawVersion(string path)
        {
            if (vault == null)
            {
                vault = new EdmVault5();
            }
            if (!vault.IsLoggedIn)
            {
                vault.LoginAuto(VaultName, new Control().Handle.ToInt32());
            }
            IEdmFolder5 retFolder = default(IEdmFolder5);
            //aFile = vault1.GetFileFromPath(FileName, out retFolder);
            IEdmFile5 file = null;

            file = vault.GetFileFromPath(path, out retFolder);
            IEdmEnumeratorVersion5 enumVersion;

            enumVersion = (IEdmEnumeratorVersion5)file;
            return(enumVersion.VersionCount);
        }
Пример #9
0
        ///// <summary>
        ///// Download file in to local directory.
        ///// </summary>
        ///// <param name="dataModel"></param>
        //public string GetPathAndDownLoadFile(DataModel dataModel, string directoryPath)
        //{
        //    this.PDMInitialize();
        //    IEdmFolder5 srcFolder = null;
        //    IEdmFile5 file = edmVault5.GetFileFromPath(dataModel.Path,out srcFolder);
        //    IEdmVault7 vault2 = (IEdmVault7)this.edmVault5;
        //    IEdmFolder5 edmFolder5 = vault2.GetFolderFromPath(directoryPath);
        //    IEdmFolder8 edmFolder8 = (IEdmFolder8)edmFolder5;

        //    int copyFileStatus;
        //    edmFolder8.CopyFile2(file.ID, srcFolder.ID, 0, out copyFileStatus, "", (int)EdmCopyFlag.EdmCpy_Simple);

        //    //var batchGetter = (IEdmBatchGet)(edmVault5 as IEdmVault7).CreateUtility(EdmUtility.EdmUtil_BatchGet);
        //    // batchGetter.AddSelectionEx((EdmVault5)edmVault5, dataModel.Id, dataModel.FolderId, 0);
        //    // if ((batchGetter != null))
        //    // {
        //    //     batchGetter.CreateTree(0, (int)EdmGetCmdFlags.Egcf_SkipUnlockedWritable);
        //    //     batchGetter.GetFiles(0, null);
        //    // }
        //    return null;
        //}

        /// <summary>
        /// Reference in to the components of assembly.
        /// </summary>
        /// <param name="file"></param>
        /// <param name="indent"></param>
        /// <param name="projName"></param>
        /// <returns></returns>
        private string AddReferences(IEdmReference5 file, long indent, ref string projName)
        {
            string filename = null;

            filename = filename + file.Name;

            const bool isTop = false;

            IEdmVault7 vault2 = null;

            if (edmVault5 == null)
            {
                edmVault5 = new EdmVault5();
            }
            vault2 = (IEdmVault7)edmVault5;

            if (!edmVault5.IsLoggedIn)
            {
                edmVault5.LoginAuto(vaultname, 0);
            }

            IEdmPos5 pos = file.GetFirstChildPosition(projName, isTop, true, 0);

            IEdmFolder5 oFolder = null;


            while (!(pos.IsNull))
            {
                IEdmReference5 @ref  = file.GetNextChild(pos);
                var            oFile = (IEdmFile5)edmVault5.GetFileFromPath(@ref.FoundPath, out oFolder);

                filename = filename + AddReferences(@ref, indent, ref projName);

                //MessageBox.Show(filename);
                // Последняя копия перечня в сборке
                oFile.GetFileCopy(0, "", @ref.FoundPath);
            }
            return(filename);
        }
Пример #10
0
        private void SearchFiles(IEdmVault5 vault, object Val1)
        {
            try

            {
                IEdmSearch5 search = null;
                IEdmFolder5 folder = null;

                folder = vault.GetFolderFromPath(@"C:\CDI Controlled Documents\drawings\part drawings- controlled");

                search               = vault.CreateSearch();
                search.FileName      = "%.%d%w%";
                search.StartFolderID = folder.ID;

                object Var1  = "Part Numbers";
                object State = "Approved for Production";


                search.AddVariable(Var1, Val1);

                search.set_State(State);
                search.FindHistoricStates = false;
                search.Recursive          = true;

                String message = string.Empty;



                List <IEdmSearchResult5> results = new List <IEdmSearchResult5>();

                IEdmSearchResult5 result = search.GetFirstResult();

                while (result != null)

                {
                    results.Add(result);
                    result = search.GetNextResult();
                }
                results = results.Distinct(new SearchResultComparer()).ToList();
                if (results.Count < 1)
                {
                    search.Clear();
                    search.FileName      = Val1 + ".%d%w%";
                    search.StartFolderID = folder.ID;
                    State = "Approved for Production";
                    search.set_State(State);
                    search.FindHistoricStates = false;
                    search.Recursive          = true;

                    result = search.GetFirstResult();
                    while (result != null)

                    {
                        results.Add(result);
                        result = search.GetNextResult();
                    }
                    results = results.Distinct(new SearchResultComparer()).ToList();
                }
                foreach (IEdmSearchResult5 item in results)
                {
                    //get latest version
                    IEdmFile5   file      = null;
                    IEdmFolder5 retFolder = default(IEdmFolder5);
                    file = vault.GetFileFromPath(item.Path, out retFolder);
                    file.GetFileCopy(0);
                    //System.Diagnostics.Process.Start(item.Path, @"C:\Program Files\SOLIDWORKS Corp\eDrawings\eDrawings.exe");
                    //OpenEdwg(item.Path);
                    OpenSaveSldrwPdf(item.Path);



                    message = message + "Filename: " + item.Name + ", Rev: " + file.CurrentRevision + "; \n";
                }



                MessageBox.Show(message);
            }



            catch (Exception ex)

            {
                MessageBox.Show(ex.Message);
            }
        }
Пример #11
0
    public int Add(string fileName, string fFilter, string vName)
    {
        int        exitCode = 0;
        IEdmVault5 vault    = (IEdmVault5)Activator.CreateInstance(System.Type.GetTypeFromProgID("Conisiolib.EdmVault"));

        LogIn(ref exitCode, ref vault, vName);
        if (exitCode != 0)
        {
            return(exitCode);
        }
        string refFileName = string.Empty;

        GetFileName(ref refFileName, vault.RootFolderPath, fFilter, 0);
        if (refFileName == string.Empty)
        {
            exitCode = 11;
            return(exitCode);
        }
        if (refFileName.ToLower() == fileName.ToLower())
        {
            exitCode = 12;
            return(exitCode);
        }
        IEdmEnumeratorCustomReference6 addCustRefs = default(IEdmEnumeratorCustomReference6);
        IEdmFolder5 rFolder = default(IEdmFolder5);
        IEdmFile5   rFile   = default(IEdmFile5);
        IEdmFolder5 zFolder = default(IEdmFolder5);
        IEdmFile5   file    = default(IEdmFile5);

        try {
            rFile = vault.GetFileFromPath(refFileName, out rFolder);
            file  = vault.GetFileFromPath(fileName, out zFolder);
            if (rFile == null | file == null)
            {
                exitCode = 13;
                return(exitCode);
            }
            if (!file.IsLocked)
            {
                exitCode = 14;
                return(exitCode);
            }
            addCustRefs = (IEdmEnumeratorCustomReference6)file;
            try {
                addCustRefs.AddReference2(rFile.ID, rFolder.ID, 1);
            } catch (COMException e) {
                exitCode = 15;
                return(exitCode);
            }
        } catch (COMException e) {
            exitCode = 16;
            return(exitCode);
        } finally {
            if (rFolder != null)
            {
                Marshal.FinalReleaseComObject(rFolder);
                rFolder = null;
            }
            if (rFile != null)
            {
                Marshal.FinalReleaseComObject(rFile);
                rFile = null;
            }
            if (zFolder != null)
            {
                Marshal.FinalReleaseComObject(zFolder);
                zFolder = null;
            }
            if (file != null)
            {
                Marshal.FinalReleaseComObject(file);
                file = null;
            }
            if (addCustRefs != null)
            {
                Marshal.FinalReleaseComObject(addCustRefs);
                addCustRefs = null;
            }
            if (vault != null)
            {
                Marshal.FinalReleaseComObject(vault);
                vault = null;
            }
        }
        return(exitCode);
    }
Пример #12
0
        public SldBsp GetSldPrdInfoFromFile(IEdmVault5 poVault, string filePath)
        {
            IEdmFolder5 opParentFolder;
            //bspPrt = new SldBuy();
            IEdmFile5 poFile = poVault.GetFileFromPath(filePath, out opParentFolder);

            if (poFile == null)
            {
                return(null);
            }
            IEdmEnumeratorVariable5 enumVar = poFile.GetEnumeratorVariable();

            if (enumVar == null)
            {
                return(null);
            }
            IEdmVariableMgr5 varMgr = (IEdmVariableMgr5)poVault;

            if (varMgr == null)
            {
                return(null);
            }

            object tmpVar;
            string partType = "";

            if (varMgr.GetVariable("Part Type") != null && enumVar.GetVar("Part Type", "@", out tmpVar) && tmpVar != null)
            {
                partType = tmpVar.ToString();
            }
            if (partType == "自制件")
            {
                SldPrt prt = new SldPrt();
                prt.type = 1;
                object route = null;
                if (varMgr.GetVariable("工艺路线") != null)
                {
                    if (enumVar.GetVar("工艺路线", "@", out route) && route != null)
                    {
                        prt.route = route.ToString();
                    }
                }

                return(prt);
            }
            else if (partType == "标准件")
            {
                SldStd std = new SldStd();
                std.type = 2;
                return(std);
            }
            else if (partType == "外购件")
            {
                SldBuy buy = new SldBuy();
                buy.type = 3;
                return(buy);
            }
            else
            {
                SldBsp buy = new SldBsp();
                buy.type = 4;
                return(buy);
            }
        }
Пример #13
0
        public SldAsm GetAsmIndoFromFile(IEdmVault5 poVault, string filePath)
        {
            IEdmFolder5 opParentFolder;
            IEdmFile5   poFile = poVault.GetFileFromPath(filePath, out opParentFolder);

            if (poFile == null)
            {
                return(null);
            }
            IEdmVariableMgr5 varMgr = (IEdmVariableMgr5)poVault;

            if (varMgr == null)
            {
                return(null);
            }

            IEdmEnumeratorVariable5 enumVar = poFile.GetEnumeratorVariable();

            if (enumVar == null)
            {
                return(null);
            }
            if (filePath == "")
            {
                return(null);
            }
            EdmStrLst5 cfgList = poFile.GetConfigurations();

            SldAsm asmPrd = new SldAsm();

            asmPrd.path  = filePath;
            asmPrd.amout = 1;


            if (varMgr.GetVariable("代号") != null)
            {
                object   tmpVar  = null;
                IEdmPos5 pos     = cfgList.GetHeadPosition();
                string   cfgName = null;
                while (!pos.IsNull)
                {
                    cfgName = cfgList.GetNext(pos);
                    enumVar.GetVar("代号", cfgName, out tmpVar);
                    if (tmpVar == null)
                    {
                        continue;
                    }
                    if (!tmpVar.ToString().Equals(""))
                    {
                        break;
                    }
                }
                if (tmpVar != null)
                {
                    asmPrd.number = tmpVar.ToString();
                }
                if (asmPrd.number.IndexOf(".") > 0 && asmPrd.number.IndexOf(".") < asmPrd.number.Length)
                {
                    asmPrd.ztdm = asmPrd.number.Substring(0, asmPrd.number.IndexOf("."));
                    asmPrd.zjdm = asmPrd.number.Substring(asmPrd.number.IndexOf(".") + 1);
                }
                else
                {
                    asmPrd.ztdm = asmPrd.zjdm = asmPrd.number;
                }
            }
            if (varMgr.GetVariable("名称") != null)
            {
                object   tmpVar  = null;
                IEdmPos5 pos     = cfgList.GetHeadPosition();
                string   cfgName = null;
                while (!pos.IsNull)
                {
                    cfgName = cfgList.GetNext(pos);
                    enumVar.GetVar("名称", cfgName, out tmpVar);
                    if (tmpVar == null)
                    {
                        continue;
                    }
                    if (!tmpVar.ToString().Equals(""))
                    {
                        break;
                    }
                }
                if (tmpVar != null)
                {
                    asmPrd.name = tmpVar.ToString();
                }
            }
            if (varMgr.GetVariable("设计") != null)
            {
                object   tmpVar  = null;
                IEdmPos5 pos     = cfgList.GetHeadPosition();
                string   cfgName = null;
                while (!pos.IsNull)
                {
                    cfgName = cfgList.GetNext(pos);
                    enumVar.GetVar("设计", cfgName, out tmpVar);
                    if (tmpVar == null)
                    {
                        continue;
                    }
                    if (!tmpVar.ToString().Equals(""))
                    {
                        break;
                    }
                }
                if (tmpVar != null)
                {
                    asmPrd.bzr = tmpVar.ToString();
                }
            }
            if (varMgr.GetVariable("设计日期") != null)
            {
                object   tmpVar  = null;
                IEdmPos5 pos     = cfgList.GetHeadPosition();
                string   cfgName = null;
                while (!pos.IsNull)
                {
                    cfgName = cfgList.GetNext(pos);
                    enumVar.GetVar("设计日期", cfgName, out tmpVar);
                    if (tmpVar == null)
                    {
                        continue;
                    }
                    if (!tmpVar.ToString().Equals(""))
                    {
                        break;
                    }
                }
                if (tmpVar != null)
                {
                    asmPrd.bzsj = tmpVar.ToString();
                }
                if (asmPrd.bzsj.IndexOf(" ") >= 0)
                {
                    asmPrd.bzsj = asmPrd.bzsj.Substring(0, asmPrd.bzsj.IndexOf(" "));
                }
            }
            if (varMgr.GetVariable("批准") != null)
            {
                object   tmpVar  = null;
                IEdmPos5 pos     = cfgList.GetHeadPosition();
                string   cfgName = null;
                while (!pos.IsNull)
                {
                    cfgName = cfgList.GetNext(pos);
                    enumVar.GetVar("批准", cfgName, out tmpVar);
                    if (tmpVar == null)
                    {
                        continue;
                    }
                    if (!tmpVar.ToString().Equals(""))
                    {
                        break;
                    }
                }
                if (tmpVar != null)
                {
                    asmPrd.pzr = tmpVar.ToString();
                }
            }
            if (varMgr.GetVariable("批准日期") != null)
            {
                object   tmpVar  = null;
                IEdmPos5 pos     = cfgList.GetHeadPosition();
                string   cfgName = null;
                while (!pos.IsNull)
                {
                    cfgName = cfgList.GetNext(pos);
                    enumVar.GetVar("批准日期", cfgName, out tmpVar);
                    if (tmpVar == null)
                    {
                        continue;
                    }
                    if (!tmpVar.ToString().Equals(""))
                    {
                        break;
                    }
                }
                if (tmpVar != null)
                {
                    asmPrd.pzsj = tmpVar.ToString();
                }
                if (asmPrd.pzsj.IndexOf(" ") >= 0)
                {
                    asmPrd.pzsj = asmPrd.pzsj.Substring(0, asmPrd.pzsj.IndexOf(" "));
                }
            }
            if (varMgr.GetVariable("阶段标记") != null)
            {
                object   tmpVar  = null;
                IEdmPos5 pos     = cfgList.GetHeadPosition();
                string   cfgName = null;
                while (!pos.IsNull)
                {
                    cfgName = cfgList.GetNext(pos);
                    enumVar.GetVar("阶段标记", cfgName, out tmpVar);
                    if (tmpVar == null)
                    {
                        continue;
                    }
                    if (!tmpVar.ToString().Equals(""))
                    {
                        break;
                    }
                }
                if (tmpVar != null)
                {
                    asmPrd.jdbj = tmpVar.ToString();
                }
            }

            if (varMgr.GetVariable("设备型号") != null)
            {
                object   tmpVar  = null;
                IEdmPos5 pos     = cfgList.GetHeadPosition();
                string   cfgName = null;
                while (!pos.IsNull)
                {
                    cfgName = cfgList.GetNext(pos);
                    enumVar.GetVar("设备型号", cfgName, out tmpVar);
                    if (tmpVar == null)
                    {
                        continue;
                    }
                    if (!tmpVar.ToString().Equals(""))
                    {
                        break;
                    }
                }
                if (tmpVar != null)
                {
                    asmPrd.sbxh = tmpVar.ToString();
                }
            }
            if (varMgr.GetVariable("Project Name") != null)
            {
                object   tmpVar  = null;
                IEdmPos5 pos     = cfgList.GetHeadPosition();
                string   cfgName = null;
                while (!pos.IsNull)
                {
                    cfgName = cfgList.GetNext(pos);
                    enumVar.GetVar("Project Name", cfgName, out tmpVar);
                    if (tmpVar == null)
                    {
                        continue;
                    }
                    if (!tmpVar.ToString().Equals(""))
                    {
                        break;
                    }
                }
                if (tmpVar != null)
                {
                    asmPrd.projName = tmpVar.ToString();
                }
            }
            return(asmPrd);
        }
Пример #14
0
        public bool exportExcel(IEdmVault5 poVault, string selectFile, string saveFile)
        {
            WiseUtil    wiseUtil            = new WiseUtil();
            IEdmFolder5 templateExcelFolder = null;
            string      finalFilePath       = poVault.RootFolderPath + WiseUtil.templateExcelFilePath;
            IEdmFile5   templateExcelFile   = poVault.GetFileFromPath(finalFilePath, out templateExcelFolder);

            if (templateExcelFile == null)
            {
                System.Windows.Forms.MessageBox.Show("在PDM中找不到模板EXCEL:\n" + finalFilePath);
                return(false);
            }

            //string installLocation = wiseUtil.GetLocalMachineRegistryValue("SOFTWARE\\solidworks\\Applications\\PDMWorks Enterprise\\", "Location");
            //System.Console.WriteLine(installLocation);
            //if (installLocation == "")
            //{
            //   installLocation = "C:\\";
            //}
            //string excelTemplate = installLocation + "ExportTemplate\\template-list.xlsx";
            Workbook templateWb = null;

            try {
                templateWb = wiseUtil.OpenExcel(finalFilePath);
            }
            catch (Exception e) {
                System.Windows.Forms.MessageBox.Show("打开模板表格失败,请查看位置" + templateExcelFile + "的文件状态");
                return(false);
            }
            if (templateWb == null)
            {
                System.Windows.Forms.MessageBox.Show("打开模板表格失败");
                return(false);
            }
            SldWorks.SldWorks swApp = new SldWorks.SldWorks();
            int       longstatus    = 0;
            int       longwarnings  = 0;
            ModelDoc2 modelDoc      = swApp.OpenDoc6(selectFile, (int)swDocumentTypes_e.swDocDRAWING,
                                                     (int)(swOpenDocOptions_e.swOpenDocOptions_ReadOnly | swOpenDocOptions_e.swOpenDocOptions_Silent),
                                                     "", ref longstatus, ref longwarnings);

            if (modelDoc == null || longstatus > 0)
            {
                System.Windows.Forms.MessageBox.Show("打开二维图失败");
                swApp.ExitApp();
                templateWb.Close();
                return(false);
            }
            BomTableAnnotation bomTableAnno = null;
            string             configName   = "";
            string             topFileName  = "";

            try
            {
                wiseUtil.GetDrawingDocBOMTable(modelDoc, out bomTableAnno, out configName, out topFileName);
            }
            catch (Exception e)
            {
                System.Windows.Forms.MessageBox.Show("获取明细表信息出错" + e.StackTrace);
            }
            if (bomTableAnno == null)
            {
                System.Windows.Forms.MessageBox.Show("未找到明细表信息");
                swApp.ExitApp();
                templateWb.Close();
                return(false);
            }
            //modelDoc.Close();
            SldAsm asmPrd = wiseUtil.GetAsmIndoFromFile(poVault, topFileName);// new SldAsm();

            if (asmPrd == null)
            {
                System.Windows.Forms.MessageBox.Show("获取材料明细表关联产品失败");
                swApp.ExitApp();
                templateWb.Close();
                return(false);
            }
            //asmPrd.bzr = "hou";
            //asmPrd.bzsj = "2016/1/1";
            try
            {
                wiseUtil.ProcessTableAnn(poVault, bomTableAnno, configName, asmPrd);
            }
            catch (Exception e)
            {
                System.Windows.Forms.MessageBox.Show("解析明细表信息出错" + e.StackTrace);
            }
            //if (WiseUtil.errors > 0)
            //{
            //    System.Windows.Forms.MessageBox.Show("解析明细表信息出错" + WiseUtil.errorStr);
            //}
            wiseUtil.SaveBuyToWorkbook(templateWb, asmPrd);
            wiseUtil.SaveStdToWorkbook(templateWb, asmPrd);
            wiseUtil.SavePrtToWorkbook(templateWb, asmPrd);
            wiseUtil.SaveBspToWorkbook(templateWb, asmPrd);
            templateWb.SaveAs(saveFile);
            templateWb.Close();
            swApp.ExitApp();
            swApp = null;
            return(true);
        }