コード例 #1
0
        private static bool GetOperToolAttr(NXOpen.CAM.Operation item, ref OperData sOperData)
        {
            try
            {
                sOperData.OperName          = item.Name;
                sOperData.ToolNumber        = "T" + CaxOper.AskOperToolNumber(item);
                sOperData.ToolName          = CaxOper.AskOperToolNameFromTag(item.Tag);
                sOperData.HolderDescription = CaxOper.AskOperHolderDescription(item);

                sOperData.TOOL_NO     = "T" + CaxOper.AskOperToolERPNumFromAttribute(item.Tag, ToolListMember.TOOL_NO);
                sOperData.ERP_NO      = CaxOper.AskOperToolERPNumFromAttribute(item.Tag, ToolListMember.ERP_NO);
                sOperData.CUTTER_QTY  = CaxOper.AskOperToolERPNumFromAttribute(item.Tag, ToolListMember.CUTTER_QTY);
                sOperData.CUTTER_LIFE = CaxOper.AskOperToolERPNumFromAttribute(item.Tag, ToolListMember.CUTTER_LIFE);
                sOperData.FLUTE_QTY   = CaxOper.AskOperToolERPNumFromAttribute(item.Tag, ToolListMember.FLUTE_QTY);
                sOperData.TITLE       = CaxOper.AskOperToolERPNumFromAttribute(item.Tag, ToolListMember.TITLE);
                if (CaxOper.AskOperToolERPNumFromAttribute(item.Tag, ToolListMember.SPECIFICATION) != "")
                {
                    sOperData.SPECIFICATION = CaxOper.AskOperToolERPNumFromAttribute(item.Tag, ToolListMember.SPECIFICATION);
                }
                else
                {
                    sOperData.SPECIFICATION = CaxOper.AskOperToolNameFromTag(item.Tag);
                }
                sOperData.NOTE      = CaxOper.AskOperToolERPNumFromAttribute(item.Tag, ToolListMember.NOTE);
                sOperData.ACCESSORY = CaxOper.AskOperToolERPNumFromAttribute(item.Tag, ToolListMember.ACCESSORY);
            }
            catch (System.Exception ex)
            {
                return(false);
            }
            return(true);
        }
