Exemple #1
0
        private void GetBoundingBox()
        {
            Point3d     centerPt = new Point3d();
            Point3d     disPt    = new Point3d();
            Part        workPart = Session.GetSession().Parts.Work;
            List <Body> bodys    = new List <Body>();

            //  NXOpen.Assemblies.Component ct = AssmbliesUtils.GetPartComp(workPart, part)[0];
            foreach (NXOpen.Assemblies.Component ct in AssmbliesUtils.GetPartComp(workPart, part))
            {
                if (!ct.IsSuppressed)
                {
                    foreach (Body body in this.part.Bodies.ToArray())
                    {
                        bodys.Add(AssmbliesUtils.GetNXObjectOfOcc(ct.Tag, body.Tag) as Body);
                    }
                }
            }
            Matrix4 invers = workMatr.GetInversMatrix();
            CartesianCoordinateSystem csys = BoundingBoxUtils.CreateCoordinateSystem(workMatr, invers);//坐标

            BoundingBoxUtils.GetBoundingBoxInLocal(bodys.ToArray(), csys, workMatr, ref centerPt, ref disPt);
            LayerUtils.MoveDisplayableObject(201, bodys.ToArray());
            this.CenterPt = centerPt;
            this.DisPt    = disPt;
        }
        /// <summary>
        /// 获取EDM下面工件
        /// </summary>
        /// <returns></returns>
        public List <Part> GetWorkPieces()
        {
            List <Part> parts = new List <Part>();

            foreach (Part pt in coll.Other)
            {
                try
                {
                    List <NXOpen.Assemblies.Component> ct = AssmbliesUtils.GetPartComp(this.workModel.PartTag, pt);
                    if (ct.Count > 0)
                    {
                        parts.Add(pt);
                    }
                }
                catch
                {
                }
            }
            parts.Sort(delegate(Part a, Part b)
            {
                return(a.Name.CompareTo(b.Name));
            }
                       );
            return(parts);
        }
        /// <summary>
        /// 更新图纸
        /// </summary>
        /// <returns></returns>
        private bool UpdeteDrawing(Part part)
        {
            Part workPart = Session.GetSession().Parts.Work;

            if (oldCt != null && newCt != null)
            {
                PartUtils.SetPartDisplay(part);
                foreach (NXOpen.Drawings.DrawingSheet ds in part.DrawingSheets)
                {
                    ds.Open();
                    foreach (NXOpen.Drawings.DraftingView dv in ds.GetDraftingViews())
                    {
                        Basic.DrawingUtils.HideComponent(dv, AssmbliesUtils.GetPartComp(workPart, oldCt));
                        Basic.DrawingUtils.ShowComponent(dv, AssmbliesUtils.GetPartComp(workPart, newCt));
                        dv.Update();
                    }
                }
                PartUtils.SetPartDisplay(workPart);
                return(true);
            }
            else
            {
                return(false);
            }
        }
 public WorkpieceInfo(Part workpiece, WorkModel work)
 {
     this.workpiece = workpiece;
     this.work      = work;
     workpieceComp  = AssmbliesUtils.GetPartComp(this.work.PartTag, this.workpiece);
     this.poin      = CreateMinAndMaxPt();
 }
        /// <summary>
        /// 获取工件实体在装配下的体
        /// </summary>
        /// <param name="ct"></param>
        /// <param name="pt"></param>
        /// <returns></returns>
        private List <Body> GetCompBodys(NXOpen.Assemblies.Component ct, Part pt)
        {
            List <Body> bodys = new List <Body>();

            if ((ct.Prototype as Part).Equals(pt))
            {
                foreach (Body by in pt.Bodies.ToArray())
                {
                    Body bo = AssmbliesUtils.GetNXObjectOfOcc(ct.Tag, by.Tag) as Body;
                    if (bo != null)
                    {
                        bodys.Add(bo);
                    }
                }
            }
            else
            {
                foreach (NXOpen.Assemblies.Component co in AssmbliesUtils.GetPartComp(ct.Prototype as Part, pt))
                {
                    if (!co.IsSuppressed)
                    {
                        foreach (Body by in pt.Bodies.ToArray())
                        {
                            Body bo = AssmbliesUtils.GetNXObjectOfOcc(co.Tag, by.Tag) as Body;
                            if (bo != null)
                            {
                                bodys.Add(bo);
                            }
                        }
                    }
                }
            }

            return(bodys);
        }
        /// <summary>
        /// 保存坐标
        /// </summary>
        /// <param name="asm"></param>
        /// <returns></returns>
        public bool SaveCsys(Part asm)
        {
            UFSession theUFSession = UFSession.GetUFSession();

            try
            {
                PartUtils.SetPartDisplay(asm);
                List <NXOpen.Assemblies.Component> ct = AssmbliesUtils.GetPartComp(asm, this.PartTag);
                CsysUtils.SetWcsOfCenteAndMatr(this.Info.Matr.GetCenter(), this.Info.Matr.GetMatrix3());
                PartUtils.SetPartWork(ct[0]);
                CartesianCoordinateSystem csys = asm.WCS.Save();
                string name   = "WORK" + this.Info.WorkNumber.ToString();
                Tag    objTag = Tag.Null;
                theUFSession.Obj.CycleByName(name, ref objTag);
                if (objTag != Tag.Null)
                {
                    theUFSession.Obj.DeleteObject(objTag);
                }
                csys.Name  = name;
                csys.Layer = 200;
                csys.Color = 186;
                PartUtils.SetPartWork(null);
                CsysUtils.SetWcsToAbs();
                return(true);
            }
            catch (NXException ex)
            {
                ClassItem.WriteLogFile("创建坐标错误" + ex.Message);
                return(false);
            }
        }
        private void GetWorkPieceComp()
        {
            Part host = Work.GetHostWorkpiece();

            if (host == null)
            {
                throw new Exception("无法找到主工件!");
            }
            foreach (NXOpen.Assemblies.Component ct in AssmbliesUtils.GetPartComp(workPart, host))
            {
                if (!ct.IsSuppressed)
                {
                    ct.Unblank();
                    this.HostComp.Add(ct);
                }
            }
            foreach (Part pt in Work.GetAllWorkpiece())
            {
                if (!host.Equals(pt))
                {
                    foreach (NXOpen.Assemblies.Component ct in AssmbliesUtils.GetPartComp(workPart, pt))
                    {
                        ct.Unblank();
                        OtherComp.Add(ct);
                    }
                }
            }
            this.OtherComp.Sort(delegate(NXOpen.Assemblies.Component a, NXOpen.Assemblies.Component b)
            {
                return(a.Name.CompareTo(b.Name));
            });
        }
