public bool PositionBuilder(Vector3d vec)
        {
            try
            {
                Matrix4 inv = this.work.Info.Matr.GetInversMatrix();
                CartesianCoordinateSystem csys        = BoundingBoxUtils.CreateCoordinateSystem(this.work.Info.Matr, inv);
                ElectrodeSetValueInfo     setValue    = ElectrodeSetValueInfo.GetAttribute(eleComp);
                ElectrodeSetValueInfo     newSetValue = setValue.Clone() as ElectrodeSetValueInfo;

                Component copyComp = AssmbliesUtils.MoveCompCopyPart(eleComp, vec, work.Info.Matr);
                NXObject  instance = AssmbliesUtils.GetOccOfInstance(copyComp.Tag);
                BodyInfo  info     = GetDischargeFace(csys, copyComp);
                newSetValue.EleSetValue[0] = setValue.EleSetValue[0] + vec.X;
                newSetValue.EleSetValue[1] = setValue.EleSetValue[1] + vec.Y;
                newSetValue.EleSetValue[2] = setValue.EleSetValue[2] + vec.Z;
                newSetValue.Positioning    = GetPositionName();
                if (info != null)
                {
                    newSetValue.ContactArea   = info.ContactArea;
                    newSetValue.ProjectedArea = info.GetProjectedArea(csys, this.work.Info.Matr);
                }

                newSetValue.SetAttribute(instance);
                return(true);
            }
            catch (NXException ex)
            {
                ClassItem.WriteLogFile("电极跑位错误!" + ex.Message);
                return(false);
            }
        }
Пример #2
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);
        }
Пример #3
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);
        }
Пример #4
0
        /// <summary>
        /// AB齿跑位
        /// </summary>
        /// <param name="eleComp"></param>
        public void MoveEleComp(NXOpen.Assemblies.Component eleComp)
        {
            for (int i = 1; i < condition.ToolhInfo.Count; i++)
            {
                Vector3d temp = new Vector3d();
                temp.X = -condition.ToolhInfo[i].Offset[0];
                temp.Y = -condition.ToolhInfo[i].Offset[1];
                temp.Z = 0;
                NXOpen.Assemblies.Component ct = AssmbliesUtils.MoveCompCopyPart(eleComp, temp, condition.Work.Info.Matr);
                NXObject instance = AssmbliesUtils.GetOccOfInstance(ct.Tag);
                ElectrodeSetValueInfo setValue = allInfo.SetValue.Clone() as ElectrodeSetValueInfo;
                setValue.EleSetValue[0] = setValue.EleSetValue[0] + temp.X;
                setValue.EleSetValue[1] = setValue.EleSetValue[1] + temp.Y;

                setValue.ContactArea   = condition.ToolhInfo[i].GetAllContactArea();
                setValue.ProjectedArea = condition.ToolhInfo[i].GetProjectedArea(condition.Work.Info.Matr);
                setValue.Positioning   = condition.ToolhInfo[i].ToolhName;
                setValue.SetAttribute(instance);
            }
        }
Пример #5
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);
        }
Пример #6
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);
        }