Example #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);
        }