예제 #1
0
        /// <summary>
        /// 替换电极图纸
        /// </summary>
        /// <param name="oldParenInfo"></param>
        /// <param name="newParenInfo"></param>
        /// <returns></returns>
        public List <string> AlterEleDra(ParentAssmblieInfo oldParenInfo, ParentAssmblieInfo newParenInfo)
        {
            List <string> err          = new List <string>();
            UFSession     theUFSession = UFSession.GetUFSession();
            Part          workPart     = Session.GetSession().Parts.Work;
            string        oldDra       = directoryPath + oldNameInfo.EleName + "_dwg.prt";

            if (!File.Exists(oldDra))
            {
                return(err);
            }
            string newDra = directoryPath + newNameInfo.EleName + "_dwg.prt";

            if (File.Exists(newDra))
            {
                err.Add(newNameInfo.EleName + "            替换失败,替换后有同名工件!          ");
                return(err);
            }
            else
            {
                foreach (Part pt in Session.GetSession().Parts)
                {
                    if (pt.Name.Equals(oldNameInfo.EleName + "_dwg", StringComparison.CurrentCultureIgnoreCase))
                    {
                        pt.Close(NXOpen.BasePart.CloseWholeTree.False, NXOpen.BasePart.CloseModified.UseResponses, null);
                    }
                }
                File.Move(oldDra, newDra);
                Tag partTag;
                UFPart.LoadStatus error_status;
                theUFSession.Part.Open(newDra, out partTag, out error_status);
                Part newPart = NXObjectManager.Get(partTag) as Part;

                PartUtils.SetPartDisplay(newPart);
                NXOpen.Assemblies.Component comp = newPart.ComponentAssembly.RootComponent.GetChildren()[0];
                string workName = comp.Name.Replace(oldParenInfo.MoldInfo.MoldNumber + "-" + oldParenInfo.MoldInfo.WorkpieceNumber, newParenInfo.MoldInfo.MoldNumber + "-" + newParenInfo.MoldInfo.WorkpieceNumber);
                try
                {
                    Basic.AssmbliesUtils.ReplaceComp(comp, this.directoryPath + workName + ".prt", workName);
                }
                catch
                {
                }
                if (newPart != null)
                {
                    newNameInfo.SetAttribute(newPart);
                    ParentAssmblieInfo info = ParentAssmblieInfo.GetAttribute(newPart);
                    info.MoldInfo  = newParenInfo.MoldInfo;
                    info.UserModel = newParenInfo.UserModel;
                    info.SetAttribute(newPart);
                    foreach (DrawingSheet st in newPart.DrawingSheets)
                    {
                        Basic.DrawingUtils.UpdateViews(st);
                    }
                }
                PartUtils.SetPartDisplay(workPart);
                err.Add(newNameInfo.EleName + "           图纸替换成功!          ");
                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);
        }