コード例 #2
0
        private void Output_Click(object sender, EventArgs e)
        {
            NXOpen.CAM.Preferences preferences1 = theSession.CAMSession.CreateCamPreferences();
            preferences1.ReplayRefreshBeforeEachPath = true;
            preferences1.Commit();
            preferences1.Destroy();

            for (int i = 0; i < OperPanel.Rows.Count; i++)
            {
                string PostName = OperPanel.GetCell(i, 2).Value.ToString();
                if (PostName == "")
                {
                    continue;
                }
                string OperName = OperPanel.GetCell(i, 1).Value.ToString();
                for (int y = 0; y < OperationObj.Length; y++)
                {
                    if (OperName != OperationObj[y].Name)
                    {
                        continue;
                    }
                    string outputpath = "";

                    //if (PostName == "Globaltek_DMU_40_eVo_Mill_turn_20151214")
                    //{
                    //    outputpath = string.Format(@"{0}\{1}", NCFolderPath, OperationObj[y].Name + ".mpf");
                    //}
                    //else if (PostName == "GLOBALTEK_DMU50_NEW_20120924" || PostName == "GLOBALTEK_DMU50_NEW_VERICUT")
                    //{
                    //    outputpath = string.Format(@"{0}\{1}", NCFolderPath, OperationObj[y].Name + ".h");
                    //}
                    //else
                    //{
                    //    outputpath = string.Format(@"{0}\{1}", NCFolderPath, OperationObj[y].Name);
                    //}

                    NCFolderPath = Path.GetFullPath(NCFolderPath);
                    if (ExtensionName.Text.Contains('.'))
                    {
                        outputpath = string.Format(@"{0}\{1}", NCFolderPath, OperationObj[y].Name + ExtensionName.Text);
                    }
                    else if (ExtensionName.Text != "")
                    {
                        outputpath = string.Format(@"{0}\{1}", NCFolderPath, OperationObj[y].Name + "." + ExtensionName.Text);
                    }
                    else
                    {
                        outputpath = string.Format(@"{0}\{1}", NCFolderPath, OperationObj[y].Name);
                    }

                    bool checkSucess = CaxOper.CreatePost(OperationObj[y], PostName, outputpath);
                    if (!checkSucess)
                    {
                        CaxLog.ShowListingWindow("程式:" + OperationObj[y].Name + "可能尚未完成,導致輸出的後處理不完全");
                    }
                    break;
                }
            }


            MessageBox.Show("後處理輸出完成!");
            //CaxLog.ShowListingWindow("後處理輸出完成!");

            /*
             * if (CurrentSelPostName == "")
             * {
             *  UI.GetUI().NXMessageBox.Show("注意", NXMessageBox.DialogType.Error, "先指定一個後處理器名稱!");
             *  return;
             * }
             *
             * foreach (NXOpen.CAM.NCGroup ncGroup in NCGroupAry)
             * {
             *  int type;
             *  int subtype;
             *  theUfSession.Obj.AskTypeAndSubtype(ncGroup.Tag, out type, out subtype);
             *  //判斷是否為Program群組
             *  if (type != UFConstants.UF_machining_task_type)
             *  {
             *      continue;
             *  }
             *
             *  //判斷是否已更名為OPXXX
             *  if (!ncGroup.Name.Contains("OP"))
             *  {
             *      UI.GetUI().NXMessageBox.Show("注意", NXMessageBox.DialogType.Error, "請先手動將Group名稱:" + ncGroup.Name + ",改為正確格式,再重新啟動功能!");
             *      this.Close();
             *      return;
             *  }
             *
             *  //選到的OP與Collection做比對
             *  if (CurrentNCGroup != ncGroup.Name)
             *  {
             *      continue;
             *  }
             *
             *  //記錄checkbox為true的OP
             *  List<string> ListSelectOP = new List<string>();
             *  for (int i = 0; i < OperPanel.Rows.Count; i++)
             *  {
             *      bool check_sel = false;
             *      check_sel = (bool)OperPanel.GetCell(i, 0).Value;
             *      if (check_sel)
             *      {
             *          ListSelectOP.Add(OperPanel.GetCell(i, 1).Value.ToString());
             *      }
             *  }
             *
             *  //取得此NC下的Operation
             *  CAMObject[] OperGroup = ncGroup.GetMembers();
             *
             *  //開始輸出後處理
             *  foreach (string i in ListSelectOP)
             *  {
             *      foreach (CAMObject y in OperGroup)
             *      {
             *          if (i != y.Name)
             *          {
             *              continue;
             *          }
             *          string outputpath = string.Format(@"{0}\{1}", NCFolderPath, y.Name);
             *          bool checkSucess = CaxOper.CreatePost(y, CurrentSelPostName, outputpath);
             *          if (!checkSucess)
             *          {
             *              CaxLog.ShowListingWindow("程式:" + y.Name + "可能尚未完成,導致輸出的後處理不完全");
             *          }
             *      }
             *  }
             * }
             */
        }