Exemple #8
0
        /// <summary>
        /// 获取work
        /// </summary>
        /// <param name="model"></param>
        /// <param name="asmPart"></param>
        /// <returns></returns>
        private WorkModel GetWorkModel(ElectrodeModel model)
        {
            List <NXOpen.Assemblies.Component> eleComs = AssmbliesUtils.GetPartComp(this.asmPart, model.PartTag);
            List <WorkModel> works = new List <WorkModel>();

            foreach (NXOpen.Assemblies.Component ct in eleComs)
            {
                NXOpen.Assemblies.Component parent = ct.Parent;
                if (parent != null)
                {
                    Part pt = parent.Prototype as Part;
                    if (WorkModel.IsWork(pt) && !works.Exists(a => a.PartTag.Equals(pt)) && ParentAssmblieInfo.GetAttribute(pt).MoldInfo.Equals(model.Info.MoldInfo))
                    {
                        works.Add(new WorkModel(pt));
                    }
                }
            }
            works.Sort();
            if (works.Count != 0)
            {
                return(works[0]);
            }
            else
            {
                return(null);
            }
        }
Exemple #9
0
        /// <summary>
        /// 设置连接体
        /// </summary>
        public void WaveBodys()
        {
            Part      workPart     = Session.GetSession().Parts.Work;
            UFSession theUFSession = UFSession.GetUFSession();

            if (workPart.Tag != this.PartTag.Tag)
            {
                NXOpen.Assemblies.Component ct = AssmbliesUtils.GetPartComp(workPart, this.PartTag);
                PartUtils.SetPartWork(ct);
            }
            foreach (Part part in Session.GetSession().Parts)
            {
                string type = AttributeUtils.GetAttrForString(part, "PartType");
                if (type.Equals("Workpiece"))
                {
                    Body[] bodys = part.Bodies.ToArray();
                    NXOpen.Features.Feature feat = AssmbliesUtils.WaveAssociativeBodys(bodys);
                    Body[] waveBodys             = ((NXOpen.Features.BodyFeature)feat).GetBodies();
                    foreach (Body body in waveBodys)
                    {
                        body.Layer = 2;
                        theUFSession.Layer.SetStatus(2, 2);
                    }
                    break;
                }
            }
            PartUtils.SetPartWork(null);
        }
