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

            try
            {
                //---- Enter your callback code here -----
                NXOpen.Assemblies.Component ct = seleComp.GetSelectedObjects()[0] as NXOpen.Assemblies.Component;
                if (ParentAssmblieInfo.IsElectrode(ct))
                {
                    AlterEle(ct);
                }
                else if (ParentAssmblieInfo.IsWork(ct))
                {
                    AlterWork(ct, user.CreatorUser);
                }
                else if (ParentAssmblieInfo.IsWorkpiece(ct) || !ParentAssmblieInfo.IsParent(ct))
                {
                    AlterWorkpiece(ct, user.CreatorUser);
                }

                bool           anyPartsModified;
                PartSaveStatus saveStatus;
                theSession.Parts.SaveAll(out anyPartsModified, out saveStatus);
            }
            catch (Exception ex)
            {
                //---- Enter your exception handling code here -----
                errorCode = 1;
                theUI.NXMessageBox.Show("Block Styler", NXMessageBox.DialogType.Error, ex.ToString());
            }
            return(errorCode);
        }
Esempio n. 2
0
        /// <summary>
        /// 替换工件
        /// </summary>
        /// <param name="ct"></param>
        private void AlterWorkpiece(NXOpen.Assemblies.Component ct, UserModel user)
        {
            MoldInfo mold;

            if (!ParentAssmblieInfo.IsParent(ct))
            {
                mold = new MoldInfo()
                {
                    MoldNumber      = this.strMoldNumber.Value.ToUpper(),
                    WorkpieceNumber = this.strWorkpieceNumber.Value.ToUpper(),
                    EditionNumber   = this.strEditionNumber.Value.ToUpper()
                };
            }
            else
            {
                mold                 = MoldInfo.GetAttribute(ct);
                mold.MoldNumber      = this.strMoldNumber.Value;
                mold.WorkpieceNumber = this.strWorkpieceNumber.Value;
                mold.EditionNumber   = this.strEditionNumber.Value;
            }
            WorkPieceInfo wk      = new WorkPieceInfo(mold, user);
            string        newName = mold.MoldNumber + "-" + mold.WorkpieceNumber + "-" + mold.EditionNumber;
            Part          pt      = ct.Prototype as Part;
            ReplaceOther  ot      = new ReplaceOther(pt, wk);
            List <string> err     = ot.Alter(newName);

            if (err.Count > 0)
            {
                ClassItem.Print(err.ToArray());
            }
        }
Esempio n. 3
0
 public int filter_cb(NXOpen.BlockStyler.UIBlock block, NXOpen.TaggedObject selectedObject)
 {
     NXOpen.Assemblies.Component ct = selectedObject as NXOpen.Assemblies.Component;
     if (ct != null)
     {
         if (ParentAssmblieInfo.IsParent(ct))
         {
             return(NXOpen.UF.UFConstants.UF_UI_SEL_ACCEPT);
         }
     }
     return(NXOpen.UF.UFConstants.UF_UI_SEL_FAILURE);
 }
Esempio n. 4
0
 //------------------------------------------------------------------------------
 //Callback Name: update_cb
 //------------------------------------------------------------------------------
 public int update_cb(NXOpen.BlockStyler.UIBlock block)
 {
     try
     {
         if (block == seleComp)
         {
             //---------Enter your code here-----------
             TaggedObject[] objs = seleComp.GetSelectedObjects();
             if (objs.Length > 0)
             {
                 NXOpen.Assemblies.Component ct = objs[0] as NXOpen.Assemblies.Component;
                 if (ct != null)
                 {
                     if (ParentAssmblieInfo.IsParent(ct))
                     {
                         MoldInfo mold = MoldInfo.GetAttribute(ct);
                         this.ClientNumber.Value = mold.ClientName;
                     }
                 }
             }
         }
         else if (block == MoldNumber)
         {
             //---------Enter your code here-----------
         }
         else if (block == PartNumber)
         {
             //---------Enter your code here-----------
         }
         else if (block == EditionNumber)
         {
             //---------Enter your code here-----------
         }
         else if (block == ClientNumber)
         {
             //---------Enter your code here-----------
         }
         else if (block == enum0)
         {
             //---------Enter your code here-----------
         }
     }
     catch (Exception ex)
     {
         //---- Enter your exception handling code here -----
         theUI.NXMessageBox.Show("Block Styler", NXMessageBox.DialogType.Error, ex.ToString());
     }
     return(0);
 }
Esempio n. 5
0
 /// <summary>
 /// 获取模具号
 /// </summary>
 /// <returns></returns>
 public MoldInfo GetMoldInfo()
 {
     if (ParentAssmblieInfo.IsParent(this.pt))
     {
         return(MoldInfo.GetAttribute(this.pt));
     }
     else
     {
         return(new MoldInfo()
         {
             ClientName = "",
             EditionNumber = "",
             MachineType = "",
             MoldNumber = "",
             MoldType = "",
             WorkpieceNumber = ""
         });
     }
 }