コード例 #3
0
ファイル: Function.cs プロジェクト: chiumimy/CaxGlobalTek
        public static bool GetNCProgramData(NCGroup[] NCGroupAry, out Dictionary <string, OperData> DicNCData)
        {
            DicNCData = new Dictionary <string, OperData>();
            try
            {
                foreach (NXOpen.CAM.NCGroup ncGroup in NCGroupAry)
                {
                    int type, subtype;
                    theUfSession.Obj.AskTypeAndSubtype(ncGroup.Tag, out type, out subtype);

                    //此處比對是否為Program群組
                    if (type != UFConstants.UF_machining_task_type)
                    {
                        continue;
                    }

                    if (!ncGroup.Name.Contains("OP"))
                    {
                        MessageBox.Show("請先手動將Group名稱:" + ncGroup.Name + ",改為正確格式,再重新啟動功能!");
                        return(false);
                    }

                    //取得此NCGroup下的所有Oper
                    CAMObject[] OperGroup = ncGroup.GetMembers();
                    foreach (NXOpen.CAM.Operation item in OperGroup)
                    {
                        string StockStr = "", FloorstockStr = "";
                        CaxOper.AskOperStock(item, out StockStr, out FloorstockStr);

                        bool     cheValue;
                        OperData sOperData = new OperData();
                        cheValue = DicNCData.TryGetValue(ncGroup.Name, out sOperData);
                        if (!cheValue)
                        {
                            sOperData.OperName          = item.Name;
                            sOperData.ToolName          = CaxOper.AskOperToolNameFromTag(item.Tag);
                            sOperData.HolderDescription = CaxOper.AskOperHolderDescription(item);
                            sOperData.CuttingLength     = Convert.ToDouble(CaxOper.AskOperTotalCuttingLength(item)).ToString("f3");
                            sOperData.ToolFeed          = Math.Round(Convert.ToDouble(CaxOper.AskOperToolFeed(item)), 3, MidpointRounding.AwayFromZero).ToString();
                            sOperData.CuttingTime       = Math.Ceiling((Convert.ToDouble(CaxOper.AskOperTotalCuttingTime(item)) * 60)).ToString();//因為進給單位mmpm,距離單位mm,將進給的60放來這邊乘
                            sOperData.ToolNumber        = "T" + CaxOper.AskOperToolNumber(item);
                            sOperData.ToolSpeed         = CaxOper.AskOperToolSpeed(item);
                            sOperData.PartStock         = StockStr;
                            sOperData.PartFloorStock    = FloorstockStr;
                            sOperData.CutterLife        = CaxOper.AskOperToolERPNumFromAttribute(item.Tag, "GTTL_CUTTER_LIFE");
                            sOperData.Extension         = CaxOper.AskOperToolERPNumFromAttribute(item.Tag, "GTTL_EXTENTION");
                            DicNCData.Add(ncGroup.Name, sOperData);
                        }
                        else
                        {
                            sOperData.OperName          = sOperData.OperName + "," + item.Name;
                            sOperData.ToolName          = sOperData.ToolName + "," + CaxOper.AskOperToolNameFromTag(item.Tag);
                            sOperData.HolderDescription = sOperData.HolderDescription + "," + CaxOper.AskOperHolderDescription(item);
                            sOperData.CuttingLength     = sOperData.CuttingLength + "," + Convert.ToDouble(CaxOper.AskOperTotalCuttingLength(item)).ToString("f3");
                            sOperData.ToolFeed          = sOperData.ToolFeed + "," + Math.Round(Convert.ToDouble(CaxOper.AskOperToolFeed(item)), 3, MidpointRounding.AwayFromZero).ToString();
                            sOperData.CuttingTime       = sOperData.CuttingTime + "," + Math.Ceiling((Convert.ToDouble(CaxOper.AskOperTotalCuttingTime(item)) * 60)).ToString();//因為進給單位mmpm,距離單位mm,將進給的60放來這邊乘
                            sOperData.ToolNumber        = sOperData.ToolNumber + "," + "T" + CaxOper.AskOperToolNumber(item);
                            sOperData.ToolSpeed         = sOperData.ToolSpeed + "," + CaxOper.AskOperToolSpeed(item);
                            sOperData.PartStock         = sOperData.PartStock + "," + StockStr;
                            sOperData.PartFloorStock    = sOperData.PartFloorStock + "," + FloorstockStr;
                            sOperData.CutterLife        = sOperData.CutterLife + "," + CaxOper.AskOperToolERPNumFromAttribute(item.Tag, "GTTL_CUTTER_LIFE");
                            sOperData.Extension         = sOperData.Extension + "," + CaxOper.AskOperToolERPNumFromAttribute(item.Tag, "GTTL_EXTENTION");
                            DicNCData[ncGroup.Name]     = sOperData;
                        }
                    }
                }
            }
            catch (System.Exception ex)
            {
                return(false);
            }
            return(true);
        }
