Exemplo n.º 1
0
        //------------------------------------------------------------------------------
        //Callback Name: apply_cb
        //------------------------------------------------------------------------------
        public int apply_cb()
        {
            int errorCode = 0;

            try
            {
                //---- Enter your callback code here -----

                Session.UndoMarkId          markId  = Session.GetSession().SetUndoMark(NXOpen.Session.MarkVisibility.Visible, "删除电极");
                ElectrodeModel              ele     = new ElectrodeModel();
                NXOpen.Assemblies.Component eleComp = this.selection_Ele.GetSelectedObjects()[0] as NXOpen.Assemblies.Component;
                Part elePart = eleComp.Prototype as Part;
                ele.GetModelForPart(elePart);
                int ok = theUI.NXMessageBox.Show("删除", NXOpen.NXMessageBox.DialogType.Question, elePart.Name + "电极是否删除");
                if (ok == 1)
                {
                    string path = elePart.FullPath;
                    elePart.Close(NXOpen.BasePart.CloseWholeTree.False, NXOpen.BasePart.CloseModified.UseResponses, null);
                    AssmbliesUtils.DeleteComponent(eleComp);
                    LayerUtils.MoveDisplayableObject(ele.EleInfo.EleNumber + 10, LayerUtils.GetAllObjectsOnLayer(ele.EleInfo.EleNumber + 100));
                    if (File.Exists(path))
                    {
                        File.Delete(path);
                    }
                }
            }
            catch (Exception ex)
            {
                //---- Enter your exception handling code here -----
                errorCode = 1;
                theUI.NXMessageBox.Show("Block Styler", NXMessageBox.DialogType.Error, ex.ToString());
            }
            return(errorCode);
        }
Exemplo n.º 2
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;
        }
        public bool DeleteBuilder()
        {
            Part workPart = Session.GetSession().Parts.Work;
            List <NXOpen.Assemblies.Component> eleCom = GetEleAllComponent();
            ElectrodeModel eleModel  = new ElectrodeModel(elePart);
            int            eleNumber = eleModel.Info.AllInfo.Name.EleNumber;
            string         path      = elePart.FullPath;

            if (eleCom != null)
            {
                Part work = GetEleWorkPart(eleCom);
                if (work != null)
                {
                    PartUtils.SetPartDisplay(work);
                    NXObject[] objs = LayerUtils.GetAllObjectsOnLayer(eleNumber + 100);
                    LayerUtils.MoveDisplayableObject(eleNumber + 10, objs);
                }
                PartUtils.SetPartDisplay(workPart);
                Part elePart = eleCom[0].Prototype as Part;
                AssmbliesUtils.DeleteComponent(eleCom.ToArray());

                elePart.Close(BasePart.CloseWholeTree.False, BasePart.CloseModified.CloseModified, null);
                if (File.Exists(path))
                {
                    File.Delete(path);
                }
                return(true);
            }
            return(false);
        }
        private void SetLayer(int layer)
        {
            List <Body> eleBy = model.GetEleBody();

            if (eleBy.Count > 0)
            {
                LayerUtils.MoveDisplayableObject(layer, eleBy.ToArray());
            }
            List <Body> workpieceBody = model.GetWorkpieceBody();

            if (workpieceBody.Count > 0)
            {
                LayerUtils.MoveDisplayableObject(layer, workpieceBody.ToArray());
            }
            List <Line> xLine = model.GetXLine();

            if (xLine.Count > 0)
            {
                LayerUtils.MoveDisplayableObject(layer, xLine.ToArray());
            }
            List <Line> yLine = model.GetYLine();

            if (yLine.Count > 0)
            {
                LayerUtils.MoveDisplayableObject(layer, yLine.ToArray());
            }
        }