Esempio n. 6
0
 /// <summary>
 /// 设置对话框显示
 /// </summary>
 private void SetDisp(NXOpen.Assemblies.Component ct)
 {
     if (ParentAssmblieInfo.IsElectrode(ct))
     {
         this.groupEle.Show = true;
         info = ElectrodeInfo.GetAttribute(ct);
         //this.strMoldNumber.Show = false;
         // this.strWorkpieceNumber.Show = false;
         // this.strEditionNumber.Show = false;
         this.groupWorkpiece.Show = false;
         this.groupWork.Show      = false;
         ElectrodeInfo eleInfo = info as ElectrodeInfo;
         string        temp    = info.MoldInfo.MoldNumber + "-" + info.MoldInfo.WorkpieceNumber;
         this.strEleName.Value          = temp;
         this.strEleName1.Value         = eleInfo.AllInfo.Name.EleName.Substring(temp.Length, eleInfo.AllInfo.Name.EleName.Length - temp.Length);
         this.strEleEditionNumber.Value = eleInfo.AllInfo.Name.EleEditionNumber;
     }
     else if (ParentAssmblieInfo.IsWorkpiece(ct))
     {
         info = WorkPieceInfo.GetAttribute(ct);
         this.groupWorkpiece.Show      = true;
         this.groupEle.Show            = false;
         this.groupWork.Show           = false;
         this.strMoldNumber.Value      = info.MoldInfo.MoldNumber;
         this.strWorkpieceNumber.Value = info.MoldInfo.WorkpieceNumber;
         this.strEditionNumber.Value   = info.MoldInfo.EditionNumber;
     }
     else if (ParentAssmblieInfo.IsWork(ct))
     {
         info = WorkInfo.GetAttribute(ct);
         this.groupWork.Show      = true;
         this.groupEle.Show       = false;
         this.groupWorkpiece.Show = false;
         this.intWorkNumber.Value = (info as WorkInfo).WorkNumber;
     }
     else if (!ParentAssmblieInfo.IsParent(ct))
     {
         this.groupWorkpiece.Show      = true;
         this.groupEle.Show            = false;
         this.strWorkpieceNumber.Value = ct.Name;
     }
 }
Esempio n. 7
0
        private void GetAllModel()
        {
            foreach (Part pt in Session.GetSession().Parts)
            {
                string name = pt.Name;
                if (ParentAssmblieInfo.IsParent(pt))
                {
                    ParentAssmblieInfo parent = ParentAssmblieInfo.GetAttribute(pt);
                    switch (parent.Type)
                    {
                    case PartType.ASM:
                        Asm.Add(new ASMModel(pt));
                        break;

                    case PartType.EDM:
                        Edm.Add(new EDMModel(pt));
                        break;

                    case PartType.Electrode:
                        ElectrodeModel eleModel = new ElectrodeModel(pt);
                        Electrode.Add(eleModel);
                        break;

                    case PartType.Work:
                        Work.Add(new WorkModel(pt));
                        break;

                    default:
                        Other.Add(pt);
                        break;
                    }
                }
                else
                {
                    Other.Add(pt);
                }
            }
        }
        /// <summary>
        /// 设置电极信息
        /// </summary>
        private void SetEleInfo()
        {
            DataTable table;

            try
            {
                table = ElectrodeAllInfo.CreateDataTable();
            }
            catch (Exception ex)
            {
                ClassItem.WriteLogFile("创建表列错误!" + ex.Message);
                return;
            }
            foreach (Part pt in elePart)
            {
                if (ParentAssmblieInfo.IsElectrode(pt))
                {
                    ElectrodeModel em = new ElectrodeModel(pt);
                    try
                    {
                        em.Info.AllInfo.CreateDataRow(ref table);
                    }
                    catch (Exception ex)
                    {
                        ClassItem.WriteLogFile(em.AssembleName + "          创建行错误!" + ex.Message);
                    }
                }
                else if (!ParentAssmblieInfo.IsParent(pt))
                {
                    DataRow row = table.NewRow();
                    row["EleName"] = pt.Name;
                    table.Rows.Add(row);
                }
            }
            dataGridViewEle.DataSource = table;
        }
        /// <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);
        }
Esempio n. 10
0
 /// <summary>
 /// 判断是否是工件
 /// </summary>
 /// <returns></returns>
 public bool IsWorkpiece()
 {
     return(ParentAssmblieInfo.IsWorkpiece(this.pt) || !ParentAssmblieInfo.IsParent(this.pt));
 }