コード例 #4
0
        private static void CheckRepeat(NXOpen.CAM.Operation item, ref OperData sOperData)
        {
            try
            {
                string toolNumber = "T" + CaxOper.AskOperToolNumber(item);
                //取得現有的刀號
                string[] toolNumbers = sOperData.ToolNumber.Split(',');

                string toolName = CaxOper.AskOperToolNameFromTag(item.Tag);
                string holder   = CaxOper.AskOperHolderDescription(item);
                //string toolERP = CaxOper.AskOperToolERPNumFromAttribute(item.Tag, "ToolERP");
                //string shankERP = CaxOper.AskOperToolERPNumFromAttribute(item.Tag, "ShankERP");
                //string extensionShankERP = CaxOper.AskOperToolERPNumFromAttribute(item.Tag, "ExtensionShankERP");
                //string holderERP = CaxOper.AskOperToolERPNumFromAttribute(item.Tag, "HolderERP");
                string specification = "";
                if (CaxOper.AskOperToolERPNumFromAttribute(item.Tag, ToolListMember.SPECIFICATION) != "")
                {
                    specification = CaxOper.AskOperToolERPNumFromAttribute(item.Tag, ToolListMember.SPECIFICATION);
                }
                else
                {
                    specification = CaxOper.AskOperToolNameFromTag(item.Tag);
                }

                string tool_NO     = CaxOper.AskOperToolERPNumFromAttribute(item.Tag, ToolListMember.TOOL_NO);
                string erp_NO      = CaxOper.AskOperToolERPNumFromAttribute(item.Tag, ToolListMember.ERP_NO);
                string cutter_qty  = CaxOper.AskOperToolERPNumFromAttribute(item.Tag, ToolListMember.CUTTER_QTY);
                string cutter_life = CaxOper.AskOperToolERPNumFromAttribute(item.Tag, ToolListMember.CUTTER_LIFE);
                string flute_qty   = CaxOper.AskOperToolERPNumFromAttribute(item.Tag, ToolListMember.FLUTE_QTY);
                string title       = CaxOper.AskOperToolERPNumFromAttribute(item.Tag, ToolListMember.TITLE);
                string note        = CaxOper.AskOperToolERPNumFromAttribute(item.Tag, ToolListMember.NOTE);
                //string specification = CaxOper.AskOperToolERPNumFromAttribute(item.Tag, ToolListMember.SPECIFICATION);


                #region toolNumber檢查
                bool toolNumberChk = false;
                foreach (string i in toolNumbers)
                {
                    if (toolNumber == i)
                    {
                        toolNumberChk = true;
                        break;
                    }
                }
                if (toolNumberChk)
                {
                    sOperData.ToolNumber        = sOperData.ToolNumber + "," + toolNumber;
                    sOperData.ToolName          = sOperData.ToolName + "," + "";
                    sOperData.HolderDescription = sOperData.HolderDescription + "," + "";
                    //sOperData.ToolERP = sOperData.ToolERP + "," + "";
                    //sOperData.ShankERP = sOperData.ShankERP + "," + "";
                    //sOperData.ExtensionShankERP = sOperData.ExtensionShankERP + "," + "";
                    //sOperData.HolderERP = sOperData.HolderERP + "," + "";
                    //attribute
                    sOperData.TOOL_NO       = sOperData.TOOL_NO + "," + "";
                    sOperData.ERP_NO        = sOperData.ERP_NO + "," + "";
                    sOperData.CUTTER_QTY    = sOperData.CUTTER_QTY + "," + "";
                    sOperData.CUTTER_LIFE   = sOperData.CUTTER_LIFE + "," + "";
                    sOperData.FLUTE_QTY     = sOperData.FLUTE_QTY + "," + "";
                    sOperData.TITLE         = sOperData.TITLE + "," + "";
                    sOperData.SPECIFICATION = sOperData.SPECIFICATION + "," + "";
                    sOperData.NOTE          = sOperData.NOTE + "," + "";
                }
                else
                {
                    sOperData.ToolNumber        = sOperData.ToolNumber + "," + toolNumber;
                    sOperData.ToolName          = sOperData.ToolName + "," + toolName;
                    sOperData.HolderDescription = sOperData.HolderDescription + "," + holder;
                    //sOperData.ToolERP = sOperData.ToolERP + "," + toolERP;
                    //sOperData.ShankERP = sOperData.ShankERP + "," + shankERP;
                    //sOperData.ExtensionShankERP = sOperData.ExtensionShankERP + "," + extensionShankERP;
                    //sOperData.HolderERP = sOperData.HolderERP + "," + holderERP;
                    //attribute
                    sOperData.TOOL_NO       = sOperData.TOOL_NO + "," + tool_NO;
                    sOperData.ERP_NO        = sOperData.ERP_NO + "," + erp_NO;
                    sOperData.CUTTER_QTY    = sOperData.CUTTER_QTY + "," + cutter_qty;
                    sOperData.CUTTER_LIFE   = sOperData.CUTTER_LIFE + "," + cutter_life;
                    sOperData.FLUTE_QTY     = sOperData.FLUTE_QTY + "," + flute_qty;
                    sOperData.TITLE         = sOperData.TITLE + "," + title;
                    sOperData.SPECIFICATION = sOperData.SPECIFICATION + "," + specification;
                    sOperData.NOTE          = sOperData.NOTE + "," + note;
                }
                #endregion
                //string toolName = CaxOper.AskOperToolNameFromTag(item.Tag);
                //string holder = CaxOper.AskOperHolderDescription(item);
                //string[] toolNames = sOperData.ToolName.Split(',');
                //string[] holders = sOperData.HolderDescription.Split(',');

                #region (註解)toolName檢查

                /*
                 * bool toolNameChk = false;
                 * foreach (string i in toolNames)
                 * {
                 *  if (toolName == i)
                 *  {
                 *      toolNameChk = true;
                 *  }
                 * }
                 * if (toolNameChk)
                 * {
                 *  sOperData.ToolName = sOperData.ToolName + "," + "";
                 * }
                 * else
                 * {
                 *  sOperData.ToolName = sOperData.ToolName + "," + toolName;
                 * }
                 */
                #endregion

                #region (註解)holder檢查

                /*
                 * bool holderChk = false;
                 * foreach (string i in holders)
                 * {
                 *  if (holder == i)
                 *  {
                 *      holderChk = true;
                 *  }
                 * }
                 * if (holderChk)
                 * {
                 *  sOperData.HolderDescription = sOperData.HolderDescription + "," + "";
                 * }
                 * else
                 * {
                 *  sOperData.HolderDescription = sOperData.HolderDescription + "," + holder;
                 * }
                 */
                #endregion
            }
            catch (System.Exception ex)
            {
                MessageBox.Show("判斷是否重複的刀具與刀柄失敗");
            }
        }
