コード例 #1
0
        /// <summary>
        /// 修改电极名
        /// </summary>
        /// <returns></returns>
        public List <string> AlterEle(out Part newElePart)
        {
            newElePart = null;
            string        newEleName = elePt.Name.Replace(oldNameInfo.EleName, newNameInfo.EleName);
            string        newPath    = directoryPath + newEleName + ".prt";
            List <string> err        = new List <string>();

            if (File.Exists(newPath))
            {
                err.Add(newEleName + "            替换失败,替换后有同名工件!          ");
            }
            else
            {
                err.AddRange(ReplacePart.Replace(elePt, newPath, newEleName, out newElePart));
                if (newElePart != null)
                {
                    newNameInfo.SetAttribute(newElePart);
                }
            }
            return(err);
        }
コード例 #2
0
        public List <string> Alter(string newName)
        {
            string        newPath = this.directoryPath + newName + ".prt";
            List <string> err     = new List <string>();

            if (File.Exists(newPath))
            {
                err.Add(newName + "            替换失败,替换后有同名工件!          ");
                return(err);
            }
            Part newPart;

            err.AddRange(ReplacePart.Replace(pt, newPath, newName, out newPart));
            if (newPart != null)
            {
                newInfo.SetAttribute(newPart);
            }
            else
            {
                newInfo.SetAttribute(pt);
            }
            return(err);
        }
コード例 #3
0
        public List <string> AlterEle(ParentAssmblieInfo parenInfo)
        {
            Part          newElePart;
            string        newEleName = elePt.Name.Replace(oldNameInfo.EleName, newNameInfo.EleName);
            string        newPath    = directoryPath + newEleName + ".prt";
            List <string> err        = new List <string>();

            if (File.Exists(newPath))
            {
                err.Add(newEleName + "            替换失败,替换后有同名工件!          ");
                return(err);
            }
            ParentAssmblieInfo info = ParentAssmblieInfo.GetAttribute(elePt);

            err.AddRange(ReplacePart.Replace(elePt, newPath, newEleName, out newElePart));
            if (newElePart != null)
            {
                info.MoldInfo  = parenInfo.MoldInfo;
                info.UserModel = parenInfo.UserModel;
                newNameInfo.SetAttribute(newElePart);
                info.SetAttribute(newElePart);
            }
            return(err);
        }
コード例 #4
0
        public List <string> Replace()
        {
            List <string>  err = new List <string>();
            Part           part;
            bool           anyPartsModified;
            PartSaveStatus saveStatus;
            Session        theSession = Session.GetSession();

            if (oldCt != null && newCt != null && oldCt.Equals(newCt))
            {
                return(err);
            }
            //  AllUpdeteDrawing();
            if ((part = ReplacePart.Replace(assm.Edm, info)) != null)
            {
                info.SetAttribute(part);
                theSession.Parts.SaveAll(out anyPartsModified, out saveStatus);
                err.Add("修改" + assm.Edm.AssembleName + "成功!");
            }
            foreach (ElectrodeModel em in assm.Electrodes)
            {
                if ((part = ReplacePart.Replace(em, info)) != null)
                {
                    info.SetAttribute(part);
                    ElectrodeInfo eleInfo = new ElectrodeInfo();
                    eleInfo.GetAttribute(part);
                    string oldEleName = eleInfo.EleName;
                    string olddrwPath = em.WorkpieceDirectoryPath + oldEleName + "_dwg.prt";
                    string newEleName = oldEleName.Replace(em.MoldInfo.MoldNumber + "-" + em.MoldInfo.WorkpieceNumber, info.MoldNumber + "-" + info.WorkpieceNumber);
                    eleInfo.EleName = newEleName;
                    if (isBorrow)
                    {
                        eleInfo.BorrowName = oldEleName;
                    }
                    eleInfo.SetAttribute(part);
                    theSession.Parts.SaveAll(out anyPartsModified, out saveStatus);
                    err.Add("修改" + em.AssembleName + "成功!");
                }
            }
            foreach (WorkModel wm in assm.Works)
            {
                if ((part = ReplacePart.Replace(wm, info)) != null)
                {
                    info.SetAttribute(part);
                    theSession.Parts.SaveAll(out anyPartsModified, out saveStatus);
                    err.Add("修改" + wm.AssembleName + "成功!");
                }
            }
            foreach (ElectrodeModel em in assm.Electrodes)
            {
                Part          workPart   = Session.GetSession().Parts.Work;
                ElectrodeInfo eleInfo    = em.EleInfo;
                string        oldEleName = eleInfo.EleName;
                string        olddrwPath = em.WorkpieceDirectoryPath + oldEleName + "_dwg.prt";
                if (File.Exists(olddrwPath))
                {
                    string newEleName = oldEleName.Replace(em.MoldInfo.MoldNumber + "-" + em.MoldInfo.WorkpieceNumber, info.MoldNumber + "-" + info.WorkpieceNumber);
                    eleInfo.EleName = newEleName;
                    if (isBorrow)
                    {
                        eleInfo.BorrowName = oldEleName;
                    }
                    if (File.Exists(olddrwPath.Replace(oldEleName, newEleName)))
                    {
                        File.Delete(olddrwPath.Replace(oldEleName, newEleName));
                    }
                    File.Move(olddrwPath, olddrwPath.Replace(oldEleName, newEleName));
                    NXOpen.PartLoadStatus partLoadStatus1;
                    BasePart part1 = Session.GetSession().Parts.OpenBase(olddrwPath.Replace(oldEleName, newEleName), out partLoadStatus1);
                    PartUtils.SetPartDisplay(part1 as Part);
                    eleInfo.SetAttribute(part1 as Part);
                    NXOpen.Assemblies.Component comp = part1.ComponentAssembly.RootComponent.GetChildren()[0];
                    string workName = comp.Name.Replace(em.MoldInfo.MoldNumber + "-" + em.MoldInfo.WorkpieceNumber, info.MoldNumber + "-" + info.WorkpieceNumber);
                    Basic.AssmbliesUtils.ReplaceComp(comp, em.WorkpieceDirectoryPath + workName + ".prt", workName);
                    theSession.Parts.SaveAll(out anyPartsModified, out saveStatus);
                    PartUtils.SetPartDisplay(workPart);
                    err.Add("修改" + em.AssembleName + "_dwg" + "成功!");
                }
            }
            return(err);
        }