Exemple #10
0
        public NXOpen.Assemblies.Component[] GetEleHideComp()
        {
            Part workPart = theSession.Parts.Work;
            List <NXOpen.Assemblies.Component> hide = new List <NXOpen.Assemblies.Component>();
            Part workpiece = GetWorkpiecePart();

            foreach (NXOpen.Assemblies.Component workComp in workPart.ComponentAssembly.RootComponent.GetChildren())
            {
                workComp.Blank();
                foreach (NXOpen.Assemblies.Component ct in workComp.GetChildren())
                {
                    ct.Unblank();
                    NXOpen.Assemblies.Component[] edm = ct.GetChildren();
                    if (edm.Length != 0)
                    {
                        hide.Add(ct);
                        foreach (NXOpen.Assemblies.Component workpieceComp in edm)
                        {
                            workpieceComp.Unblank();
                            hide.Add(workpieceComp);
                        }
                    }
                    else
                    {
                        hide.Add(ct);
                    }
                }
            }

            NXOpen.Assemblies.Component eleComp = AssmbliesUtils.GetPartComp(workPart, EleModel.PartTag);
            hide.Remove(eleComp);
            return(hide.ToArray());
        }
Exemple #11
0
        /// <summary>
        /// 获取Work下原点
        /// </summary>
        /// <returns></returns>
        public Point GetWorkCompPoint()
        {
            Part      workPart     = Session.GetSession().Parts.Work;
            UFSession theUFSession = UFSession.GetUFSession();
            Component ct           = AssmbliesUtils.GetPartComp(this.PartTag, work.PartTag)[0];
            Point     pt           = work.CreateCenterPoint();

            return(AssmbliesUtils.GetNXObjectOfOcc(ct.Tag, pt.Tag) as Point);
        }
        /// <summary>
        /// 更新work零件明细表
        /// </summary>
        private void AlterWorkDrawing()
        {
            Part      workPart     = Session.GetSession().Parts.Work;
            UFSession theUFSession = UFSession.GetUFSession();

            if (!workPart.Equals(work.PartTag))
            {
                NXOpen.Assemblies.Component ct = AssmbliesUtils.GetPartComp(workPart, work.PartTag);
                PartUtils.SetPartWork(ct);
            }
            theUFSession.Plist.UpdateAllPlists();
            PartUtils.SetPartWork(null);
        }
Exemple #13
0
        /// <summary>
        /// 画中心点和中心线
        /// </summary>
        /// <param name="disPt"></param>
        public void CreatePointAndCenterLine(Point3d centerPt, Point3d disPt)
        {
            Part workPart = Session.GetSession().Parts.Work;

            if (workPart.Tag != PartTag.Tag)
            {
                NXOpen.Assemblies.Component ct = AssmbliesUtils.GetPartComp(workPart, PartTag);
                PartUtils.SetPartWork(ct);
            }
            CreateCenterLine(centerPt, disPt);
            CreateCenterPoint();
            PartUtils.SetPartWork(null);
        }
        /// <summary>
        /// 获得电极组件
        /// </summary>
        /// <returns></returns>
        private List <NXOpen.Assemblies.Component> GetEleAllComponent()
        {
            ASMModel asm = ASMCollection.GetAsmModel(this.elePart);

            try
            {
                return(AssmbliesUtils.GetPartComp(asm.PartTag, elePart));
            }
            catch (NXException ex)
            {
                ClassItem.WriteLogFile("获取电极组件错误!" + ex.Message);
                return(null);
            }
        }
