private void CloseDlg_Click(object sender, EventArgs e) { NXOpen.CAM.Preferences preferences1 = theSession.CAMSession.CreateCamPreferences(); preferences1.ReplayRefreshBeforeEachPath = true; preferences1.Commit(); preferences1.Destroy(); this.Close(); }
private void SuperGridOperPanel_RowClick(object sender, GridRowClickEventArgs e) { //取得使用者選取的OP名稱 ListSelOper = new List <string>(); SelectedElementCollection OperSelCollection = OperPanel.GetSelectedElements(); foreach (GridRow item in OperSelCollection) { ListSelOper.Add(item.Cells[1].Value.ToString()); //CaxLog.ShowListingWindow(item.Cells[0].Value.ToString());//可以看出debug中item的值會顯示GridRow的型態 } //這邊設定NX中是否顯示加工路徑為->單條顯示or多條顯示 NXOpen.CAM.Preferences preferences1 = theSession.CAMSession.CreateCamPreferences(); if (ListSelOper.Count == 1) { preferences1.ReplayRefreshBeforeEachPath = true; preferences1.Commit(); preferences1.Destroy(); } else if (ListSelOper.Count > 1) { preferences1.ReplayRefreshBeforeEachPath = false; preferences1.Commit(); preferences1.Destroy(); } foreach (string SelectOper in ListSelOper) { for (int i = 0; i < OperationObj.Length; i++) { if (SelectOper == OperationObj[i].Name) { NXOpen.CAM.CAMObject[] tempObjToCreateImg = new CAMObject[1]; tempObjToCreateImg[0] = (NXOpen.CAM.CAMObject)OperationObj[i]; workPart.CAMSetup.ReplayToolPath(tempObjToCreateImg); } } } }
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 + "可能尚未完成,導致輸出的後處理不完全"); * } * } * } * } */ }
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]; * } * } */ } } } }