コード例 #5
0
        public bool Doit()
        {
            try
            {
                int module_id;
                theUfSession.UF.AskApplicationModule(out module_id);
                if (module_id != UFConstants.UF_APP_CAM)
                {
                    MessageBox.Show("請先轉換為加工模組後再執行!");
                    return(false);
                }

                if (!GetToolListPath(out ToolListPath))
                {
                    MessageBox.Show("取得ToolList.xls失敗");
                    return(false);
                }



                //取得正確路徑,拆零件路徑字串取得客戶名稱、料號、版本
                status = CaxPublic.GetAllPath("TE", displayPart.FullPath, out sPartInfo, ref cMETE_Download_Upload_Path);
                if (!status)
                {
                    Is_Local = null;
                }

                //此條件判斷是否為走系統的零件
                if (!displayPart.FullPath.Contains("Task"))
                {
                    Is_Local = null;
                }

                if (Is_Local == null)
                {
                    PartNo = Path.GetFileNameWithoutExtension(displayPart.FullPath);
                }
                else
                {
                    PartNo = sPartInfo.PartNo;
                }

                //取得所有GroupAry,用來判斷Group的Type決定是NC、Tool、Geometry
                NXOpen.CAM.NCGroup[] NCGroupAry = displayPart.CAMSetup.CAMGroupCollection.ToArray();
                //取得所有OperationAry
                NXOpen.CAM.Operation[] OperationAry = displayPart.CAMSetup.CAMOperationCollection.ToArray();

                #region 取得相關資訊,填入DIC
                DicNCData = new Dictionary <string, List <OperData> >();
                foreach (NXOpen.CAM.NCGroup ncGroup in NCGroupAry)
                {
                    if (!IsNC(ncGroup))
                    {
                        continue;
                    }

                    if (!ncGroup.Name.Contains("OP"))
                    {
                        MessageBox.Show("請先手動將Group名稱:" + ncGroup.Name + ",改為正確格式,再重新啟動功能!");
                        return(false);
                    }

                    //取得此NCGroup下的所有Oper
                    CAMObject[] OperGroup = ncGroup.GetMembers();

                    foreach (NXOpen.CAM.Operation item in OperGroup)
                    {
                        bool            cheValue;
                        List <OperData> listOperData = new List <OperData>();
                        cheValue = DicNCData.TryGetValue(ncGroup.Name, out listOperData);
                        if (!cheValue)
                        {
                            listOperData = new List <OperData>();
                        }
                        bool chk = true;
                        foreach (OperData i in listOperData)
                        {
                            if (i.ToolNumber == "T" + CaxOper.AskOperToolNumber(item))
                            {
                                chk = false;
                                break;
                            }
                        }
                        if (!chk)
                        {
                            continue;
                        }
                        OperData sOperData = new OperData();
                        GetOperToolAttr(item, ref sOperData);
                        listOperData.Add(sOperData);
                        DicNCData[ncGroup.Name] = listOperData;
                    }
                }

                //將DicNCData的key存入程式群組下拉選單中
                foreach (KeyValuePair <string, List <OperData> > kvp in DicNCData)
                {
                    comboBoxNCName.Items.Add(kvp.Key);
                }
                if (comboBoxNCName.Items.Count == 1)
                {
                    comboBoxNCName.Text = comboBoxNCName.Items[0].ToString();
                }
                #endregion
            }
            catch (System.Exception ex)
            {
                return(false);
            }
            return(true);
        }