Exemple #15
0
        /// <summary>
        /// 更新Pitch
        /// </summary>
        private bool UpdatePitch()
        {
            Part workPart = Session.GetSession().Parts.Work;

            NXOpen.Features.ExtractFace     ext;
            NXOpen.Features.MoveObject      move;
            NXOpen.Features.PatternGeometry patt;
            List <Body> bodys = new List <Body>();
            Body        boolBody;
            List <NXOpen.Features.BooleanFeature> extBools;

            GetExtrudeBooleanBody(out boolBody, out extBools);
            GetFeature(out ext, out move, out patt);
            if (ext == null || move == null || patt == null || boolBody == null)
            {
                return(false);
            }
            if (extBools.Count > 0)
            {
                DeleteObject.Delete(extBools.ToArray());
            }
            bodys.AddRange(ext.GetBodies());
            bodys.AddRange(patt.GetAssociatedBodies());
            try
            {
                MoveObject.CreateMoveObjToXYZ("moveX", "moveY", "moveZ", move as NXOpen.Features.MoveObject, bodys.ToArray());
            }
            catch (NXException ex)
            {
                ClassItem.WriteLogFile("更新移动错误!" + ex.Message);
                return(false);
            }
            List <Body> bys = eleModel.PartTag.Bodies.ToArray().ToList();

            bys.Remove(boolBody);
            SetHeadColour(newAllInfo.Pitch, newAllInfo.GapValue, bys);
            try
            {
                PartUtils.SetPartWork(AssmbliesUtils.GetPartComp(asm, eleModel.PartTag)[0]);
                Body elebody = BooleanUtils.CreateBooleanFeature(boolBody, false, false, NXOpen.Features.Feature.BooleanType.Unite, bys.ToArray()).GetBodies()[0];
                SetEleColor(elebody);
                PartUtils.SetPartWork(null);
            }
            catch (NXException ex)
            {
                ClassItem.WriteLogFile("更新求和错误!" + ex.Message);
                return(false);
            }
            return(true);
        }
Exemple #16
0
        /// <summary>
        /// 获取边
        /// </summary>
        /// <param name="xEdge"></param>
        /// <param name="yEdge"></param>
        public void GetEdge(out List <Edge> xEdge, out Point centerCom)
        {
            xEdge     = new List <Edge>();
            centerCom = null;
            string         str = "";
            ElectrodeModel ele = null;

            foreach (ElectrodeModel em in eleModels)
            {
                if (em.Info.AllInfo.SetValue.Positioning == "" || em.Info.AllInfo.SetValue.Positioning.Equals("A", StringComparison.CurrentCultureIgnoreCase))
                {
                    ele = em;
                }
            }
            if (ele == null)
            {
                return;
            }

            List <Face> faces = new List <Face>();

            faces.AddRange(ele.PartTag.Bodies.ToArray()[0].GetFaces());
            Point elePoint = ele.GetSetPoint();

            faces.Sort(delegate(Face a, Face b)
            {
                FaceData data1 = FaceUtils.AskFaceData(a);
                FaceData data2 = FaceUtils.AskFaceData(b);
                return(data1.Point.Z.CompareTo((data2.Point.Z)));
            });
            foreach (Component ct in AssmbliesUtils.GetPartComp(this.PartTag, ele.PartTag))
            {
                ElectrodeSetValueInfo value = ElectrodeSetValueInfo.GetAttribute(ct);
                if (value.Positioning == "" || value.Positioning.Equals("A", StringComparison.CurrentCultureIgnoreCase))
                {
                    centerCom = AssmbliesUtils.GetNXObjectOfOcc(ct.Tag, elePoint.Tag) as Point;
                    foreach (Edge eg in faces[10].GetEdges())
                    {
                        NXOpen.UF.UFEval.Line lineData;
                        if (EdgeUtils.GetLineData(eg, out lineData, ref str))
                        {
                            if (UMathUtils.IsEqual(lineData.start[1], lineData.end[1]))
                            {
                                xEdge.Add(AssmbliesUtils.GetNXObjectOfOcc(ct.Tag, eg.Tag) as Edge);
                            }
                        }
                    }
                }
            }
        }
