Exemple #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);
        }
        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 List <string> CreateNewWork1(NXOpen.Assemblies.Component ct, WorkpieceModel workpiece, Matrix4 mat, UserModel user)
        {
            List <string> err      = new List <string>();
            MoldInfo      moldInfo = workpiece.Info.MoldInfo;
            int           num      = asmColl.GetWorkCollection(moldInfo).Work.Count;
            WorkInfo      workInfo = new WorkInfo(workpiece.Info.MoldInfo, user, num + 1, mat);
            string        workName = workInfo.MoldInfo.MoldNumber + "-" + workInfo.MoldInfo.WorkpieceNumber + "-" + "WORK" + workInfo.WorkNumber.ToString();
            EDMModel      edm      = GetEdm(ct);

            if (edm == null)
            {
                err.Add("获取EDM错误");
                return(err);
            }
            NXOpen.Assemblies.Component comp = AssmbliesUtils.MoveCompCopyPart(ct.Parent.Parent, new Vector3d(0, 0, 0), mat);
            AssmbliesUtils.MakeUnique(comp, edm.WorkpieceDirectoryPath + workName + ".prt");
            workInfo.SetAttribute(comp.Prototype as Part);
            WorkModel wm = new WorkModel(comp.Prototype as Part);

            if (wm != null)
            {
                wm.SaveCsys(workPart);
            }
            if (!edm.Info.MoldInfo.Equals(workInfo.MoldInfo))
            {
                EDMInfo edmInfo = new EDMInfo(workInfo.MoldInfo, workInfo.UserModel);
                string  edmName = edmInfo.MoldInfo.MoldNumber + "-" + edmInfo.MoldInfo.WorkpieceNumber + "-" + "EDM";
                foreach (NXOpen.Assemblies.Component cp in comp.GetChildren())
                {
                    if (ParentAssmblieInfo.IsEDM(cp))
                    {
                        AssmbliesUtils.MakeUnique(cp, edm.WorkpieceDirectoryPath + edmName + ".prt");
                        edmInfo.SetAttribute(cp.Prototype as Part);
                        foreach (NXOpen.Assemblies.Component co in cp.GetChildren())
                        {
                            if (!(co.Prototype as Part).Equals(workpiece.PartTag))
                            {
                                AssmbliesUtils.DeleteComponent(co);
                            }
                        }
                    }
                }
            }
            return(err);
        }