コード例 #6
0
ファイル: PostProcessorDlg.cs プロジェクト: chiumimy/cax
        private void Output_Click(object sender, EventArgs e)
        {
            if (CurrentSelPostName == "")
            {
                UI.GetUI().NXMessageBox.Show("注意", NXMessageBox.DialogType.Error, "先指定一個後處理器名稱!");
                return;
            }

            foreach (NXOpen.CAM.NCGroup ncGroup in NCGroupAry)
            {
                int type;
                int subtype;
                theUfSession.Obj.AskTypeAndSubtype(ncGroup.Tag, out type, out subtype);
                //判斷是否為Program群組
                if (type != UFConstants.UF_machining_task_type)
                {
                    continue;
                }

                //判斷是否已更名為OPXXX
                if (!ncGroup.Name.Contains("OP"))
                {
                    UI.GetUI().NXMessageBox.Show("注意", NXMessageBox.DialogType.Error, "請先手動將Group名稱:" + ncGroup.Name + ",改為正確格式,再重新啟動功能!");
                    this.Close();
                    return;
                }

                //選到的OP與Collection做比對
                if (CurrentNCGroup != ncGroup.Name)
                {
                    continue;
                }

                //記錄checkbox為true的OP(Key=index,Value=OPName)
                List <string> ListSelectOP = new List <string>();
                for (int i = 0; i < OperPanel.Rows.Count; i++)
                {
                    bool check_sel = false;
                    check_sel = (bool)OperPanel.GetCell(i, 0).Value;
                    if (check_sel)
                    {
                        ListSelectOP.Add(OperPanel.GetCell(i, 1).Value.ToString());
                    }
                }

                //取得此OP下的Operation
                CAMObject[] OperGroup = ncGroup.GetMembers();

                //開始輸出後處理
                foreach (string i in ListSelectOP)
                {
                    foreach (CAMObject y in OperGroup)
                    {
                        if (i != y.Name)
                        {
                            continue;
                        }
                        string outputpath  = string.Format(@"{0}\{1}", NCFolderPath, y.Name);
                        bool   checkSucess = CaxOper.CreatePost(y, CurrentSelPostName, outputpath);
                        if (!checkSucess)
                        {
                            CaxLog.ShowListingWindow("程式:" + y.Name + "可能尚未完成,導致輸出的後處理不完全");
                        }
                    }
                }
            }
        }
コード例 #7
0
ファイル: MainProgramDlg.cs プロジェクト: chiumimy/cax
        private void RemoveButton_Click(object sender, EventArgs e)
        {
            if (DicSelOper.Count == 0)
            {
                this.Hide();
                UI.GetUI().NXMessageBox.Show("注意", NXMessageBox.DialogType.Warning, "請選擇程式");
                this.Show();
                return;
            }

            //判斷選到的Oper只能是listView1裡面的Oper
            foreach (KeyValuePair <int, ListViewItem> kvp in DicSelOper)
            {
                if (kvp.Value.ListView.Name == listView5.Name)
                {
                    return;
                }
                if (!kvp.Value.Text.Contains(chb_M198.Text) &
                    !kvp.Value.Text.Contains(chb_M98.Text) &
                    !kvp.Value.Text.Contains("extcall") &
                    !kvp.Value.Text.Contains("CALL PGM"))
                {
                    this.Hide();
                    UI.GetUI().NXMessageBox.Show("注意", NXMessageBox.DialogType.Warning, "如欲移除" + kvp.Value.Text + "請使用刪除功能");
                    this.Show();
                    return;
                }
            }

            #region 將listView1選到的Oper填回listView5中,並重新取得刀號

            foreach (KeyValuePair <int, ListViewItem> kvp in DicSelOper)
            {
                ListViewItem tempViewItem = new ListViewItem();
                tempViewItem.Text = kvp.Value.Text.Split()[kvp.Value.Text.Split().Length - 1];
                if (chb_Fanuc.Checked == true)
                {
                    tempViewItem.Text = tempViewItem.Text.Replace("P", "O");
                }

                /*
                 * //如果選擇發那科控制器,則取代P為O
                 * if (chb_Fanuc.Checked == true)
                 * {
                 *  //先將M98或M198移除
                 *  string splitSel = kvp.Value.Text.Split()[1];
                 *  //kvp.Value.Text = splitSel.Replace("P", "O");
                 *  tempViewItem.Text = splitSel.Replace("P", "O");
                 * }
                 */
                //如果選擇海德漢控制器,則將順序移除再填回listView5中
                //if (chb_Heidenhain.Checked == true)
                //{
                //    kvp.Value.Text = kvp.Value.Text.Split()[1];
                //    tempViewItem.Text = kvp.Value.Text;
                //}

                ListViewItem.ListViewSubItem tempViewSubItem = new ListViewItem.ListViewSubItem();
                foreach (CAMObject tempOper in OperObjAry)
                {
                    if (tempViewItem.Text == tempOper.Name)
                    {
                        tempViewSubItem = new ListViewItem.ListViewSubItem(tempViewItem, CaxOper.AskOperToolNumber((NXOpen.CAM.Operation)tempOper));
                    }
                }

                tempViewItem.SubItems.Add(tempViewSubItem);
                listView5.Items.Add(tempViewItem);
            }

            #endregion

            int count = 0;
            foreach (KeyValuePair <int, ListViewItem> kvp in DicSelOper)
            {
                foreach (ListViewItem tmpLstView in listView1.Items)
                {
                    if (kvp.Value.Text != tmpLstView.Text || kvp.Key != (tmpLstView.Index + count))
                    {
                        continue;
                    }
                    count++;
                    listView1.Items.Remove(tmpLstView);
                    listView1.Update();
                    break;
                }
            }
            DicSelOper = new Dictionary <int, ListViewItem>();
        }