Exemple #17
0
        /// <summary>
        /// 获取隐藏工件
        /// </summary>
        /// <param name="setValueHidden"></param>
        /// <param name="eleHidden"></param>
        public void GetHidden(out List <Component> setValueHidden, out List <Component> eleHidden)
        {
            List <Component> all = new List <Component>();

            setValueHidden = new List <Component>();
            eleHidden      = new List <Component>();
            foreach (NXOpen.Assemblies.Component ct in this.PartTag.ComponentAssembly.RootComponent.GetChildren())
            {
                //  all.Add(ct);
                ct.Blank();
                foreach (Component co in ct.GetChildren())
                {
                    co.Unblank();
                    Component[] coms = co.GetChildren();
                    if (coms.Length > 0)
                    {
                        all.AddRange(coms);
                        continue;
                    }
                    all.Add(co);
                }
            }
            setValueHidden.AddRange(all);
            eleHidden.AddRange(all);
            foreach (ElectrodeModel em in eleModels)
            {
                List <Component> elecom = AssmbliesUtils.GetPartComp(this.PartTag, em.PartTag);
                foreach (Component eleCt in elecom)
                {
                    eleCt.Unblank();
                    setValueHidden.Remove(eleCt);
                    if (em.Info.AllInfo.SetValue.Positioning == "" || em.Info.AllInfo.SetValue.Positioning.Equals("A", StringComparison.CurrentCultureIgnoreCase))
                    {
                        ElectrodeSetValueInfo value = ElectrodeSetValueInfo.GetAttribute(eleCt);
                        if (value.Positioning == "" || value.Positioning.Equals("A", StringComparison.CurrentCultureIgnoreCase))
                        {
                            eleHidden.Remove(eleCt);
                        }
                    }
                }
            }
            Part workpiecePart = this.work.GetHostWorkpiece();

            foreach (Component ct in AssmbliesUtils.GetPartComp(this.PartTag, workpiecePart))
            {
                setValueHidden.Remove(ct);
            }
        }
Exemple #18
0
        private List <Body> GetBodys()
        {
            Part        workPart  = theSession.Parts.Work;
            List <Body> bodys     = new List <Body>();
            Part        workpiece = GetWorkpiecePart();

            NXOpen.Assemblies.Component workComp = AssmbliesUtils.GetPartComp(workPart, workpiece);
            workComp.Unblank();
            bodys.Add(AssmbliesUtils.GetNXObjectOfOcc(workComp.Tag, workpiece.Bodies.ToArray()[0].Tag) as Body);
            foreach (ElectrodeModel model in this.DraModel.Eles)
            {
                NXOpen.Assemblies.Component eleComp = AssmbliesUtils.GetPartComp(workPart, model.PartTag);
                bodys.Add(AssmbliesUtils.GetNXObjectOfOcc(eleComp.Tag, model.PartTag.Bodies.ToArray()[0].Tag) as Body);
            }
            return(bodys);
        }
        /// <summary>
        /// 替换组件
        /// </summary>
        /// <param name="pt"></param>
        /// <param name="info"></param>
        /// <param name="newPath"></param>
        /// <param name="newName"></param>
        /// <returns></returns>
        public static List <string> Replace(Part pt, string newPath, string newName, out Part newPart)
        {
            List <string> err = new List <string>();

            newPart = null;
            Session          theSession   = Session.GetSession();
            UFSession        theUFSession = UFSession.GetUFSession();
            Part             workPart     = theSession.Parts.Work;
            List <Component> cts          = AssmbliesUtils.GetPartComp(workPart, pt);
            string           oldPath      = pt.FullPath;

            pt.Close(NXOpen.BasePart.CloseWholeTree.False, NXOpen.BasePart.CloseModified.UseResponses, null);
            File.Move(oldPath, newPath);
            if (cts.Count > 0)
            {
                foreach (Component co in cts)
                {
                    try
                    {
                        bool rep = AssmbliesUtils.ReplaceComp(co, newPath, newName);
                        if (rep)
                        {
                            err.Add(newName + "           组件替换成功!          ");
                        }
                        else
                        {
                            err.Add(newName + "           组件替换失败!          ");
                        }
                    }
                    catch
                    {
                        err.Add(newName + "           组件替换失败!          ");
                    }
                }
                newPart = cts[0].Prototype as Part;
                return(err);
            }
            else
            {
                Tag partTag;
                UFPart.LoadStatus error_status;
                theUFSession.Part.Open(newPath, out partTag, out error_status);
                err.Add(newName + "           组件替换成功!          ");
                newPart = NXObjectManager.Get(partTag) as Part;
                return(err);
            }
        }