Exemplo n.º 5
0
        /// <summary>
        /// 更新图纸
        /// </summary>
        public void UpdateDrawing()
        {
            string dwgName = eleModel.Info.AllInfo.Name.EleName + "_dwg";
            string path    = eleModel.WorkpieceDirectoryPath + dwgName + ".prt";

            if (!File.Exists(path))
            {
                return;
            }
            Part dwg = null;

            foreach (Part part in Session.GetSession().Parts)
            {
                if (part.Name.ToUpper().Equals(dwgName.ToUpper()))
                {
                    dwg = part;
                    break;
                }
            }
            if (dwg == null)
            {
                if (File.Exists(path))
                {
                    dwg = PartUtils.OpenPartFile(path);
                }
            }
            if (dwg != null)
            {
                newAllInfo.SetAttribute(dwg);
                string temp = newAllInfo.Preparetion.Preparation[0].ToString() + "*" + newAllInfo.Preparetion.Preparation[1].ToString() + "*" + newAllInfo.Preparetion.Preparation[2].ToString();
                AttributeUtils.AttributeOperation("StrPre", temp, dwg);
                if (!oldAllInfo.Pitch.IsEquals(newAllInfo.Pitch))
                {
                    PartUtils.SetPartDisplay(dwg);
                    LayerUtils.MoveDisplayableObject(201, GetDrawingBody(dwg).ToArray());
                    foreach (NXOpen.Drawings.DrawingSheet sh in dwg.DrawingSheets)
                    {
                        Basic.DrawingUtils.UpdateViews(sh);
                    }
                }
                if (!oldAllInfo.Preparetion.IsEquals(newAllInfo.Preparetion))
                {
                    foreach (NXOpen.Drawings.DrawingSheet sh in dwg.DrawingSheets)
                    {
                        Basic.DrawingUtils.UpdateViews(sh);
                    }
                }
                newAllInfo.SetAttribute(dwg);
                PartUtils.SetPartDisplay(asm);
            }
        }
        /// <summary>
        ///检查体
        /// </summary>
        /// <returns></returns>
        public BodyInfo GetBodyInfoForInterference(bool extract, out List <string> err)
        {
            err = new List <string>();
            List <Face> dischargeFace = new List <Face>();
            List <Face> temp          = new List <Face>();
            List <Body> bodys         = new List <Body>();

            try
            {
                AnalysisUtils.SetInterferenceOutFace(this.eleBody, this.toolBody, out temp, out bodys);
            }
            catch (NXException ex)
            {
                err.Add("干涉检查错误!" + ex.Message);
            }
            if (bodys.Count > 0)
            {
                LayerUtils.MoveDisplayableObject(252, bodys.ToArray());
                if (extract)
                {
                    this.eleBody.Color = 186;
                }
                err.Add("电极头有过切,请检查!");
            }
            dischargeFace = temp.Where(a => a.GetBody().Equals((this.eleBody))).Distinct().ToList(); //过滤电极面
            List <Face> tt    = temp.Where(a => a.GetBody().Equals((this.toolBody))).Distinct().ToList();
            List <Face> faces = new List <Face>();

            foreach (Face fe in dischargeFace)
            {
                FaceData data1 = FaceUtils.AskFaceData(fe);
                foreach (Face fa in tt)
                {
                    FaceData fd = FaceUtils.AskFaceData(fa);
                    if (UMathUtils.SelfDis(data1.Dir) == 0)
                    {
                        if (data1.FaceType == fd.FaceType && data1.IntNorm == -fd.IntNorm)
                        {
                            faces.Add(fe);
                            break;
                        }
                    }
                    else
                    {
                        double anlge = UMathUtils.Angle(data1.Dir, fd.Dir);
                        if (data1.FaceType == fd.FaceType && data1.IntNorm == -fd.IntNorm && UMathUtils.IsEqual(anlge, Math.PI))
                        {
                            faces.Add(fe);
                            break;
                        }
                    }
                }
            }
            if (extract)
            {
                ExtractFace(this.toolBody, faces.ToArray());
            }
            BodyInfo info = new BodyInfo(eleBody, faces);

            info.SetAttribute(csys, matr);
            return(info);
        }