コード例 #8
0
ファイル: MainProgramDlg.cs プロジェクト: chiumimy/cax
        private void ShowToolPath()
        {
            NXOpen.CAM.Preferences preferences1 = theSession.CAMSession.CreateCamPreferences();
            if (DicSelOper.Count == 1)
            {
                preferences1.ReplayRefreshBeforeEachPath = true;
                preferences1.Commit();
                preferences1.Destroy();
            }
            else if (DicSelOper.Count > 1)
            {
                preferences1.ReplayRefreshBeforeEachPath = false;
                preferences1.Commit();
                preferences1.Destroy();
            }

            foreach (NXOpen.CAM.NCGroup ncGroup in NCGroupAry)
            {
                if (CurrentNCGroup != ncGroup.Name)
                {
                    continue;
                }
                for (int i = 0; i < OperationAry.Length; i++)
                {
                    //取得父層的群組(回傳:NCGroup XXXX)
                    string NCProgramTag = OperationAry[i].GetParent(CAMSetup.View.ProgramOrder).ToString();
                    NCProgramTag = Regex.Replace(NCProgramTag, "[^0-9]", "");
                    NXOpen.CAM.CAMObject[] tempObjToCreateImg = new CAMObject[1];

                    foreach (KeyValuePair <int, ListViewItem> kvp in DicSelOper)
                    {
                        string tempOper = kvp.Value.Text;
                        //如果選擇發那科控制器,則取代P為O才能看路徑
                        if (chb_Fanuc.Checked == true)
                        {
                            tempOper = tempOper.Replace("P", "O");
                        }
                        if (tempOper.Split().Length > 1)
                        {
                            tempOper = tempOper.Split()[tempOper.Split().Length - 1];
                        }
                        if (NCProgramTag == ncGroup.Tag.ToString() && tempOper == CaxOper.AskOperNameFromTag(OperationAry[i].Tag))
                        {
                            tempObjToCreateImg[0] = (NXOpen.CAM.CAMObject)OperationAry[i];
                            workPart.CAMSetup.ReplayToolPath(tempObjToCreateImg);
                        }

                        /*
                         * if (chb_Fanuc.Checked == true)
                         * {
                         *  tempOper = tempOper.Replace("P", "O");
                         *  if (tempOper.Split().Length > 1)
                         *  {
                         *      tempOper = tempOper.Split()[tempOper.Split().Length - 1];
                         *  }
                         *  //if (NCProgramTag == ncGroup.Tag.ToString() && tempOper == CaxOper.AskOperNameFromTag(OperationAry[i].Tag))
                         *  //{
                         *  //    tempObjToCreateImg[0] = (NXOpen.CAM.CAMObject)OperationAry[i];
                         *  //    workPart.CAMSetup.ReplayToolPath(tempObjToCreateImg);
                         *  //}
                         * }
                         * else if (chb_Heidenhain.Checked == true)
                         * {
                         *  if (tempOper.Split().Length > 1)
                         *  {
                         *      tempOper = tempOper.Split()[tempOper.Split().Length - 1];
                         *  }
                         *  //if (NCProgramTag == ncGroup.Tag.ToString() && kvp.Value.Text == CaxOper.AskOperNameFromTag(OperationAry[i].Tag))
                         *  //{
                         *  //    tempObjToCreateImg[0] = (NXOpen.CAM.CAMObject)OperationAry[i];
                         *  //    workPart.CAMSetup.ReplayToolPath(tempObjToCreateImg);
                         *  //}
                         * }
                         * else if (chb_Simens.Checked == true)
                         * {
                         *  if (tempOper.Split().Length > 1)
                         *  {
                         *      tempOper = tempOper.Split()[tempOper.Split().Length - 1];
                         *  }
                         * }
                         */
                    }
                }
            }
        }
