예제 #1
0
        //------------------------------------------------------------------------------
        //Callback Name: apply_cb
        //------------------------------------------------------------------------------
        public int apply_cb()
        {
            int errorCode = 0;

            try
            {
                //---- Enter your callback code here
                bool anyPartsModified1;
                NXOpen.PartSaveStatus partSaveStatus1;
                Session.GetSession().Parts.SaveAll(out anyPartsModified1, out partSaveStatus1);
                NXOpen.Assemblies.Component eleComp = this.SeleElePart.GetSelectedObjects()[0] as NXOpen.Assemblies.Component;
                string name = eleComp.Name + "-" + this.StrName.Value.ToUpper();
                if (!this.EleDuplicationOfName(name))
                {
                    this.StrName.Value = "";
                    return(0);
                }
                ElectrodeModel eleModel = new ElectrodeModel();
                eleModel.GetModelForPart(eleComp.Prototype as Part);
                name = work.WorkpieceDirectoryPath + name + ".prt";
                Vector3d movePt = new Vector3d(double_x.Value, double_y.Value, double_z.Value);
                NXOpen.Assemblies.Component copyComp = AssmbliesUtils.MoveCompCopyPart(eleComp, movePt, work.WorkMatr);
                AssmbliesUtils.MakeUnique(copyComp, name);
                ElectrodeInfo newInfo = this.SetEleInfo(eleModel.EleInfo);
                newInfo.SetAttribute(copyComp.Prototype as Part);
            }
            catch (Exception ex)
            {
                //---- Enter your exception handling code here -----
                errorCode = 1;
                theUI.NXMessageBox.Show("Block Styler", NXMessageBox.DialogType.Error, ex.ToString());
            }
            return(errorCode);
        }
예제 #2
0
        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);
        }
예제 #3
0
        private List <string> CopWork(NXOpen.Assemblies.Component ct, WorkModel work, UserModel user)
        {
            List <string> err = new List <string>();
            Matrix4       mat = new Matrix4();

            mat.Identity();

            MoldInfo       mold     = work.Info.MoldInfo.Clone() as MoldInfo;
            WorkCollection workColl = new WorkCollection(mold);

            NXOpen.Assemblies.Component moveCt = null;
            try
            {
                moveCt = AssmbliesUtils.MoveCompCopyPart(ct, new Vector3d(), mat);
            }
            catch (NXException ex)
            {
                err.Add("无法移动工件!" + ex.Message);
                return(err);
            }
            string name = work.WorkpieceDirectoryPath + mold.MoldNumber + "-" + mold.WorkpieceNumber + "-";

            if (moveCt != null)
            {
                WorkInfo wk = new WorkInfo(mold, user, work.Info.WorkNumber, work.Info.Matr);
                try
                {
                    NXObject make1 = AssmbliesUtils.MakeUnique(moveCt, name + "WORK" + (workColl.Work[workColl.Work.Count - 1].Info.WorkNumber + 1).ToString() + ".prt");
                    wk.WorkNumber = (workColl.Work[workColl.Work.Count - 1].Info.WorkNumber + 1);
                    wk.SetAttribute(moveCt.Prototype as Part);
                }
                catch (NXException ex)
                {
                    err.Add(name + "WORK" + (workColl.Work[workColl.Work.Count - 1].Info.WorkNumber + 1).ToString() + ".prt" + ex.Message + "无法创建唯一");
                }
            }

            return(err);
        }
예제 #4
0
        /// <summary>
        /// 复制work
        /// </summary>
        /// <param name="ct"></param>
        /// <param name="work"></param>
        /// <param name="workpieceNumber"></param>
        /// <param name="user"></param>
        /// <returns></returns>
        private List <string> CopyWork(NXOpen.Assemblies.Component ct, WorkModel work, string workpieceNumber, UserModel user)
        {
            List <string> err = new List <string>();
            Matrix4       mat = new Matrix4();

            mat.Identity();
            MoldInfo mold = work.Info.MoldInfo.Clone() as MoldInfo;

            NXOpen.Assemblies.Component moveCt = null;
            try
            {
                moveCt = AssmbliesUtils.MoveCompCopyPart(ct, new Vector3d(), mat);
            }
            catch (NXException ex)
            {
                err.Add("无法移动工件!" + ex.Message);
                return(err);
            }
            mold.WorkpieceNumber = workpieceNumber;
            string name = work.WorkpieceDirectoryPath + mold.MoldNumber + "-" + mold.WorkpieceNumber + "-";

            if (moveCt != null)
            {
                foreach (NXOpen.Assemblies.Component com in moveCt.GetChildren())
                {
                    if (ParentAssmblieInfo.IsParent(com))
                    {
                        ParentAssmblieInfo info1 = ParentAssmblieInfo.GetAttribute(com);
                        if (info1.Type == PartType.EDM)
                        {
                            string edmName = name + "EDM";
                            if (File.Exists(edmName + ".prt"))
                            {
                                edmName = edmName + "5";
                            }
                            EDMInfo edm = new EDMInfo(mold, user);
                            try
                            {
                                NXObject make = AssmbliesUtils.MakeUnique(com, edmName + ".prt");
                                edm.SetAttribute(com.Prototype as Part);
                                break;
                            }
                            catch (NXException ex)
                            {
                                err.Add(name + "EDM.prt" + ex.Message + "无法创建唯一");
                            }
                        }
                    }
                }
                try
                {
                    NXObject make1 = AssmbliesUtils.MakeUnique(moveCt, name + "WORK" + work.Info.WorkNumber.ToString() + ".prt");
                    WorkInfo wk    = new WorkInfo(mold, user, work.Info.WorkNumber, work.Info.Matr);
                    wk.SetAttribute(moveCt.Prototype as Part);
                }
                catch (NXException ex)
                {
                    err.Add(name + "WORK" + work.Info.WorkNumber.ToString() + ".prt" + ex.Message + "无法创建唯一");
                }
            }

            return(err);
        }