Exemple #20
0
        private List <Body> GetDrawingBody(Part draPart)
        {
            List <Body> bodys = new List <Body>();
            Body        by    = eleModel.PartTag.Bodies.ToArray()[0];

            foreach (NXOpen.Assemblies.Component ct in AssmbliesUtils.GetPartComp(draPart, eleModel.PartTag))
            {
                try
                {
                    bodys.Add(AssmbliesUtils.GetNXObjectOfOcc(ct.Tag, by.Tag) as Body);
                }
                catch
                {
                }
            }
            return(bodys);
        }
Exemple #21
0
        /// <summary>
        /// 修改设定值
        /// </summary>
        /// <param name="asm"></param>
        /// <returns></returns>
        public bool AlterEleSetValue()
        {
            List <ElectrodeModel> eleModels = new List <ElectrodeModel>();

            try
            {
                foreach (Part pt in Session.GetSession().Parts)
                {
                    List <NXOpen.Assemblies.Component> ct = AssmbliesUtils.GetPartComp(this.PartTag, pt);
                    if (ct.Count > 0 && ElectrodeModel.IsElectrode(pt))
                    {
                        eleModels.Add(new ElectrodeModel(pt));
                    }
                }
                foreach (ElectrodeModel em in eleModels)
                {
                    List <Component> eleCt = AssmbliesUtils.GetPartComp(this.PartTag, em.PartTag);
                    Point            pt    = em.GetSetPoint();
                    foreach (Component ct in eleCt)
                    {
                        Point   ptOcc = AssmbliesUtils.GetNXObjectOfOcc(ct.Tag, pt.Tag) as Point;
                        Point3d value = ptOcc.Coordinates;
                        this.Info.Matr.ApplyPos(ref value);
                        ElectrodeSetValueInfo setValue    = ElectrodeSetValueInfo.GetAttribute(ct);
                        ElectrodeSetValueInfo newSetValue = setValue.Clone() as ElectrodeSetValueInfo;
                        newSetValue.EleSetValue = new double[] { value.X, value.Y, value.Z };
                        if (setValue.Positioning == "" || setValue.Positioning.Equals("A", StringComparison.CurrentCultureIgnoreCase))
                        {
                            newSetValue.SetAttribute(em.PartTag);
                        }
                        else
                        {
                            NXObject obj = AssmbliesUtils.GetOccOfInstance(ct.Tag);
                            newSetValue.SetAttribute(obj);
                        }
                    }
                }

                return(true);
            }
            catch (NXException ex)
            {
                ClassItem.WriteLogFile("修改电极设定值错误!" + ex.Message);
                return(false);
            }
        }
Exemple #22
0
        /// <summary>
        /// 获取电极X轴线
        /// </summary>
        /// <returns></returns>
        public List <Line> GetYLine()
        {
            List <Line> le = new List <Line>();

            foreach (ElectrodeModel em in eleModels)
            {
                Line bo = em.GetYLine();
                foreach (Component eleCt in AssmbliesUtils.GetPartComp(this.PartTag, em.PartTag))
                {
                    Line temp = AssmbliesUtils.GetNXObjectOfOcc(eleCt.Tag, bo.Tag) as Line;
                    if (temp != null)
                    {
                        le.Add(temp);
                    }
                }
            }
            return(le);
        }
Exemple #23
0
        /// <summary>
        /// 获取电极设定点
        /// </summary>
        /// <returns></returns>
        public List <Point> GetEleSetPoint()
        {
            List <Point> pt = new List <Point>();

            foreach (ElectrodeModel em in eleModels)
            {
                Point bo = em.GetSetPoint();
                foreach (Component eleCt in AssmbliesUtils.GetPartComp(this.PartTag, em.PartTag))
                {
                    Point temp = AssmbliesUtils.GetNXObjectOfOcc(eleCt.Tag, bo.Tag) as Point;
                    if (temp != null)
                    {
                        pt.Add(temp);
                    }
                }
            }
            return(pt);
        }