コード例 #9
0
ファイル: MainProgramDlg.cs プロジェクト: chiumimy/cax
        private void comboBoxNCgroup_SelectedIndexChanged(object sender, EventArgs e)
        {
            //清空listView資料
            listView1.Items.Clear();
            listView3.Items.Clear();
            listView4.Items.Clear();
            listView5.Items.Clear();
            //取得comboBox資料
            CurrentNCGroup = comboBoxNCgroup.Text;

            //取得選擇的NC
            foreach (NXOpen.CAM.NCGroup ncGroup in NCGroupAry)
            {
                if (CurrentNCGroup != ncGroup.Name)
                {
                    continue;
                }
                NCGroupMessage = CaxOper.AskNCGroupMessage(ncGroup);
                SelectNCGroup  = ncGroup;
            }

            //當選擇海德漢控制器時,修改檔頭檔尾
            NewGroupName = "O" + Regex.Replace(CurrentNCGroup, "[^0-9]", "") + "0";



            if (chb_Heidenhain.Checked == true)
            {
                for (int i = 0; i < cControlerConfig.Controler.Count; i++)
                {
                    if (cControlerConfig.Controler[i].CompanyName == chb_Heidenhain.Text)
                    {
                        if (cControlerConfig.Controler[i].MasterValue1 != "")
                        {
                            listView3.Items.Add(cControlerConfig.Controler[i].MasterValue1);
                        }
                        if (cControlerConfig.Controler[i].MasterValue2 != "")
                        {
                            listView4.Items.Add(cControlerConfig.Controler[i].MasterValue2);
                        }
                        if (cControlerConfig.Controler[i].MasterValue3 != "")
                        {
                            listView4.Items.Add(cControlerConfig.Controler[i].MasterValue3);
                        }
                        break;
                    }
                }

                listView3.Items[0].Text = listView3.Items[0].Text.Replace("[NCGroupName]", NewGroupName);
                listView3.Items.Add(";(" + NCGroupMessage + ")");
                listView4.Items[1].Text = listView4.Items[1].Text.Replace("[NCGroupName]", NewGroupName);
            }
            else if (chb_Fanuc.Checked == true)
            {
                for (int i = 0; i < cControlerConfig.Controler.Count; i++)
                {
                    if (cControlerConfig.Controler[i].CompanyName == chb_Fanuc.Text)
                    {
                        if (cControlerConfig.Controler[i].MasterValue1 != "")
                        {
                            ListViewItem tempViewItem = new ListViewItem(cControlerConfig.Controler[i].MasterValue1);
                            listView3.Items.Add(tempViewItem);
                        }
                        if (cControlerConfig.Controler[i].MasterValue2 != "")
                        {
                            ListViewItem tempViewItem = new ListViewItem(cControlerConfig.Controler[i].MasterValue2);
                            listView4.Items.Add(tempViewItem);
                        }
                        if (cControlerConfig.Controler[i].MasterValue3 != "")
                        {
                            ListViewItem tempViewItem = new ListViewItem(cControlerConfig.Controler[i].MasterValue3);
                            listView4.Items.Add(tempViewItem);
                        }
                        break;
                    }
                }
                listView3.Items.Add(NewGroupName + "(" + NCGroupMessage + ")");
            }

            //取得Group下的所有OP
            OperObjAry = SelectNCGroup.GetMembers();

            #region 填值到ListView5

            foreach (KeyValuePair <string, string> kvp in DicNCData)
            {
                if (CurrentNCGroup != kvp.Key)
                {
                    continue;
                }

                string[] splitOperName = kvp.Value.Split(',');

                for (int i = 0; i < splitOperName.Length; i++)
                {
                    ListViewItem tempViewItem = new ListViewItem(splitOperName[i]);
                    ListViewItem.ListViewSubItem tempViewSubItem = new ListViewItem.ListViewSubItem();
                    foreach (CAMObject tempOper in OperObjAry)
                    {
                        if (splitOperName[i] == tempOper.Name)
                        {
                            tempViewSubItem = new ListViewItem.ListViewSubItem(tempViewItem, CaxOper.AskOperToolNumber((NXOpen.CAM.Operation)tempOper));
                        }
                    }

                    tempViewItem.SubItems.Add(tempViewSubItem);
                    listView5.Items.Add(tempViewItem);
                }
            }

            #endregion
        }