Exemple #24
0
        /// <summary>
        /// 获取工件体
        /// </summary>
        /// <returns></returns>
        public List <Body> GetWorkpieceBody()
        {
            List <Body> bodys         = new List <Body>();
            Part        workpiecePart = this.work.GetHostWorkpiece();

            foreach (Body body in workpiecePart.Bodies.ToArray())
            {
                foreach (Component workpieceCom in AssmbliesUtils.GetPartComp(this.PartTag, workpiecePart))
                {
                    Body by = AssmbliesUtils.GetNXObjectOfOcc(workpieceCom.Tag, body.Tag) as Body;
                    if (by != null)
                    {
                        bodys.Add(by);
                    }
                }
            }
            return(bodys);
        }
Exemple #25
0
        /// <summary>
        /// 获取电极体
        /// </summary>
        /// <returns></returns>
        public List <Body> GetEleBody()
        {
            //  Part workPart = Session.GetSession().Parts.Work;
            List <Body> by = new List <Body>();

            foreach (ElectrodeModel em in eleModels)
            {
                Body bo = em.PartTag.Bodies.ToArray()[0];
                foreach (Component eleCt in AssmbliesUtils.GetPartComp(this.PartTag, em.PartTag))
                {
                    Body temp = AssmbliesUtils.GetNXObjectOfOcc(eleCt.Tag, bo.Tag) as Body;
                    if (temp != null)
                    {
                        by.Add(temp);
                    }
                }
            }
            return(by);
        }
        /// <summary>
        /// 获取装配下面所有电极
        /// </summary>
        /// <returns></returns>
        public List <ElectrodeModel> GetElectrodes()
        {
            List <ElectrodeModel> eles = new List <ElectrodeModel>();

            foreach (ElectrodeModel ele in coll.Electrode)
            {
                try
                {
                    List <NXOpen.Assemblies.Component> ct = AssmbliesUtils.GetPartComp(this.model.PartTag, ele.PartTag);
                    if (ct.Count > 0)
                    {
                        eles.Add(ele);
                    }
                }
                catch
                {
                }
            }
            return(eles);
        }
        /// <summary>
        /// 获取ASM下所有works
        /// </summary>
        /// <returns></returns>
        public List <WorkModel> GetWorks()
        {
            List <WorkModel> works = new List <WorkModel>();

            foreach (WorkModel wk in coll.Work)
            {
                try
                {
                    List <NXOpen.Assemblies.Component> ct = AssmbliesUtils.GetPartComp(this.model.PartTag, wk.PartTag);
                    if (ct.Count > 0)
                    {
                        works.Add(wk);
                    }
                }
                catch
                {
                }
            }
            return(works);
        }
        /// <summary>
        /// 获取Part的OCC
        /// </summary>
        /// <param name="pt"></param>
        /// <returns></returns>
        private Component GetPartInOcc(Part pt)
        {
            Part workPart = Session.GetSession().Parts.Work;

            try
            {
                List <Component> cts = AssmbliesUtils.GetPartComp(workPart, pt);
                foreach (Component ct in cts)
                {
                    if (ct.Parent.Parent.Equals(workComp))
                    {
                        return(ct);
                    }
                }
                return(null);
            }
            catch
            {
                return(null);
            }
        }
Exemple #29
0
        public static Part Replace(Part pt, string newName)
        {
            Session   theSession = Session.GetSession();
            Part      workPart   = theSession.Parts.Work;
            string    oldName    = pt.Name;
            string    oldPath    = pt.FullPath;
            string    newPath    = oldPath.Replace(oldName, newName);
            Component ct         = AssmbliesUtils.GetPartComp(workPart, pt);

            File.Move(oldPath, newPath);
            if (ct != null)
            {
                pt.Close(NXOpen.BasePart.CloseWholeTree.False, NXOpen.BasePart.CloseModified.UseResponses, null);
                if (Basic.AssmbliesUtils.ReplaceComp(ct, newPath, newName))
                {
                    return(ct.OwningPart as Part);
                }
                return(null);
            }
            return(null);
        }
Exemple #30
0
        private List <NXObject> AskEleAllInstance(Part ele)
        {
            List <NXObject> objs = new List <NXObject>();

            foreach (NXOpen.Assemblies.Component ct in AssmbliesUtils.GetPartComp(asm.PartTag, ele))
            {
                NXObject nt = null;
                try
                {
                    nt = AssmbliesUtils.GetOccOfInstance(ct.Tag);
                }
                catch
                {
                }
                if (nt != null)
                {
                    objs.Add(nt);
                }
            }
            return(objs);
        }