public static void DownArrowBtn(DevComponents.DotNetBar.ButtonX Btn) { try { Point[] pts = { new Point(0, 20), new Point(10, 20), new Point(10, 0), new Point(30, 0), new Point(30, 20), new Point(40, 20), new Point(20, 40) }; GraphicsPath polygon_path = new GraphicsPath(FillMode.Winding); polygon_path.AddPolygon(pts); Region polygon_region = new Region(polygon_path); Btn.Region = polygon_region; Btn.SetBounds(Btn.Location.X, Btn.Location.Y + 10, pts[5].X + 5, pts[6].Y + 5); } catch (System.Exception ex) { CaxLog.ShowListingWindow("箭頭按鈕建立失敗"); } }
private void SameData_CheckedChanged(object sender, EventArgs e) { if (SameData.Checked == true) { if (Gauge.Text.Contains("T")) { CaxLog.ShowListingWindow("現場量測檢具不具有【" + Gauge.Text + "】"); SelfCheck_0.Text = Freq_0.Text; SelfCheck_1.Text = Freq_1.Text; SelfCheck_Units.Text = Freq_Units.Text; return; } else { SelfCheckGauge.Text = Gauge.Text; SelfCheck_0.Text = Freq_0.Text; SelfCheck_1.Text = Freq_1.Text; SelfCheck_Units.Text = Freq_Units.Text; } } else { SelfCheckGauge.Text = ""; SelfCheck_0.Text = ""; SelfCheck_1.Text = ""; SelfCheck_Units.Text = ""; } }
private void OpRevcomboBox_SelectedIndexChanged(object sender, EventArgs e) { //清空ListView資訊 listBox1.Items.Clear(); //取得當前選取的製程版次 //CurrentOpRev = OpRevcomboBox.Text; //打開&清空下拉選單-製程序 Oper1comboBox.Enabled = true; Oper1comboBox.Items.Clear(); Oper1comboBox.Text = ""; //取得PECreateData.dat string PECreateData_Path = string.Format(@"{0}\{1}\{2}\{3}\{4}\{5}\{6}", CaxEnv.GetGlobaltekTaskDir(), comboBoxCusName.Text, PartNocomboBox.Text, CusRevcomboBox.Text, OpRevcomboBox.Text, "MODEL", "PECreateData.dat"); if (!File.Exists(PECreateData_Path)) { CaxLog.ShowListingWindow("此料號沒有舊資料檔案,請檢查PECreateData.dat"); return; } CaxPE.ReadPECreateData(PECreateData_Path, out cPECreateData); Oper1comboBox.Items.AddRange(cPECreateData.oper1Ary.ToArray()); Oper1comboBox.Items.Add("全部下載"); }
private void Gauge_SelectedIndexChanged(object sender, EventArgs e) { if (SameData.Checked == true) { if (Gauge.Text.Contains("T")) { CaxLog.ShowListingWindow("現場量測檢具沒有【" + Gauge.Text + "】"); return; } SelfCheckGauge.Text = Gauge.Text; } }
public CheckBox1() { try { CaxLog.ShowListingWindow("220"); //Checked = false; CheckedChanged += new System.EventHandler(aabb); //CaxLog.ShowListingWindow(OperPanel.GetCell(0,0).Value.ToString()); } catch (System.Exception ex) { } }
private void comboBoxOldCusRev_SelectedIndexChanged(object sender, EventArgs e) { //清空superGrid資料 panel.Rows.Clear(); //取得當前選取的客戶版次 CurrentOldCusRev = comboBoxOldCusRev.Text; //取得PECreateData.dat string PECreateData_Path = string.Format(@"{0}\{1}\{2}\{3}\{4}\{5}", CaxEnv.GetGlobaltekTaskDir(), CurrentOldCusName, CurrentOldPartNo, CurrentOldCusRev, "MODEL", "PECreateData.dat"); if (!File.Exists(PECreateData_Path)) { CaxLog.ShowListingWindow("此料號沒有舊資料檔案,請檢查PECreateData.dat"); return; } CaxPE.ReadPECreateData(PECreateData_Path, out cPECreateData); //將舊資料填入SuperGridControl GridRow row = new GridRow(); for (int i = 0; i < cPECreateData.Oper1Ary.Count; i++) { row = new GridRow(cPECreateData.Oper1Ary[i], cPECreateData.Oper2Ary[i], "刪除"); panel.Rows.Add(row); } /* * //比對選擇的客戶版次取得對應的Oper並塞入SuperGridControl * List<string> ListOper1 = new List<string>(); * List<string> ListOper2 = new List<string>(); * for (int i = 0; i < cMETEDownloadData.EntirePartAry[IndexofCusName].CusPart[IndexofPartNo].CusRev.Count; i++) * { * if (CurrentOldCusRev == cMETEDownloadData.EntirePartAry[IndexofCusName].CusPart[IndexofPartNo].CusRev[i].RevNo) * { * ListOper1 = cMETEDownloadData.EntirePartAry[IndexofCusName].CusPart[IndexofPartNo].CusRev[i].OperAry1; * ListOper2 = cMETEDownloadData.EntirePartAry[IndexofCusName].CusPart[IndexofPartNo].CusRev[i].OperAry2; * } * } * * GridRow row = new GridRow(); * for (int i = 0; i < ListOper1.Count;i++ ) * { * row = new GridRow(ListOper1[i], ListOper2[i], "刪除"); * panel.Rows.Add(row); * } */ Is_OldPart = true; }
private bool DataChecked() { try { if (DicSelDimension.Keys.Count == 0) { CaxLog.ShowListingWindow("請使用【選擇尺寸】來選擇標註尺寸!"); return(false); } if (FAIcheckBox.Checked == false & IQCcheckBox.Checked == false & IPQCcheckBox.Checked == false & FQCcheckBox.Checked == false) { MessageBox.Show("請先選擇一種檢驗報告格式!"); return(false); } if (Gauge.Text == "") { MessageBox.Show("請先選擇一種量具!"); return(false); } if (IPQCcheckBox.Checked == true) { if (Freq_0.Text == "" || Freq_1.Text == "" || Freq_Units.Text == "") { MessageBox.Show("IPQC需指定檢驗頻率!"); return(false); } } if (SameData.Checked == true) { if (SelfCheckGauge.Text == "" || SelfCheck_0.Text == "" || SelfCheck_1.Text == "" || SelfCheck_Units.Text == "") { MessageBox.Show("SelfCheck量測資料不足!"); return(false); } } } catch (System.Exception ex) { return(false); } return(true); }
private void OK_Click(object sender, EventArgs e) { try { if (MOT_File == "") { return; } BasePart newAsmPart; if (!CaxPart.OpenBaseDisplay(MOT_File, out newAsmPart)) { CaxLog.ShowListingWindow("MOT開啟失敗!"); return; } this.Close(); } catch (System.Exception ex) { } }
private void CusRevcomboBox_SelectedIndexChanged(object sender, EventArgs e) { //清空ListView資訊 listView.Items.Clear(); //取得當前選取的客戶版次 CurrentCusRev = CusRevcomboBox.Text; //打開&清空下拉選單-製程序 Oper1comboBox.Enabled = true; Oper1comboBox.Items.Clear(); Oper1comboBox.Text = ""; //取得PECreateData.dat string PECreateData_Path = string.Format(@"{0}\{1}\{2}\{3}\{4}\{5}", CaxEnv.GetGlobaltekTaskDir(), CurrentCusName, CurrentPartNo, CurrentCusRev, "MODEL", "PECreateData.dat"); if (!File.Exists(PECreateData_Path)) { CaxLog.ShowListingWindow("此料號沒有舊資料檔案,請檢查PECreateData.dat"); return; } CaxPE.ReadPECreateData(PECreateData_Path, out cPECreateData); Oper1comboBox.Items.AddRange(cPECreateData.Oper1Ary.ToArray()); Oper1comboBox.Items.Add("全部下載"); /* * //比對選擇的客戶、料號、版次取得對應的製程序並塞入下拉選單中 * for (int i = 0; i < cMETEDownloadData.EntirePartAry[IndexofCusName].CusPart[IndexofPartNo].CusRev.Count; i++ ) * { * if (CurrentCusRev == cMETEDownloadData.EntirePartAry[IndexofCusName].CusPart[IndexofPartNo].CusRev[i].RevNo) * { * Oper1comboBox.Items.AddRange(cMETEDownloadData.EntirePartAry[IndexofCusName].CusPart[IndexofPartNo].CusRev[i].OperAry1.ToArray()); * } * } * Oper1comboBox.Items.Add("全部下載"); */ }
private void buttonDownload_Click(object sender, EventArgs e) { //建立Local路徑資料 string Local_IP = cMETE_Download_Upload_Path.Local_IP; string Local_ShareStr = cMETE_Download_Upload_Path.Local_ShareStr; Local_Folder_MODEL = cMETE_Download_Upload_Path.Local_Folder_MODEL; Local_Folder_CAM = cMETE_Download_Upload_Path.Local_Folder_CAM; Local_Folder_OIS = cMETE_Download_Upload_Path.Local_Folder_OIS; //取代字串成正確路徑 Local_ShareStr = Local_ShareStr.Replace("[Local_IP]", Local_IP); Local_ShareStr = Local_ShareStr.Replace("[CusName]", CurrentCusName); Local_ShareStr = Local_ShareStr.Replace("[PartNo]", CurrentPartNo); Local_ShareStr = Local_ShareStr.Replace("[CusRev]", CurrentCusRev); Local_Folder_MODEL = Local_Folder_MODEL.Replace("[Local_ShareStr]", Local_ShareStr); Local_Folder_CAM = Local_Folder_CAM.Replace("[Local_ShareStr]", Local_ShareStr); Local_Folder_OIS = Local_Folder_OIS.Replace("[Local_ShareStr]", Local_ShareStr); #region 建立Local_Folder_MODEL資料夾 if (!File.Exists(Local_Folder_MODEL)) { try { System.IO.Directory.CreateDirectory(Local_Folder_MODEL); } catch (System.Exception ex) { MessageBox.Show(ex.ToString()); return; } } #endregion #region 複製Server客戶檔案到Local_Folder_MODEL資料夾內 //判斷客戶檔案是否存在 status = System.IO.File.Exists(Server_MODEL); if (!status) { MessageBox.Show("指定的檔案不存在,請再次確認"); return; } //建立Local_Folder_MODEL資料夾內客戶檔案路徑 string Local_CusPartFullPath = string.Format(@"{0}\{1}", Local_Folder_MODEL, Path.GetFileName(Server_MODEL)); //判斷是否存在,不存在則開始複製 if (!File.Exists(Local_CusPartFullPath)) { try { File.Copy(Server_MODEL, Local_CusPartFullPath, true); } catch (System.Exception ex) { CaxLog.ShowListingWindow("客戶檔案複製失敗"); this.Close(); } } #endregion #region 複製ShopDoc.xls到Local_Folder_MODEL資料夾內 //判斷ShopDoc.xls是否存在 if (!File.Exists(Server_ShopDoc)) { listView.Items.Add("刀具路徑與清單樣板(ShopDoc.xls)不存在,無法下載"); return; } //建立Local_Folder_MODEL資料夾內客戶檔案路徑 string Local_ShopDocFullPath = string.Format(@"{0}\{1}", Local_Folder_MODEL, Path.GetFileName(Server_ShopDoc)); //判斷是否存在,不存在則開始複製 if (!File.Exists(Local_ShopDocFullPath)) { try { File.Copy(Server_ShopDoc, Local_ShopDocFullPath, true); } catch (System.Exception ex) { CaxLog.ShowListingWindow("ShopDoc.xls下載失敗"); this.Close(); } } #endregion #region 建立Local_Folder_CAM、Local_Folder_OIS資料夾 //暫存一個tempLocal_Folder_CAM、Local_Folder_OIS,目的要讓程式每次都能有[Oper1]可取代 tempLocal_Folder_CAM = Local_Folder_CAM; tempLocal_Folder_OIS = Local_Folder_OIS; if (CurrentOper1 == "全部下載") { for (int i = 0; i < Oper1comboBox.Items.Count; i++) { if (Oper1comboBox.Items[i].ToString() == "全部下載") { continue; } Local_Folder_CAM = tempLocal_Folder_CAM; Local_Folder_OIS = tempLocal_Folder_OIS; Local_Folder_CAM = Local_Folder_CAM.Replace("[Oper1]", Oper1comboBox.Items[i].ToString()); Local_Folder_OIS = Local_Folder_OIS.Replace("[Oper1]", Oper1comboBox.Items[i].ToString()); if (!File.Exists(Local_Folder_CAM)) { try { System.IO.Directory.CreateDirectory(Local_Folder_CAM); } catch (System.Exception ex) { MessageBox.Show(ex.ToString()); return; } } if (!File.Exists(Local_Folder_OIS)) { try { System.IO.Directory.CreateDirectory(Local_Folder_OIS); } catch (System.Exception ex) { MessageBox.Show(ex.ToString()); return; } } } } else { Local_Folder_CAM = tempLocal_Folder_CAM; Local_Folder_OIS = tempLocal_Folder_OIS; Local_Folder_CAM = Local_Folder_CAM.Replace("[Oper1]", CurrentOper1); Local_Folder_OIS = Local_Folder_OIS.Replace("[Oper1]", CurrentOper1); if (!File.Exists(Local_Folder_CAM)) { try { System.IO.Directory.CreateDirectory(Local_Folder_CAM); } catch (System.Exception ex) { MessageBox.Show(ex.ToString()); return; } } if (!File.Exists(Local_Folder_OIS)) { try { System.IO.Directory.CreateDirectory(Local_Folder_OIS); } catch (System.Exception ex) { MessageBox.Show(ex.ToString()); return; } } } /* * //DicSeleOper1(Key = 製程序,Value = ServerPartPath) * foreach (KeyValuePair<string, string> kvp in DicSeleOper1) * { * Local_Folder_CAM = tempLocal_Folder_CAM; * Local_Folder_OIS = tempLocal_Folder_OIS; * Local_Folder_CAM = Local_Folder_CAM.Replace("[Oper1]", kvp.Key); * Local_Folder_OIS = Local_Folder_OIS.Replace("[Oper1]", kvp.Key); * if (!File.Exists(Local_Folder_CAM)) * { * try * { * System.IO.Directory.CreateDirectory(Local_Folder_CAM); * } * catch (System.Exception ex) * { * MessageBox.Show(ex.ToString()); * return; * } * } * if (!File.Exists(Local_Folder_OIS)) * { * try * { * System.IO.Directory.CreateDirectory(Local_Folder_OIS); * } * catch (System.Exception ex) * { * MessageBox.Show(ex.ToString()); * return; * } * } * } */ #endregion #region 複製Server製程序檔案到Local資料夾內 foreach (string i in ListDownloadPartPath) { //判斷Part檔案是否存在 if (!File.Exists(i)) { CaxLog.ShowListingWindow("製程序檔案" + Path.GetFileName(i) + "不存在,請再次確認"); //MessageBox.Show("製程序檔案" + Path.GetFileName(i) + "不存在,請再次確認"); this.Close(); } //建立Local_ShareStr資料夾內製程序檔案路徑 string Local_Oper1PartFullPath = string.Format(@"{0}\{1}", Local_ShareStr, Path.GetFileName(i)); //開始複製 try { File.Copy(i, Local_Oper1PartFullPath, true); } catch (System.Exception ex) { CaxLog.ShowListingWindow(Path.GetFileName(i) + "下載失敗"); this.Close(); } } /* * foreach (KeyValuePair<string, string> kvp in DicSeleOper1) * { * //判斷製程序檔案是否存在 * Server_TEDownloadPart = tempServer_TEDownloadPart; * Server_TEDownloadPart = Server_TEDownloadPart.Replace("[Oper1]", kvp.Key); * status = System.IO.File.Exists(Server_TEDownloadPart); * if (!status) * { * MessageBox.Show("製程序檔案" + Path.GetFileName(Server_TEDownloadPart) + "不存在,請再次確認"); * return; * } * * //建立Local_ShareStr資料夾內製程序檔案路徑 * string Local_Oper1PartFullPath = string.Format(@"{0}\{1}", Local_ShareStr, Path.GetFileName(Server_TEDownloadPart)); * * //開始複製 * File.Copy(Server_TEDownloadPart, Local_Oper1PartFullPath, true); * } */ #endregion MessageBox.Show("下載完成!"); this.Close(); }
private void PostProcessorDlg_Load(object sender, EventArgs e) { //取得所有GroupAry,用來判斷Group的Type決定是NC、Tool、Geometry NCGroupAry = displayPart.CAMSetup.CAMGroupCollection.ToArray(); //取得所有operationAry OperationAry = displayPart.CAMSetup.CAMOperationCollection.ToArray(); //建立NC資料夾 NCFolderPath = string.Format(@"{0}\{1}", Path.GetDirectoryName(displayPart.FullPath), "NC"); if (!Directory.Exists(NCFolderPath)) { System.IO.Directory.CreateDirectory(NCFolderPath); } #region 取得相關資訊,填入Dic DicNCData = new Dictionary <string, string>(); 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; } foreach (NXOpen.CAM.Operation item in OperationAry) { //取得父層的群組(回傳:NCGroup XXXX) string NCProgramTag = item.GetParent(CAMSetup.View.ProgramOrder).ToString(); NCProgramTag = Regex.Replace(NCProgramTag, "[^0-9]", ""); if (NCProgramTag == ncGroup.Tag.ToString()) { bool cheValue; string OperName = ""; cheValue = DicNCData.TryGetValue(ncGroup.Name, out OperName); if (!cheValue) { OperName = item.Name; DicNCData.Add(ncGroup.Name, OperName); } else { OperName = OperName + "," + item.Name; DicNCData[ncGroup.Name] = OperName; } } } } #endregion //將DicProgName的key存入程式群組下拉選單中 comboBoxNCgroup.Items.AddRange(DicNCData.Keys.ToArray()); #region 將控制器名稱填入SuperGridPostPanel GridRow row = new GridRow(); //-----暫時使用版本(路徑指向UG) string TemplateRoot = string.Format(@"{0}\{1}\{2}\{3}", Environment.GetEnvironmentVariable("UGII_BASE_DIR"), "MACH", "resource", "postprocessor"); string TemplatePostPath = string.Format(@"{0}\{1}", TemplateRoot, "template_post.dat"); string[] TemplatePostData = System.IO.File.ReadAllLines(TemplatePostPath); //-----發佈使用版本(Server需有MACH檔案) //string[] TemplatePostData = CaxGetDatData.GetTemplatePostData(); if (TemplatePostData.Length == 0) { CaxLog.ShowListingWindow("template_post.dat為空,請檢查!"); } for (int i = 0; i < TemplatePostData.Length; i++) { if (i > 6) { string PostName = TemplatePostData[i].Split(',')[0]; row = new GridRow(PostName); PostPanel.Rows.Add(row); } } #endregion }
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 + "可能尚未完成,導致輸出的後處理不完全"); } } } } }
private void OK_Click(object sender, EventArgs e) { if (DicSelDimension.Keys.Count == 0) { CaxLog.ShowListingWindow("請使用【選擇物件】選擇標註尺寸!"); return; } #region 選擇Assign if (chb_Assign.Checked == true) { if (FAIcheckBox.Checked == false & IQCcheckBox.Checked == false & IPQCcheckBox.Checked == false & FQCcheckBox.Checked == false) { CaxLog.ShowListingWindow("請先選擇一種檢驗報告格式!"); return; } if (Gauge.Text == "" && SelfCheckGauge.Text == "") { CaxLog.ShowListingWindow("資料不足,請先填寫【IQC】或【IPQC】或【SelfCheck】!"); return; } if (Gauge.Text != "" && (Freq_0.Text == "" || Freq_1.Text == "" || Freq_Units.Text == "")) { CaxLog.ShowListingWindow("IQC尚未填寫完畢!"); return; } if (SelfCheckGauge.Text != "" && (SelfCheck_0.Text == "" || SelfCheck_1.Text == "" || SelfCheck_Units.Text == "")) { CaxLog.ShowListingWindow("SelfCheck尚未填寫完畢!"); return; } foreach (KeyValuePair <NXObject, string> kvp in DicSelDimension) { //取得原始顏色 int oldColor = CaxME.GetDimensionColor(kvp.Key); if (oldColor == -1) { oldColor = 125; } //取得檢具顏色 GaugeData cGaugeData = new GaugeData(); if (SelfCheckGauge.Text != "") { status = DicGaugeData.TryGetValue(SelfCheckGauge.Text, out cGaugeData); if (!status) { CaxLog.ShowListingWindow("此檢具資料可能有誤"); return; } } if (Gauge.Text != "") { status = DicGaugeData.TryGetValue(Gauge.Text, out cGaugeData); if (!status) { CaxLog.ShowListingWindow("此檢具資料可能有誤"); return; } } //改變標註尺寸顏色 CaxME.SetDimensionColor(kvp.Key, Convert.ToInt32(cGaugeData.Color)); //塞屬性 kvp.Key.SetAttribute(CaxME.DimenAttr.OldColor, oldColor.ToString());//舊顏色 if (Gauge.Text != "") { if (FAIcheckBox.Checked == true) { kvp.Key.SetAttribute(CaxME.DimenAttr.FAI_Gauge, Gauge.Text);//檢具名稱 kvp.Key.SetAttribute(CaxME.DimenAttr.FAI_Freq, Freq_0.Text + "PC/" + Freq_1.Text + Freq_Units.Text); } if (IQCcheckBox.Checked == true) { kvp.Key.SetAttribute(CaxME.DimenAttr.IQC_Gauge, Gauge.Text);//檢具名稱 kvp.Key.SetAttribute(CaxME.DimenAttr.IQC_Freq, Freq_0.Text + "PC/" + Freq_1.Text + Freq_Units.Text); } if (IPQCcheckBox.Checked == true) { kvp.Key.SetAttribute(CaxME.DimenAttr.IPQC_Gauge, Gauge.Text);//檢具名稱 kvp.Key.SetAttribute(CaxME.DimenAttr.IPQC_Freq, Freq_0.Text + "PC/" + Freq_1.Text + Freq_Units.Text); } if (FQCcheckBox.Checked == true) { kvp.Key.SetAttribute(CaxME.DimenAttr.FQC_Gauge, Gauge.Text);//檢具名稱 kvp.Key.SetAttribute(CaxME.DimenAttr.FQC_Freq, Freq_0.Text + "PC/" + Freq_1.Text + Freq_Units.Text); } } if (SelfCheckGauge.Text != "") { kvp.Key.SetAttribute(CaxME.DimenAttr.SelfCheck_Gauge, SelfCheckGauge.Text); //檢具名稱 kvp.Key.SetAttribute(CaxME.DimenAttr.SelfCheck_Freq, SelfCheck_0.Text + "PC/" + SelfCheck_1.Text + SelfCheck_Units.Text); //SelfCheck } /* * //泡泡順序增加 * BallonNum++; * //取得泡泡的座標 * CaxME.BoxCoordinate TextCoordi = new CaxME.BoxCoordinate(); * Point3d CreateBallonPt = new Point3d(); * CaxME.GetTextBoxCoordinate(kvp.Key.Tag, out TextCoordi); * if (Math.Abs(TextCoordi.upper_left[0] - TextCoordi.lower_left[0]) < 0.01) * { * CreateBallonPt.X = (TextCoordi.upper_left[0] + TextCoordi.lower_left[0]) / 2 - 2; * CreateBallonPt.Y = (TextCoordi.upper_left[1] + TextCoordi.lower_left[1]) / 2; * } * else * { * CreateBallonPt.X = (TextCoordi.upper_left[0] + TextCoordi.lower_left[0]) / 2; * CreateBallonPt.Y = (TextCoordi.upper_left[1] + TextCoordi.lower_left[1]) / 2 - 2; * } * //插入泡泡 * CaxME.CreateBallonOnSheet(BallonNum.ToString(), CreateBallonPt); * //取得泡泡在圖紙的區域 * string SheetNum = ListSheet.Text, RegionX = "", RegionY = ""; * for (int i = 0; i < cCoordinateData.DraftingCoordinate.Count;i++ ) * { * string SheetSize = cCoordinateData.DraftingCoordinate[i].SheetSize; * if (Math.Ceiling(SheetHeight) != Convert.ToDouble(SheetSize.Split(',')[0]) || Math.Ceiling(SheetLength) != Convert.ToDouble(SheetSize.Split(',')[1])) * { * continue; * } * //比對X * for (int j = 0; j < cCoordinateData.DraftingCoordinate[i].RegionX.Count;j++ ) * { * string X0 = cCoordinateData.DraftingCoordinate[i].RegionX[j].X0; * string X1 = cCoordinateData.DraftingCoordinate[i].RegionX[j].X1; * if (CreateBallonPt.X >= Convert.ToDouble(X0) && CreateBallonPt.X <= Convert.ToDouble(X1)) * { * RegionX = cCoordinateData.DraftingCoordinate[i].RegionX[j].Zone; * } * } * //比對Y * for (int j = 0; j < cCoordinateData.DraftingCoordinate[i].RegionY.Count; j++) * { * string Y0 = cCoordinateData.DraftingCoordinate[i].RegionY[j].Y0; * string Y1 = cCoordinateData.DraftingCoordinate[i].RegionY[j].Y1; * if (CreateBallonPt.Y >= Convert.ToDouble(Y0) && CreateBallonPt.Y <= Convert.ToDouble(Y1)) * { * RegionY = cCoordinateData.DraftingCoordinate[i].RegionY[j].Zone; * } * } * } * //塞泡泡屬性 * kvp.Key.SetAttribute(CaxME.DimenAttr.BallonNum, BallonNum.ToString()); * kvp.Key.SetAttribute(CaxME.DimenAttr.BallonLocation, SheetNum + "-" + RegionY + RegionX); */ } } #endregion #region 選擇Remove if (chb_Remove.Checked == true) { foreach (KeyValuePair <NXObject, string> kvp in DicSelDimension) { //恢復原始顏色 string oldColor = ""; try { //第二次以上指定顏色的話,抓出來的顏色就不是內建顏色EX:125->108->186,抓到的是108 oldColor = kvp.Key.GetStringAttribute(CaxME.DimenAttr.OldColor); //內建原始顏色 oldColor = "125"; } catch (System.Exception ex) { oldColor = "125"; } CaxME.SetDimensionColor(kvp.Key, Convert.ToInt32(oldColor)); //取得泡泡資訊 string BallonNum = ""; try { BallonNum = kvp.Key.GetStringAttribute(CaxME.DimenAttr.BallonNum); } catch (System.Exception ex) { BallonNum = ""; } if (BallonNum != "") { CaxME.DeleteBallon(BallonNum); } kvp.Key.DeleteAllAttributesByType(NXObject.AttributeType.String); } } #endregion SelectObject.Text = "選擇物件(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 + "可能尚未完成,導致輸出的後處理不完全"); * } * } * } * } */ }
//------------------------------------------------------------------------------ // Explicit Activation // This entry point is used to activate the application explicitly //------------------------------------------------------------------------------ public static int Main(string[] args) { int retValue = 0; try { theProgram = new Program(); Part workPart = theSession.Parts.Work; Part displayPart = theSession.Parts.Display; bool status; DefineVariable.Is_Local = Environment.GetEnvironmentVariable("UGII_ENV_FILE"); if (DefineVariable.Is_Local != "") { //取得本機ShopDoc.xls路徑 DefineVariable.SelfCheckPath = string.Format(@"{0}\{1}\{2}", Path.GetDirectoryName(displayPart.FullPath), "MODEL", "SelfCheck.xls"); } //取得料號 string PartNo = Path.GetFileNameWithoutExtension(displayPart.FullPath); //取得日期 string CurrentDate = DateTime.Now.ToShortDateString(); int SheetCount = 0; NXOpen.Tag[] SheetTagAry = null; theUfSession.Draw.AskDrawings(out SheetCount, out SheetTagAry); DefineVariable.DicDimenData = new Dictionary <string, TextData>(); for (int i = 0; i < SheetCount; i++) { //打開Sheet並記錄所有OBJ NXOpen.Drawings.DrawingSheet CurrentSheet = (NXOpen.Drawings.DrawingSheet)NXObjectManager.Get(SheetTagAry[i]); CurrentSheet.Open(); if (i == 0) { //記錄第一張Sheet DefineVariable.FirstDrawingSheet = CurrentSheet; } DisplayableObject[] SheetObj = CurrentSheet.View.AskVisibleObjects(); foreach (DisplayableObject singleObj in SheetObj) { TextData cTextData = new TextData(); string singleObjType = singleObj.GetType().ToString(); string SelfCheck_Gauge = "", BallonNum = "", Frequency = "", Location = ""; string[] mainText; string[] dualText; #region 取SelfCheck共用屬性(泡泡值、檢具名稱、檢驗頻率、泡泡所在區域),如果都沒屬性就找下一個 try { SelfCheck_Gauge = singleObj.GetStringAttribute(CaxME.DimenAttr.IPQC_Gauge); BallonNum = singleObj.GetStringAttribute(CaxME.DimenAttr.BallonNum); Frequency = singleObj.GetStringAttribute(CaxME.DimenAttr.IPQC_Freq); Location = singleObj.GetStringAttribute(CaxME.DimenAttr.BallonLocation); } catch (System.Exception ex) { SelfCheck_Gauge = ""; } if (SelfCheck_Gauge == "") { continue; } #endregion #region 紀錄共用屬性(泡泡值、檢具名稱、檢驗頻率、泡泡所在區域) //取得泡泡值 cTextData.BallonNum = BallonNum; //取得檢具名稱 cTextData.Gauge = SelfCheck_Gauge; //取得檢驗頻率 cTextData.Frequency = Frequency; //取得泡泡所在區域 cTextData.Location = Location; #endregion if (singleObjType == "NXOpen.Annotations.VerticalDimension") { #region VerticalDimension取Text cTextData.Type = "NXOpen.Annotations.VerticalDimension"; NXOpen.Annotations.VerticalDimension temp = (NXOpen.Annotations.VerticalDimension)singleObj; temp.GetDimensionText(out mainText, out dualText); if (mainText.Length > 0) { cTextData.MainText = mainText[0]; } if (temp.GetAppendedText().GetBeforeText().Length > 0) { cTextData.BeforeText = temp.GetAppendedText().GetBeforeText()[0].ToString(); } if (temp.GetAppendedText().GetAfterText().Length > 0) { cTextData.AfterText = temp.GetAppendedText().GetAfterText()[0].ToString(); } if (temp.GetAppendedText().GetAboveText().Length > 0) { cTextData.AboveText = temp.GetAppendedText().GetAboveText()[0].ToString(); } if (temp.GetAppendedText().GetBelowText().Length > 0) { cTextData.BelowText = temp.GetAppendedText().GetBelowText()[0].ToString(); } if (temp.ToleranceType.ToString() == "BilateralOneLine") { cTextData.TolType = "BilateralOneLine"; cTextData.UpperTol = temp.UpperMetricToleranceValue.ToString(); cTextData.LowerTol = (-1 * temp.UpperMetricToleranceValue).ToString(); } #endregion } else if (singleObjType == "NXOpen.Annotations.PerpendicularDimension") { #region PerpendicularDimension取Text cTextData.Type = "NXOpen.Annotations.PerpendicularDimension"; NXOpen.Annotations.PerpendicularDimension temp = (NXOpen.Annotations.PerpendicularDimension)singleObj; temp.GetDimensionText(out mainText, out dualText); if (mainText.Length > 0) { cTextData.MainText = mainText[0]; } if (temp.GetAppendedText().GetBeforeText().Length > 0) { cTextData.BeforeText = temp.GetAppendedText().GetBeforeText()[0].ToString(); } if (temp.GetAppendedText().GetAfterText().Length > 0) { cTextData.AfterText = temp.GetAppendedText().GetAfterText()[0].ToString(); } if (temp.GetAppendedText().GetAboveText().Length > 0) { cTextData.AboveText = temp.GetAppendedText().GetAboveText()[0].ToString(); } if (temp.GetAppendedText().GetBelowText().Length > 0) { cTextData.BelowText = temp.GetAppendedText().GetBelowText()[0].ToString(); } if (temp.ToleranceType.ToString() == "BilateralOneLine") { cTextData.TolType = "BilateralOneLine"; cTextData.UpperTol = temp.UpperMetricToleranceValue.ToString(); cTextData.LowerTol = (-1 * temp.UpperMetricToleranceValue).ToString(); } #endregion } else if (singleObjType == "NXOpen.Annotations.MinorAngularDimension") { #region MinorAngularDimension取Text cTextData.Type = "NXOpen.Annotations.MinorAngularDimension"; NXOpen.Annotations.MinorAngularDimension temp = (NXOpen.Annotations.MinorAngularDimension)singleObj; temp.GetDimensionText(out mainText, out dualText); if (mainText.Length > 0) { cTextData.MainText = mainText[0]; } if (temp.GetAppendedText().GetBeforeText().Length > 0) { cTextData.BeforeText = temp.GetAppendedText().GetBeforeText()[0].ToString(); } if (temp.GetAppendedText().GetAfterText().Length > 0) { cTextData.AfterText = temp.GetAppendedText().GetAfterText()[0].ToString(); } if (temp.GetAppendedText().GetAboveText().Length > 0) { cTextData.AboveText = temp.GetAppendedText().GetAboveText()[0].ToString(); } if (temp.GetAppendedText().GetBelowText().Length > 0) { cTextData.BelowText = temp.GetAppendedText().GetBelowText()[0].ToString(); } if (temp.ToleranceType.ToString() == "BilateralOneLine") { cTextData.TolType = "BilateralOneLine"; cTextData.UpperTol = temp.UpperMetricToleranceValue.ToString(); cTextData.LowerTol = (-1 * temp.UpperMetricToleranceValue).ToString(); } #endregion } else if (singleObjType == "NXOpen.Annotations.RadiusDimension") { #region MinorAngularDimension取Text cTextData.Type = "NXOpen.Annotations.RadiusDimension"; NXOpen.Annotations.RadiusDimension temp = (NXOpen.Annotations.RadiusDimension)singleObj; temp.GetDimensionText(out mainText, out dualText); if (mainText.Length > 0) { cTextData.MainText = mainText[0]; } if (temp.GetAppendedText().GetBeforeText().Length > 0) { cTextData.BeforeText = temp.GetAppendedText().GetBeforeText()[0].ToString(); } if (temp.GetAppendedText().GetAfterText().Length > 0) { cTextData.AfterText = temp.GetAppendedText().GetAfterText()[0].ToString(); } if (temp.GetAppendedText().GetAboveText().Length > 0) { cTextData.AboveText = temp.GetAppendedText().GetAboveText()[0].ToString(); } if (temp.GetAppendedText().GetBelowText().Length > 0) { cTextData.BelowText = temp.GetAppendedText().GetBelowText()[0].ToString(); } if (temp.ToleranceType.ToString() == "BilateralOneLine") { cTextData.TolType = "BilateralOneLine"; cTextData.UpperTol = temp.UpperMetricToleranceValue.ToString(); cTextData.LowerTol = (-1 * temp.UpperMetricToleranceValue).ToString(); } #endregion } else if (singleObjType == "NXOpen.Annotations.HorizontalDimension") { #region HorizontalDimension取Text cTextData.Type = "NXOpen.Annotations.HorizontalDimension"; NXOpen.Annotations.HorizontalDimension temp = (NXOpen.Annotations.HorizontalDimension)singleObj; temp.GetDimensionText(out mainText, out dualText); if (mainText.Length > 0) { cTextData.MainText = mainText[0]; } if (temp.GetAppendedText().GetBeforeText().Length > 0) { cTextData.BeforeText = temp.GetAppendedText().GetBeforeText()[0].ToString(); } if (temp.GetAppendedText().GetAfterText().Length > 0) { cTextData.AfterText = temp.GetAppendedText().GetAfterText()[0].ToString(); } if (temp.GetAppendedText().GetAboveText().Length > 0) { cTextData.AboveText = temp.GetAppendedText().GetAboveText()[0].ToString(); } if (temp.GetAppendedText().GetBelowText().Length > 0) { cTextData.BelowText = temp.GetAppendedText().GetBelowText()[0].ToString(); } if (temp.ToleranceType.ToString() == "BilateralOneLine") { cTextData.TolType = "BilateralOneLine"; cTextData.UpperTol = temp.UpperMetricToleranceValue.ToString(); cTextData.LowerTol = (-1 * temp.UpperMetricToleranceValue).ToString(); } #endregion } else if (singleObjType == "NXOpen.Annotations.IdSymbol") { #region IdSymbol取Text cTextData.Type = "NXOpen.Annotations.IdSymbol"; NXOpen.Annotations.IdSymbol temp = (NXOpen.Annotations.IdSymbol)singleObj; #endregion } else if (singleObjType == "NXOpen.Annotations.Note") { #region Note取Text cTextData.Type = "NXOpen.Annotations.Note"; NXOpen.Annotations.Note temp = (NXOpen.Annotations.Note)singleObj; cTextData.MainText = temp.GetText()[0]; #endregion } else if (singleObjType == "NXOpen.Annotations.DraftingFcf") { #region DraftingFcf取Text NXOpen.Annotations.DraftingFcf temp = (NXOpen.Annotations.DraftingFcf)singleObj; CaxME.FcfData sFcfData = new CaxME.FcfData(); CaxME.GetFcfData(temp, out sFcfData); cTextData.Type = "NXOpen.Annotations.DraftingFcf"; cTextData.Characteristic = sFcfData.Characteristic; cTextData.ZoneShape = sFcfData.ZoneShape; cTextData.ToleranceValue = sFcfData.ToleranceValue; cTextData.MaterialModifier = sFcfData.MaterialModifier; cTextData.PrimaryDatum = sFcfData.PrimaryDatum; cTextData.PrimaryMaterialModifier = sFcfData.PrimaryMaterialModifier; cTextData.SecondaryDatum = sFcfData.SecondaryDatum; cTextData.SecondaryMaterialModifier = sFcfData.SecondaryMaterialModifier; cTextData.TertiaryDatum = sFcfData.TertiaryDatum; cTextData.TertiaryMaterialModifier = sFcfData.TertiaryMaterialModifier; #endregion } else if (singleObjType == "NXOpen.Annotations.Label") { #region Label取Text cTextData.Type = "NXOpen.Annotations.Label"; NXOpen.Annotations.Label temp = (NXOpen.Annotations.Label)singleObj; cTextData.MainText = temp.GetText()[0]; #endregion } else if (singleObjType == "NXOpen.Annotations.DraftingDatum") { #region DraftingDatum取Text cTextData.Type = "NXOpen.Annotations.DraftingDatum"; NXOpen.Annotations.DraftingDatum temp = (NXOpen.Annotations.DraftingDatum)singleObj; #endregion } else if (singleObjType == "NXOpen.Annotations.DiameterDimension") { #region DiameterDimension取Text cTextData.Type = "NXOpen.Annotations.DiameterDimension"; NXOpen.Annotations.DiameterDimension temp = (NXOpen.Annotations.DiameterDimension)singleObj; temp.GetDimensionText(out mainText, out dualText); if (mainText.Length > 0) { cTextData.MainText = mainText[0]; } if (temp.GetAppendedText().GetBeforeText().Length > 0) { cTextData.BeforeText = temp.GetAppendedText().GetBeforeText()[0].ToString(); } if (temp.GetAppendedText().GetAfterText().Length > 0) { cTextData.AfterText = temp.GetAppendedText().GetAfterText()[0].ToString(); } if (temp.GetAppendedText().GetAboveText().Length > 0) { cTextData.AboveText = temp.GetAppendedText().GetAboveText()[0].ToString(); } if (temp.GetAppendedText().GetBelowText().Length > 0) { cTextData.BelowText = temp.GetAppendedText().GetBelowText()[0].ToString(); } if (temp.ToleranceType.ToString() == "BilateralOneLine") { cTextData.TolType = "BilateralOneLine"; cTextData.UpperTol = temp.UpperMetricToleranceValue.ToString(); cTextData.LowerTol = (-1 * temp.UpperMetricToleranceValue).ToString(); } #endregion } else if (singleObjType == "NXOpen.Annotations.AngularDimension") { #region AngularDimension取Text cTextData.Type = "NXOpen.Annotations.AngularDimension"; NXOpen.Annotations.AngularDimension temp = (NXOpen.Annotations.AngularDimension)singleObj; temp.GetDimensionText(out mainText, out dualText); if (mainText.Length > 0) { cTextData.MainText = mainText[0]; } if (temp.GetAppendedText().GetBeforeText().Length > 0) { cTextData.BeforeText = temp.GetAppendedText().GetBeforeText()[0].ToString(); } if (temp.GetAppendedText().GetAfterText().Length > 0) { cTextData.AfterText = temp.GetAppendedText().GetAfterText()[0].ToString(); } if (temp.GetAppendedText().GetAboveText().Length > 0) { cTextData.AboveText = temp.GetAppendedText().GetAboveText()[0].ToString(); } if (temp.GetAppendedText().GetBelowText().Length > 0) { cTextData.BelowText = temp.GetAppendedText().GetBelowText()[0].ToString(); } if (temp.ToleranceType.ToString() == "BilateralOneLine") { cTextData.TolType = "BilateralOneLine"; cTextData.UpperTol = temp.UpperMetricToleranceValue.ToString(); cTextData.LowerTol = (-1 * temp.UpperMetricToleranceValue).ToString(); } #endregion } else if (singleObjType == "NXOpen.Annotations.CylindricalDimension") { #region CylindricalDimension取Text cTextData.Type = "NXOpen.Annotations.CylindricalDimension"; NXOpen.Annotations.CylindricalDimension temp = (NXOpen.Annotations.CylindricalDimension)singleObj; temp.GetDimensionText(out mainText, out dualText); if (mainText.Length > 0) { cTextData.MainText = mainText[0]; } if (temp.GetAppendedText().GetBeforeText().Length > 0) { cTextData.BeforeText = temp.GetAppendedText().GetBeforeText()[0].ToString(); } if (temp.GetAppendedText().GetAfterText().Length > 0) { cTextData.AfterText = temp.GetAppendedText().GetAfterText()[0].ToString(); } if (temp.GetAppendedText().GetAboveText().Length > 0) { cTextData.AboveText = temp.GetAppendedText().GetAboveText()[0].ToString(); } if (temp.GetAppendedText().GetBelowText().Length > 0) { cTextData.BelowText = temp.GetAppendedText().GetBelowText()[0].ToString(); } if (temp.ToleranceType.ToString() == "BilateralOneLine") { cTextData.TolType = "BilateralOneLine"; cTextData.UpperTol = temp.UpperMetricToleranceValue.ToString(); cTextData.LowerTol = (-1 * temp.UpperMetricToleranceValue).ToString(); } if (temp.ToleranceType.ToString() == "BilateralTwoLines") { cTextData.TolType = "BilateralOneLine"; cTextData.UpperTol = temp.UpperMetricToleranceValue.ToString(); cTextData.LowerTol = temp.LowerMetricToleranceValue.ToString(); } if (temp.ToleranceType.ToString() == "UnilateralAbove") { cTextData.TolType = "UnilateralAbove"; cTextData.UpperTol = temp.UpperMetricToleranceValue.ToString(); cTextData.LowerTol = "0"; } if (temp.ToleranceType.ToString() == "UnilateralBelow") { cTextData.TolType = "UnilateralBelow"; cTextData.UpperTol = "0"; cTextData.LowerTol = temp.LowerMetricToleranceValue.ToString(); } #endregion } else if (singleObjType == "NXOpen.Annotations.ChamferDimension") { #region ChamferDimension取Text cTextData.Type = "NXOpen.Annotations.ChamferDimension"; NXOpen.Annotations.ChamferDimension temp = (NXOpen.Annotations.ChamferDimension)singleObj; temp.GetDimensionText(out mainText, out dualText); if (mainText.Length > 0) { cTextData.MainText = mainText[0] + "X" + "45" + "<$s>"; } if (temp.GetAppendedText().GetBeforeText().Length > 0) { cTextData.BeforeText = temp.GetAppendedText().GetBeforeText()[0].ToString(); } if (temp.GetAppendedText().GetAfterText().Length > 0) { cTextData.AfterText = temp.GetAppendedText().GetAfterText()[0].ToString(); } if (temp.GetAppendedText().GetAboveText().Length > 0) { cTextData.AboveText = temp.GetAppendedText().GetAboveText()[0].ToString(); } if (temp.GetAppendedText().GetBelowText().Length > 0) { cTextData.BelowText = temp.GetAppendedText().GetBelowText()[0].ToString(); } if (temp.ToleranceType.ToString() == "BilateralOneLine") { cTextData.TolType = "BilateralOneLine"; cTextData.UpperTol = temp.UpperMetricToleranceValue.ToString(); cTextData.LowerTol = (-1 * temp.UpperMetricToleranceValue).ToString(); } if (temp.ToleranceType.ToString() == "BilateralTwoLines") { cTextData.TolType = "BilateralOneLine"; cTextData.UpperTol = temp.UpperMetricToleranceValue.ToString(); cTextData.LowerTol = temp.LowerMetricToleranceValue.ToString(); } if (temp.ToleranceType.ToString() == "UnilateralAbove") { cTextData.TolType = "UnilateralAbove"; cTextData.UpperTol = temp.UpperMetricToleranceValue.ToString(); cTextData.LowerTol = "0"; } if (temp.ToleranceType.ToString() == "UnilateralBelow") { cTextData.TolType = "UnilateralBelow"; cTextData.UpperTol = "0"; cTextData.LowerTol = temp.LowerMetricToleranceValue.ToString(); } #endregion } //計算泡泡總數 DefineVariable.BallonCount++; DefineVariable.DicDimenData[BallonNum] = cTextData; } } //設定輸出路徑--Local //string[] FolderFile = System.IO.Directory.GetFileSystemEntries(Path.GetDirectoryName(displayPart.FullPath), "*.xls"); //string OutputPath = string.Format(@"{0}\{1}", Path.GetDirectoryName(displayPart.FullPath), // Path.GetFileNameWithoutExtension(displayPart.FullPath) + "_" + "SelfCheck" + "_" + (FolderFile.Length + 1) + ".xls"); //設定輸出路徑--Server string OperNum = Regex.Replace(Path.GetFileNameWithoutExtension(displayPart.FullPath).Split('_')[1], "[^0-9]", ""); string Local_Folder_OIS = string.Format(@"{0}\{1}\{2}", Path.GetDirectoryName(displayPart.FullPath), "OP" + OperNum, "OIS"); if (!File.Exists(Local_Folder_OIS)) { System.IO.Directory.CreateDirectory(Local_Folder_OIS); } string[] FolderFile = System.IO.Directory.GetFileSystemEntries(Local_Folder_OIS, "*.xls"); List <string> ListFolderFileWithIPQC = new List <string>(); foreach (string i in FolderFile) { if (i.Contains("SelfCheck")) { ListFolderFileWithIPQC.Add(i); } } string OutputPath = string.Format(@"{0}\{1}", Local_Folder_OIS, Path.GetFileNameWithoutExtension(displayPart.FullPath) + "_" + "SelfCheck" + "_" + (ListFolderFileWithIPQC.Count + 1) + ".xls"); //檢查PC有無Excel在執行 foreach (var item in Process.GetProcesses()) { if (item.ProcessName == "EXCEL") { CaxLog.ShowListingWindow("請先關閉所有Excel再重新執行輸出,如沒有EXCEL在執行,請開啟工作管理員關閉背景EXCEL"); return(retValue); } else { continue; } } Excel.ApplicationClass x = new Excel.ApplicationClass(); Excel.Workbook book = null; Excel.Worksheet sheet = null; Excel.Range oRng = null; try { x.Visible = false; if (DefineVariable.Is_Local != "") { if (File.Exists(DefineVariable.SelfCheckPath)) { book = x.Workbooks.Open(DefineVariable.SelfCheckPath); } else { book = x.Workbooks.Open(@"D:\SelfCheck.xls"); } } else { book = x.Workbooks.Open(@"D:\SelfCheck.xls"); } sheet = (Excel.Worksheet)book.Sheets[1]; //由檢驗總數開啟符合總數的頁數 int needSheetNo = (DefineVariable.BallonCount / 11); int needSheetNo_Reserve = (DefineVariable.BallonCount % 11); if (needSheetNo_Reserve != 0) { needSheetNo++; } for (int i = 1; i < needSheetNo; i++) { sheet.Copy(System.Type.Missing, x.Workbooks[1].Worksheets[1]); } //更改每一個Sheet的名稱與頁數 for (int i = 0; i < book.Worksheets.Count; i++) { sheet = (Excel.Worksheet)book.Sheets[i + 1]; if (i == 0 && book.Worksheets.Count > 1) { sheet.Name = PartNo; oRng = (Excel.Range)sheet.Cells[4, 5]; oRng.Value = oRng.Value.ToString().Replace("1/1", "1/" + (book.Worksheets.Count).ToString()); } else { sheet.Name = PartNo + "(" + (i + 1) + ")"; oRng = (Excel.Range)sheet.Cells[4, 5]; string temp = (i + 1).ToString(); oRng.Value = oRng.Value.ToString().Replace("1/1", temp + "/" + (book.Worksheets.Count).ToString()); } } //填表 int ExcelSequenceNo = -1; for (int i = 1; i < 1000; i++) { ExcelSequenceNo++; TextData cTextData; DefineVariable.DicDimenData.TryGetValue(i.ToString(), out cTextData); if (cTextData == null) { ExcelSequenceNo--; continue; } RowColumn sRowColumn; DefineVariable.GetExcelRowColumn(ExcelSequenceNo, out sRowColumn); int currentSheet_Value = (ExcelSequenceNo / 11); int currentSheet_Reserve = (ExcelSequenceNo % 11); if (currentSheet_Value == 0) { sheet = (Excel.Worksheet)book.Sheets[1]; } else { sheet = (Excel.Worksheet)book.Sheets[currentSheet_Value + 1]; } oRng = (Excel.Range)sheet.Cells; if (cTextData.Type == "NXOpen.Annotations.DraftingFcf") { #region DraftingFcf填資料 if (cTextData.Characteristic != "") { oRng[sRowColumn.DimensionRow, sRowColumn.DimensionColumn] = DefineVariable.GetCharacteristicSymbol(cTextData.Characteristic); //oRng[sRowColumn.CharacteristicRow, sRowColumn.CharacteristicColumn] = DefineVariable.GetCharacteristicSymbol(cTextData.Characteristic); } if (cTextData.ZoneShape != "") { oRng[sRowColumn.DimensionRow, sRowColumn.DimensionColumn] = ((Excel.Range)oRng[sRowColumn.DimensionRow, sRowColumn.DimensionColumn]).Value + DefineVariable.GetZoneShapeSymbol(cTextData.ZoneShape); //oRng[sRowColumn.ZoneShapeRow, sRowColumn.ZoneShapeColumn] = DefineVariable.GetZoneShapeSymbol(cTextData.ZoneShape); } oRng[sRowColumn.DimensionRow, sRowColumn.DimensionColumn] = ((Excel.Range)oRng[sRowColumn.DimensionRow, sRowColumn.DimensionColumn]).Value + cTextData.ToleranceValue; //oRng[sRowColumn.ToleranceValueRow, sRowColumn.ToleranceValueColumn] = cTextData.ToleranceValue; if (cTextData.MaterialModifier != "" & cTextData.MaterialModifier != "None") { string ValueStr = cTextData.MaterialModifier; if (ValueStr == "LeastMaterialCondition") { ValueStr = "l"; } else if (ValueStr == "MaximumMaterialCondition") { ValueStr = "m"; } else if (ValueStr == "RegardlessOfFeatureSize") { ValueStr = "s"; } oRng[sRowColumn.DimensionRow, sRowColumn.DimensionColumn] = ((Excel.Range)oRng[sRowColumn.DimensionRow, sRowColumn.DimensionColumn]).Value + ValueStr; //oRng[sRowColumn.MaterialModifierRow, sRowColumn.MaterialModifierColumn] = ValueStr; } //Primary oRng[sRowColumn.DimensionRow, sRowColumn.DimensionColumn] = ((Excel.Range)oRng[sRowColumn.DimensionRow, sRowColumn.DimensionColumn]).Value + cTextData.PrimaryDatum; //oRng[sRowColumn.PrimaryDatumRow, sRowColumn.PrimaryDatumColumn] = cTextData.PrimaryDatum; if (cTextData.PrimaryMaterialModifier != "" & cTextData.PrimaryMaterialModifier != "None") { string ValueStr = cTextData.PrimaryMaterialModifier; if (ValueStr == "LeastMaterialCondition") { ValueStr = "l"; } else if (ValueStr == "MaximumMaterialCondition") { ValueStr = "m"; } else if (ValueStr == "RegardlessOfFeatureSize") { ValueStr = "s"; } oRng[sRowColumn.DimensionRow, sRowColumn.DimensionColumn] = ((Excel.Range)oRng[sRowColumn.DimensionRow, sRowColumn.DimensionColumn]).Value + ValueStr; //oRng[sRowColumn.PrimaryMaterialModifierRow, sRowColumn.PrimaryMaterialModifierColumn] = ValueStr; } //Secondary oRng[sRowColumn.DimensionRow, sRowColumn.DimensionColumn] = ((Excel.Range)oRng[sRowColumn.DimensionRow, sRowColumn.DimensionColumn]).Value + cTextData.SecondaryDatum; //oRng[sRowColumn.SecondaryDatumRow, sRowColumn.SecondaryDatumColumn] = cTextData.SecondaryDatum; if (cTextData.SecondaryMaterialModifier != "" & cTextData.SecondaryMaterialModifier != "None") { string ValueStr = cTextData.SecondaryMaterialModifier; if (ValueStr == "LeastMaterialCondition") { ValueStr = "l"; } else if (ValueStr == "MaximumMaterialCondition") { ValueStr = "m"; } else if (ValueStr == "RegardlessOfFeatureSize") { ValueStr = "s"; } oRng[sRowColumn.DimensionRow, sRowColumn.DimensionColumn] = ((Excel.Range)oRng[sRowColumn.DimensionRow, sRowColumn.DimensionColumn]).Value + ValueStr; //oRng[sRowColumn.SecondaryMaterialModifierRow, sRowColumn.SecondaryMaterialModifierColumn] = ValueStr; } //Tertiary oRng[sRowColumn.DimensionRow, sRowColumn.DimensionColumn] = ((Excel.Range)oRng[sRowColumn.DimensionRow, sRowColumn.DimensionColumn]).Value + cTextData.TertiaryDatum; //oRng[sRowColumn.TertiaryDatumRow, sRowColumn.TertiaryDatumColumn] = cTextData.TertiaryDatum; if (cTextData.TertiaryMaterialModifier != "" & cTextData.TertiaryMaterialModifier != "None") { string ValueStr = cTextData.TertiaryMaterialModifier; if (ValueStr == "LeastMaterialCondition") { ValueStr = "l"; } else if (ValueStr == "MaximumMaterialCondition") { ValueStr = "m"; } else if (ValueStr == "RegardlessOfFeatureSize") { ValueStr = "s"; } oRng[sRowColumn.DimensionRow, sRowColumn.DimensionColumn] = ((Excel.Range)oRng[sRowColumn.DimensionRow, sRowColumn.DimensionColumn]).Value + ValueStr; //oRng[sRowColumn.TertiaryMaterialModifierRow, sRowColumn.TertiaryMaterialModifierColumn] = ValueStr; } #endregion } else if (cTextData.Type == "NXOpen.Annotations.Label") { oRng[sRowColumn.DimensionRow, sRowColumn.DimensionColumn] = cTextData.MainText; //((Range)oRng[sRowColumn.MainTextRow, sRowColumn.MainTextColumn]).Interior.ColorIndex = 50; } else { #region Dimension填資料 if (cTextData.BeforeText != null) { oRng[sRowColumn.DimensionRow, sRowColumn.DimensionColumn] = ((Excel.Range)oRng[sRowColumn.DimensionRow, sRowColumn.DimensionColumn]).Value + DefineVariable.GetGDTWord(cTextData.BeforeText); //oRng[sRowColumn.BeforeTextRow, sRowColumn.BeforeTextColumn] = DefineVariable.GetGDTWord(cTextData.BeforeText); } oRng[sRowColumn.DimensionRow, sRowColumn.DimensionColumn] = ((Excel.Range)oRng[sRowColumn.DimensionRow, sRowColumn.DimensionColumn]).Value + DefineVariable.GetGDTWord(cTextData.MainText); //oRng[sRowColumn.MainTextRow, sRowColumn.MainTextColumn] = DefineVariable.GetGDTWord(cTextData.MainText); //Range ab = (Range)oRng[sRowColumn.MainTextRow, sRowColumn.MainTextColumn]; //ab.Interior.ColorIndex = 39; if (cTextData.UpperTol != "" & cTextData.TolType == "BilateralOneLine") { oRng[sRowColumn.DimensionRow, sRowColumn.DimensionColumn] = ((Excel.Range)oRng[sRowColumn.DimensionRow, sRowColumn.DimensionColumn]).Value + "±"; oRng[sRowColumn.DimensionRow, sRowColumn.DimensionColumn] = ((Excel.Range)oRng[sRowColumn.DimensionRow, sRowColumn.DimensionColumn]).Value + cTextData.UpperTol; string MaxMinStr = "(" + (Convert.ToDouble(cTextData.MainText) + Convert.ToDouble(cTextData.UpperTol)).ToString() + "-" + (Convert.ToDouble(cTextData.MainText) - Convert.ToDouble(cTextData.UpperTol)).ToString() + ")"; oRng[sRowColumn.DimensionRow, sRowColumn.DimensionColumn] = ((Excel.Range)oRng[sRowColumn.DimensionRow, sRowColumn.DimensionColumn]).Value + MaxMinStr; //oRng[sRowColumn.ToleranceSymbolRow, sRowColumn.ToleranceSymbolColumn] = "±"; //oRng[sRowColumn.UpperTolRow, sRowColumn.UpperTolColumn] = cTextData.UpperTol; } else if (cTextData.UpperTol != "" & cTextData.TolType == "BilateralTwoLines") { oRng[sRowColumn.DimensionRow, sRowColumn.DimensionColumn] = ((Excel.Range)oRng[sRowColumn.DimensionRow, sRowColumn.DimensionColumn]).Value + "+"; oRng[sRowColumn.DimensionRow, sRowColumn.DimensionColumn] = ((Excel.Range)oRng[sRowColumn.DimensionRow, sRowColumn.DimensionColumn]).Value + cTextData.UpperTol; oRng[sRowColumn.DimensionRow, sRowColumn.DimensionColumn] = ((Excel.Range)oRng[sRowColumn.DimensionRow, sRowColumn.DimensionColumn]).Value + "/"; oRng[sRowColumn.DimensionRow, sRowColumn.DimensionColumn] = ((Excel.Range)oRng[sRowColumn.DimensionRow, sRowColumn.DimensionColumn]).Value + cTextData.LowerTol; string MaxMinStr = "(" + (Convert.ToDouble(cTextData.MainText) + Convert.ToDouble(cTextData.UpperTol)).ToString() + "-" + (Convert.ToDouble(cTextData.MainText) + Convert.ToDouble(cTextData.LowerTol)).ToString() + ")"; oRng[sRowColumn.DimensionRow, sRowColumn.DimensionColumn] = ((Excel.Range)oRng[sRowColumn.DimensionRow, sRowColumn.DimensionColumn]).Value + MaxMinStr; } else if (cTextData.UpperTol != "" & cTextData.TolType == "UnilateralAbove") { oRng[sRowColumn.DimensionRow, sRowColumn.DimensionColumn] = ((Excel.Range)oRng[sRowColumn.DimensionRow, sRowColumn.DimensionColumn]).Value + "+"; oRng[sRowColumn.DimensionRow, sRowColumn.DimensionColumn] = ((Excel.Range)oRng[sRowColumn.DimensionRow, sRowColumn.DimensionColumn]).Value + cTextData.UpperTol; } else if (cTextData.UpperTol != "" & cTextData.TolType == "UnilateralBelow") { //oRng[sRowColumn.DimensionRow, sRowColumn.DimensionColumn] = ((Excel.Range)oRng[sRowColumn.DimensionRow, sRowColumn.DimensionColumn]).Value + "-"; oRng[sRowColumn.DimensionRow, sRowColumn.DimensionColumn] = ((Excel.Range)oRng[sRowColumn.DimensionRow, sRowColumn.DimensionColumn]).Value + cTextData.LowerTol; } #endregion } #region 檢具、頻率、Max、Min、泡泡、泡泡位置、料號、日期 oRng[sRowColumn.GaugeRow, sRowColumn.GaugeColumn] = cTextData.Gauge; oRng[sRowColumn.FrequencyRow, sRowColumn.FrequencyColumn] = cTextData.Frequency; oRng[sRowColumn.BallonRow, sRowColumn.BallonColumn] = cTextData.BallonNum; oRng[sRowColumn.LocationRow, sRowColumn.LocationColumn] = cTextData.Location; oRng[sRowColumn.PartNoRow, sRowColumn.PartNoColumn] = PartNo; oRng[sRowColumn.DateRow, sRowColumn.DateColumn] = CurrentDate; #endregion } book.SaveAs(OutputPath, Excel.XlFileFormat.xlWorkbookNormal, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Excel.XlSaveAsAccessMode.xlNoChange, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing); book.Close(Type.Missing, Type.Missing, Type.Missing); x.Quit(); //切回第一張Sheet DefineVariable.FirstDrawingSheet.Open(); UI.GetUI().NXMessageBox.Show("SelfCheck", NXMessageBox.DialogType.Information, "輸出完成"); theProgram.Dispose(); } catch (System.Exception ex) { book.SaveAs(OutputPath, Excel.XlFileFormat.xlWorkbookNormal, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Excel.XlSaveAsAccessMode.xlNoChange, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing); book.Close(Type.Missing, Type.Missing, Type.Missing); x.Quit(); } } catch (NXOpen.NXException ex) { // ---- Enter your exception handling code here ----- } return(retValue); }
private void AssignGaugeDlg_Load(object sender, EventArgs e) { try { int module_id; theUfSession.UF.AskApplicationModule(out module_id); if (module_id != UFConstants.UF_APP_DRAFTING) { MessageBox.Show("請先轉換為製圖模組後再執行!"); this.Close(); } Is_Local = Environment.GetEnvironmentVariable("UGII_ENV_FILE"); if (Is_Local != null) { //取得AssignGaugeData status = CaxGetDatData.GetAssignGaugeData(out AGData); if (!status) { CaxLog.ShowListingWindow("GetAssignGaugeData失敗,請檢查MEConfig是否有檔案"); return; } //取得圖紙範圍資料Data status = CaxGetDatData.GetDraftingCoordinateData(out cCoordinateData); //取得PRODUCT資料(未完成,資料庫還沒建立) ISession session = MyHibernateHelper.SessionFactory.OpenSession(); IList <Sys_Product> sysProduct = session.QueryOver <Sys_Product>().List <Sys_Product>(); foreach (Sys_Product i in sysProduct) { listProduct.Add(i.productName); } } else { //取得AssignGaugeData string AssignGaugeData_dat = "AssignGaugeData.dat"; string AssignGaugeData_Path = string.Format(@"{0}\{1}", "D:", AssignGaugeData_dat); AGData = System.IO.File.ReadAllLines(AssignGaugeData_Path); //取得圖紙範圍資料Data string DraftingCoordinate_dat = "DraftingCoordinate.dat"; string DraftingCoordinate_Path = string.Format(@"{0}\{1}", "D:", DraftingCoordinate_dat); if (!System.IO.File.Exists(DraftingCoordinate_Path)) { MessageBox.Show("路徑:" + DraftingCoordinate_Path + "不存在"); return; } CaxPublic.ReadCoordinateData(DraftingCoordinate_Path, out cCoordinateData); } //預設關閉選擇物件 //SelectDimen.Enabled = false; #region 存AGData到DicGaugeData中 foreach (string Row in AGData) { string[] splitRow = Row.Split(','); if (splitRow.Length == 0) { continue; } GaugeData cGaugeData = new GaugeData(); status = DicGaugeData.TryGetValue(splitRow[1], out cGaugeData); if (status) { continue; } cGaugeData = new GaugeData(); cGaugeData.Color = splitRow[0]; try { cGaugeData.EngName = splitRow[2]; } catch (System.Exception ex) { cGaugeData.EngName = ""; } DicGaugeData.Add(splitRow[1], cGaugeData); } #endregion //填檢具到下拉選單中 //Gauge.Items.Add(""); //Gauge.Items.AddRange(DicGaugeData.Keys.ToArray()); //填檢具到SelfCheck下拉選單中 //SelfCheckGauge.Items.Add(""); //foreach (KeyValuePair<string,GaugeData> kvp in DicGaugeData) //{ // if (kvp.Key.Contains("T")) // { // continue; // } // SelfCheckGauge.Items.Add(kvp.Key); //} //取得sheet並填入下拉選單中 int SheetCount = 0; NXOpen.Tag[] SheetTagAry = null; theUfSession.Draw.AskDrawings(out SheetCount, out SheetTagAry); for (int i = 0; i < SheetCount; i++) { NXOpen.Drawings.DrawingSheet CurrentSheet = (NXOpen.Drawings.DrawingSheet)NXObjectManager.Get(SheetTagAry[i]); ListSheet.Items.Add(CurrentSheet.Name); } //預設開啟sheet1圖紙 NXOpen.Drawings.DrawingSheet DefaultSheet = (NXOpen.Drawings.DrawingSheet)NXObjectManager.Get(SheetTagAry[0]); ListSheet.Text = DefaultSheet.Name; //取得圖紙長寬 SheetLength = DefaultSheet.Length; SheetHeight = DefaultSheet.Height; //填入IQC、IPQC與SelfCheck的單位 //string[] CheckUnits = new string[] { "HRS", "PCS", "100%" }; //Freq_Units.Items.AddRange(CheckUnits.ToArray()); //SelfCheck_Units.Items.AddRange(CheckUnits.ToArray()); } catch (System.Exception ex) { MessageBox.Show(ex.ToString()); } }
private void OK_Click(object sender, EventArgs e) { //Part上傳 List <string> ListPartName = new List <string>(); string[] PartText; foreach (KeyValuePair <string, PartDirData> kvp in DicPartDirData) { //判斷Part是否存在 if (!File.Exists(kvp.Value.PartLocalDir)) { CaxLog.ShowListingWindow("Part不存在,無法上傳"); return; } try { File.Copy(kvp.Value.PartLocalDir, kvp.Value.PartServer1Dir, true); } catch (System.Exception ex) { CaxLog.ShowListingWindow(Path.GetFileName(kvp.Value.PartLocalDir) + "上傳失敗"); this.Close(); } ListPartName.Add(kvp.Key + ".prt"); } PartText = ListPartName.ToArray(); System.IO.File.WriteAllLines(string.Format(@"{0}\{1}", Server_OP_Folder, "PartNameText_CAM.txt"), PartText); //Excel上傳 if (File.Exists(sExcelDirData.ExcelShopDocLocalDir)) { try { File.Copy(sExcelDirData.ExcelShopDocLocalDir, sExcelDirData.ExcelShopDocServerDir, true); } catch (System.Exception ex) { CaxLog.ShowListingWindow("ShopDoc.xls上傳失敗"); this.Close(); } } //NC上傳 //判斷NC是否存在 if (Directory.Exists(sNCProgramDirData.NCProgramLocalDir)) { try { CaxPublic.DirectoryCopy(sNCProgramDirData.NCProgramLocalDir, sNCProgramDirData.NCProgramServerDir, true); } catch (System.Exception ex) { CaxLog.ShowListingWindow("NC上傳失敗"); this.Close(); } } MessageBox.Show("上傳完成!"); this.Close(); }
private void buttonOpenTask_Click(object sender, EventArgs e) { #region (註解)檢查是否有選擇組裝方式 /* * if (SeleOperValue == "001") * { * if (check001HasBillet.Checked == false && check001NoBillet.Checked == false) * { * MessageBox.Show("請選擇一種組裝方式"); * return; * } * if (check001HasBillet.Checked == true && check001NoBillet.Checked == false) * { * if (label001.Text == "") * { * MessageBox.Show("請選擇一個零件當作胚料檔,或勾選無胚料檔"); * return; * } * } * } * else if (SeleOperValue == "900") * { * * } * else * { * if (checkWHasBillet.Checked == false && checkWNoBillet.Checked == false) * { * MessageBox.Show("請選擇一種組裝方式"); * return; * } * if (checkWHasBillet.Checked == true && checkWHasBillet.Checked == false) * { * if (labelW.Text == "") * { * MessageBox.Show("請選擇一個前段工序檔當作此工序零件檔,或勾選無前段工序檔"); * return; * } * } * } */ #endregion if (SelePartName == "") { MessageBox.Show("請選擇欲開啟的零件!"); return; } string Local_CAMPartFullPath = string.Format(@"{0}\{1}\{2}\{3}\{4}\{5}", CaxEnv.GetLocalTaskDir(), comboBoxCus.Text, comboBoxPartNo.Text, comboBoxCusVer.Text, comboBoxOpVer.Text, SelePartName); //組件存在,直接開啟任務組立 BasePart newAsmPart; status = CaxPart.OpenBaseDisplay(Local_CAMPartFullPath, out newAsmPart); if (!status) { CaxLog.ShowListingWindow("組立開啟失敗!"); return; } /* * //判斷組件是否曾經被開啟。如已被開啟過,則開啟檔案後離開;反之則塞上屬性(Title=IsOpend,Value=Y)並組裝客戶零件與胚料零件 * string checkIsOpened = ""; * try * { * checkIsOpened = newAsmPart.GetStringAttribute("ISOPENED"); * if (checkIsOpened == "Y") * { * CaxPart.Save(); * this.Close(); * return; * } * } * catch (System.Exception ex) * { * newAsmPart.SetAttribute("ISOPENED", "Y"); * } * * NXOpen.Assemblies.Component newComponent = null; * #region 組裝客戶檔案 * * string Local_NewModelPartFullPath = string.Format(@"{0}\{1}\{2}\{3}\{4}", CaxEnv.GetLocalTaskDir(), * CurrentCusName, * CurrentPartNo, * CurrentCusVer, * CurrentPartNo + ".prt"); * //判斷是否已經有客戶檔案,如果沒有則複製過來 * if (!System.IO.File.Exists(Local_NewModelPartFullPath)) * { * File.Copy(Local_ModelPartFullPath, Local_NewModelPartFullPath, true); * } * * status = CaxAsm.AddComponentToAsmByDefault(Local_NewModelPartFullPath, out newComponent); * if (!status) * { * CaxLog.ShowListingWindow("ERROR,組裝失敗!"); * return; * } * #endregion * * CaxAsm.SetWorkComponent(null); * #region 建立三階製程檔 * * string Local_CurrentOperPartFullPath = ""; * if (groupBox001.Enabled == true) * { * if (check001NoBillet.Checked == true) * { * //選擇無胚料檔--新建檔案(檔名:料號_TE_製程序) * Local_CurrentOperPartFullPath = string.Format(@"{0}\{1}", Local_ShareStrPartFullPath, CurrentPartNo + "_TE_" + SeleOperValue + ".prt"); * if (!System.IO.File.Exists(Local_CurrentOperPartFullPath)) * { * status = CaxAsm.CreateNewEmptyComp(Local_CurrentOperPartFullPath, out newComponent); * if (!status) * { * CaxLog.ShowListingWindow("建立二階製程檔失敗"); * return; * } * } * } * else * { * //選擇有胚料檔--組裝胚料檔(檔名:胚料檔原始名稱) * Local_CurrentOperPartFullPath = string.Format(@"{0}\{1}", Local_ShareStrPartFullPath, label001.Text); * if (!System.IO.File.Exists(Local_CurrentOperPartFullPath)) * { * status = CaxAsm.AddComponentToAsmByDefault(Local_CurrentOperPartFullPath, out newComponent); * if (!status) * { * CaxLog.ShowListingWindow("001胚料檔組裝失敗"); * return; * } * } * } * } * else if (groupBox900.Enabled == true) * { * } * else * { #region W階 * //組立"前段製程檔" * if (checkWHasBillet.Checked == true & System.IO.File.Exists(labelWBilletPath)) * { * //複製檔案到任務資料夾 * string tempBilletPath = labelWBilletPath; * tempBilletPath = tempBilletPath.Replace(Path.GetDirectoryName(tempBilletPath), Path.GetDirectoryName(Local_NewModelPartFullPath)); * File.Copy(labelWBilletPath, tempBilletPath, true); * * status = CaxAsm.AddComponentToAsmByDefault(tempBilletPath, out newComponent); * if (!status) * { * CaxLog.ShowListingWindow("W階胚料檔組裝失敗"); * return; * } * } * * //選擇無前段製程檔案--新建檔案(檔名:料號_TE_製程序) * Local_CurrentOperPartFullPath = string.Format(@"{0}\{1}", Local_ShareStrPartFullPath, CurrentPartNo + "_TE_" + SeleOperValue + ".prt"); * if (!System.IO.File.Exists(Local_CurrentOperPartFullPath)) * { * status = CaxAsm.CreateNewEmptyComp(Local_CurrentOperPartFullPath, out newComponent); * if (!status) * { * CaxLog.ShowListingWindow("建立三階製程檔失敗"); * return; * } * } #endregion * } * #endregion */ CaxPart.Save(); this.Close(); }
private void buttonOpenTask_Click(object sender, EventArgs e) { #region 檢查是否有選擇組裝方式 if (SeleOperValue == "001") { if (check001HasBillet.Checked == false && check001NoBillet.Checked == false) { MessageBox.Show("請選擇一種組裝方式"); return; } if (check001HasBillet.Checked == true && check001NoBillet.Checked == false) { if (label001.Text == "") { MessageBox.Show("請選擇一個零件當作胚料檔,或勾選無胚料檔"); return; } } } else if (SeleOperValue == "900") { } else { if (checkWHasBillet.Checked == false && checkWNoBillet.Checked == false) { MessageBox.Show("請選擇一種組裝方式"); return; } if (checkWHasBillet.Checked == true && checkWHasBillet.Checked == false) { if (labelW.Text == "") { MessageBox.Show("請選擇一個前段工序檔當作此工序零件檔,或勾選無前段工序檔"); return; } } } #endregion string Local_CAMPartFullPath = string.Format(@"{0}\{1}\{2}\{3}\{4}", CaxEnv.GetLocalTaskDir(), CurrentCusName, CurrentPartNo, CurrentCusVer, SelePartName); string Local_ModelPartFullPath = string.Format(@"{0}\{1}\{2}\{3}\{4}\{5}", CaxEnv.GetLocalTaskDir(), CurrentCusName, CurrentPartNo, CurrentCusVer, "MODEL", CurrentPartNo + ".prt"); string Local_ShareStrPartFullPath = string.Format(@"{0}\{1}\{2}\{3}", CaxEnv.GetLocalTaskDir(), CurrentCusName, CurrentPartNo, CurrentCusVer); //組件存在,直接開啟任務組立 BasePart newAsmPart; status = CaxPart.OpenBaseDisplay(Local_CAMPartFullPath, out newAsmPart); if (!status) { CaxLog.ShowListingWindow("組立開啟失敗!"); return; } //判斷組件是否曾經被開啟。如已被開啟過,則開啟檔案後離開;反之則塞上屬性(Title=IsOpend,Value=Y)並組裝客戶零件與胚料零件 string checkIsOpened = ""; try { checkIsOpened = newAsmPart.GetStringAttribute("IsOpened"); if (checkIsOpened == "Y") { CaxPart.Save(); this.Close(); return; } } catch (System.Exception ex) { newAsmPart.SetAttribute("IsOpened", "Y"); } NXOpen.Assemblies.Component newComponent = null; #region 組裝客戶檔案 string Local_NewModelPartFullPath = string.Format(@"{0}\{1}\{2}\{3}\{4}", CaxEnv.GetLocalTaskDir(), CurrentCusName, CurrentPartNo, CurrentCusVer, CurrentPartNo + ".prt"); //判斷是否已經有客戶檔案,如果沒有則複製過來 if (!System.IO.File.Exists(Local_NewModelPartFullPath)) { File.Copy(Local_ModelPartFullPath, Local_NewModelPartFullPath, true); } status = CaxAsm.AddComponentToAsmByDefault(Local_NewModelPartFullPath, out newComponent); if (!status) { CaxLog.ShowListingWindow("ERROR,組裝失敗!"); return; } #endregion CaxAsm.SetWorkComponent(null); #region 建立二階製程檔 string Local_CurrentOperPartFullPath = ""; if (groupBox001.Enabled == true) { if (check001NoBillet.Checked == true) { //選擇無胚料檔--新建檔案(檔名:料號+製程序) Local_CurrentOperPartFullPath = string.Format(@"{0}\{1}", Local_ShareStrPartFullPath, CurrentPartNo + "_TE_" + SeleOperValue + ".prt"); if (!System.IO.File.Exists(Local_CurrentOperPartFullPath)) { status = CaxAsm.CreateNewEmptyComp(Local_CurrentOperPartFullPath, out newComponent); if (!status) { CaxLog.ShowListingWindow("建立二階製程檔失敗"); return; } } } else { //選擇有胚料檔--組裝胚料檔(檔名:胚料檔原始名稱) Local_CurrentOperPartFullPath = string.Format(@"{0}\{1}", Local_ShareStrPartFullPath, label001.Text); if (!System.IO.File.Exists(Local_CurrentOperPartFullPath)) { status = CaxAsm.AddComponentToAsmByDefault(Local_CurrentOperPartFullPath, out newComponent); if (!status) { CaxLog.ShowListingWindow("001胚料檔組裝失敗"); return; } } } } else if (groupBox900.Enabled == true) { } else { if (checkWNoBillet.Checked == true) { //選擇無胚料檔--新建檔案(檔名:料號+製程序) Local_CurrentOperPartFullPath = string.Format(@"{0}\{1}", Local_ShareStrPartFullPath, CurrentPartNo + "_TE_" + SeleOperValue + ".prt"); if (!System.IO.File.Exists(Local_CurrentOperPartFullPath)) { status = CaxAsm.CreateNewEmptyComp(Local_CurrentOperPartFullPath, out newComponent); if (!status) { CaxLog.ShowListingWindow("建立二階製程檔失敗"); return; } } } else { //選擇有胚料檔--組裝胚料檔(檔名:胚料檔原始名稱) Local_CurrentOperPartFullPath = string.Format(@"{0}\{1}", Local_ShareStrPartFullPath, labelW.Text); if (!System.IO.File.Exists(Local_CurrentOperPartFullPath)) { status = CaxAsm.AddComponentToAsmByDefault(Local_CurrentOperPartFullPath, out newComponent); if (!status) { CaxLog.ShowListingWindow("W階胚料檔組裝失敗"); return; } } } } #endregion CaxPart.Save(); this.Close(); }
private void AssignGaugeDlg_Load(object sender, EventArgs e) { /* * //取回目前泡泡最大值 * try * { * BallonNum = Convert.ToInt32(workPart.GetStringAttribute(CaxME.DimenAttr.BallonNum)); * } * catch (System.Exception ex) * { * BallonNum = 0; * } */ //預設關閉選擇物件 SelectObject.Enabled = false; //取得AssignGaugeData string[] AGData = new string[] { }; status = CaxGetDatData.GetAssignGaugeData(out AGData); if (!status) { CaxLog.ShowListingWindow("GetAssignGaugeData失敗,請檢查MEConfig是否有檔案"); return; } #region 存AGData到DicGaugeData中 foreach (string Row in AGData) { string[] splitRow = Row.Split(','); if (splitRow.Length == 0) { continue; } GaugeData cGaugeData = new GaugeData(); status = DicGaugeData.TryGetValue(splitRow[1], out cGaugeData); if (status) { continue; } cGaugeData = new GaugeData(); cGaugeData.Color = splitRow[0]; try { cGaugeData.EngName = splitRow[2]; } catch (System.Exception ex) { cGaugeData.EngName = ""; } DicGaugeData.Add(splitRow[1], cGaugeData); } #endregion //填檢具到IQC、IPQC下拉選單中 Gauge.Items.Add(""); Gauge.Items.AddRange(DicGaugeData.Keys.ToArray()); //填檢具到SelfCheck下拉選單中 SelfCheckGauge.Items.Add(""); foreach (KeyValuePair <string, GaugeData> kvp in DicGaugeData) { if (kvp.Key.Contains("T")) { continue; } SelfCheckGauge.Items.Add(kvp.Key); } //取得sheet並填入下拉選單中 int SheetCount = 0; NXOpen.Tag[] SheetTagAry = null; theUfSession.Draw.AskDrawings(out SheetCount, out SheetTagAry); for (int i = 0; i < SheetCount; i++) { NXOpen.Drawings.DrawingSheet CurrentSheet = (NXOpen.Drawings.DrawingSheet)NXObjectManager.Get(SheetTagAry[i]); ListSheet.Items.Add(CurrentSheet.Name); } //預設開啟sheet1圖紙 NXOpen.Drawings.DrawingSheet DefaultSheet = (NXOpen.Drawings.DrawingSheet)NXObjectManager.Get(SheetTagAry[0]); ListSheet.Text = DefaultSheet.Name; //取得圖紙長寬 SheetLength = DefaultSheet.Length; SheetHeight = DefaultSheet.Height; //填入IQC、IPQC與SelfCheck的單位 string[] CheckUnits = new string[] { "HRS", "PCS", "100%Check" }; Freq_Units.Items.AddRange(CheckUnits.ToArray()); SelfCheck_Units.Items.AddRange(CheckUnits.ToArray()); //取得圖紙範圍資料Data CaxGetDatData.GetDraftingCoordinateData(out cCoordinateData); }
private void buttonOpenTask_Click(object sender, EventArgs e) { #region (註解)檢查是否有選擇組裝方式 //if (SeleOperValue == "001.prt") //{ // if (check001HasBillet.Checked == false && check001NoBillet.Checked == false) // { // MessageBox.Show("請選擇一種組裝方式"); // return; // } // if (check001HasBillet.Checked == true && check001NoBillet.Checked == false) // { // if (label001.Text == "") // { // MessageBox.Show("請選擇一個零件當作胚料檔,或勾選無胚料檔"); // return; // } // } //} //else if (SeleOperValue == "900.prt") //{ //} //else //{ // if (checkWHasBillet.Checked == false && checkWNoBillet.Checked == false) // { // MessageBox.Show("請選擇一種組裝方式"); // return; // } // if (checkWHasBillet.Checked == true && checkWNoBillet.Checked == false) // { // if (labelW.Text == "") // { // MessageBox.Show("請選擇一個前段工序檔當作此工序零件檔,或勾選無前段工序檔"); // return; // } // } //} #endregion if (SelePartName == "") { MessageBox.Show("請選擇欲開啟的零件!"); return; } string Local_OISPartFullPath = string.Format(@"{0}\{1}\{2}\{3}\{4}\{5}", CaxEnv.GetLocalTaskDir(), comboBoxCus.Text, comboBoxPartNo.Text, comboBoxCusVer.Text, comboBoxOpVer.Text, SelePartName); //string Local_ModelPartFullPath = string.Format(@"{0}\{1}\{2}\{3}\{4}\{5}\{6}", CaxEnv.GetLocalTaskDir(), // CurrentCusName, // CurrentPartNo, // CurrentCusVer, // CurrentOpVer, // "MODEL", // CurrentPartNo + ".prt"); //string Local_ShareStrPartFullPath = string.Format(@"{0}\{1}\{2}\{3}\{4}", CaxEnv.GetLocalTaskDir(), // CurrentCusName, // CurrentPartNo, // CurrentCusVer, // CurrentOpVer); BasePart newAsmPart; status = CaxPart.OpenBaseDisplay(Local_OISPartFullPath, out newAsmPart); if (!status) { CaxLog.ShowListingWindow("組立開啟失敗!"); return; } /* * if (check001HasBillet.Checked == true || check001NoBillet.Checked == true || * checkWHasBillet.Checked == true || checkWNoBillet.Checked == true) * { #region 組裝客戶檔案 * NXOpen.Assemblies.Component newComponent = null; * string Local_NewModelPartFullPath = string.Format(@"{0}\{1}\{2}\{3}\{4}\{5}", CaxEnv.GetLocalTaskDir(), * CurrentCusName, * CurrentPartNo, * CurrentCusVer, * CurrentOpVer, * CurrentPartNo + ".prt"); * //判斷是否已經有客戶檔案,如果沒有則複製過來 * if (!System.IO.File.Exists(Local_NewModelPartFullPath)) * { * File.Copy(Local_ModelPartFullPath, Local_NewModelPartFullPath, true); * } * * status = CaxAsm.AddComponentToAsmByDefault(Local_NewModelPartFullPath, out newComponent); * if (!status) * { * MessageBox.Show("客戶檔案組裝失敗!"); * this.Close(); * return; * } #endregion * * CaxAsm.SetWorkComponent(null); * #region 建立三階製程檔 * * string Local_CurrentOperPartFullPath = ""; * if (groupBox001.Enabled == true) * { #region 001 * //組立"胚料檔" * if (check001HasBillet.Checked == true & System.IO.File.Exists(label001BilletPath)) * { * //複製檔案到任務資料夾 * string tempBilletPath = label001BilletPath; * tempBilletPath = tempBilletPath.Replace(Path.GetDirectoryName(tempBilletPath), Path.GetDirectoryName(Local_NewModelPartFullPath)); * File.Copy(label001BilletPath, tempBilletPath, true); * * status = CaxAsm.AddComponentToAsmByDefault(tempBilletPath, out newComponent); * if (!status) * { * CaxLog.ShowListingWindow("001胚料檔組裝失敗"); * return; * } * } * * //組立"料號_ME_OISxxx" * Local_CurrentOperPartFullPath = string.Format(@"{0}\{1}", Local_ShareStrPartFullPath, CurrentPartNo + "_ME_" + SeleOperValue); * * if (!System.IO.File.Exists(Local_CurrentOperPartFullPath)) * { * status = CaxAsm.CreateNewEmptyComp(Local_CurrentOperPartFullPath, out newComponent); * if (!status) * { * CaxLog.ShowListingWindow("建立三階製程檔失敗"); * return; * } * } #endregion * } * else if (groupBox900.Enabled == true) * { * } * else * { #region W階 * //組立"前段製程檔" * if (checkWHasBillet.Checked == true & System.IO.File.Exists(labelWBilletPath)) * { * //複製檔案到任務資料夾 * string tempBilletPath = labelWBilletPath; * tempBilletPath = tempBilletPath.Replace(Path.GetDirectoryName(tempBilletPath), Path.GetDirectoryName(Local_NewModelPartFullPath)); * File.Copy(labelWBilletPath, tempBilletPath, true); * * status = CaxAsm.AddComponentToAsmByDefault(tempBilletPath, out newComponent); * if (!status) * { * CaxLog.ShowListingWindow("W階胚料檔組裝失敗"); * return; * } * } * * //組立"料號_ME_OISxxx" * Local_CurrentOperPartFullPath = string.Format(@"{0}\{1}", Local_ShareStrPartFullPath, CurrentPartNo + "_ME_" + SeleOperValue); * if (!System.IO.File.Exists(Local_CurrentOperPartFullPath)) * { * status = CaxAsm.CreateNewEmptyComp(Local_CurrentOperPartFullPath, out newComponent); * if (!status) * { * CaxLog.ShowListingWindow("建立三階製程檔失敗"); * return; * } * } #endregion * } * #endregion * } */ //組件存在,直接開啟任務組立 //BasePart newAsmPart; //status = CaxPart.OpenBaseDisplay(Local_OISPartFullPath, out newAsmPart); //if (!status) //{ // CaxLog.ShowListingWindow("組立開啟失敗!"); // return; //} //判斷組件是否曾經被開啟。如已被開啟過,則開啟檔案後離開;反之則塞上屬性(Title=IsOpend,Value=Y)並組裝客戶零件與胚料零件 //string checkIsOpened = ""; //try //{ // checkIsOpened = newAsmPart.GetStringAttribute("IsOpened"); // if (checkIsOpened == "Y") // { // CaxPart.Save(); // this.Close(); // return; // } //} //catch (System.Exception ex) //{ // newAsmPart.SetAttribute("IsOpened", "Y"); //} //NXOpen.Assemblies.Component newComponent = null; #region (註解中)組裝客戶檔案 //string Local_NewModelPartFullPath = string.Format(@"{0}\{1}\{2}\{3}\{4}", CaxEnv.GetLocalTaskDir(), // CurrentCusName, // CurrentPartNo, // CurrentCusVer, // CurrentPartNo + ".prt"); //判斷是否已經有客戶檔案,如果沒有則複製過來 //if (!System.IO.File.Exists(Local_NewModelPartFullPath)) //{ // File.Copy(Local_ModelPartFullPath, Local_NewModelPartFullPath, true); //} //status = CaxAsm.AddComponentToAsmByDefault(Local_NewModelPartFullPath, out newComponent); //if (!status) //{ // CaxLog.ShowListingWindow("ERROR,組裝失敗!"); // this.Close(); // return; //} #endregion //CaxAsm.SetWorkComponent(null); #region (註解中)建立三階製程檔 //string Local_CurrentOperPartFullPath = ""; //if (groupBox001.Enabled == true) //{ // #region 001 // //組立"胚料檔" // if (check001HasBillet.Checked == true & System.IO.File.Exists(label001BilletPath)) // { // //複製檔案到任務資料夾 // string tempBilletPath = label001BilletPath; // tempBilletPath = tempBilletPath.Replace(Path.GetDirectoryName(tempBilletPath), Path.GetDirectoryName(Local_NewModelPartFullPath)); // File.Copy(label001BilletPath, tempBilletPath, true); // status = CaxAsm.AddComponentToAsmByDefault(tempBilletPath, out newComponent); // if (!status) // { // CaxLog.ShowListingWindow("001胚料檔組裝失敗"); // return; // } // } // //組立"料號_ME_OISxxx" // Local_CurrentOperPartFullPath = string.Format(@"{0}\{1}", Local_ShareStrPartFullPath, CurrentPartNo + "_ME_" + SeleOperValue); // if (!System.IO.File.Exists(Local_CurrentOperPartFullPath)) // { // status = CaxAsm.CreateNewEmptyComp(Local_CurrentOperPartFullPath, out newComponent); // if (!status) // { // CaxLog.ShowListingWindow("建立三階製程檔失敗"); // return; // } // } // #endregion //} //else if (groupBox900.Enabled == true) //{ //} //else //{ // #region W階 // //組立"前段製程檔" // if (checkWHasBillet.Checked == true & System.IO.File.Exists(labelWBilletPath)) // { // //複製檔案到任務資料夾 // string tempBilletPath = labelWBilletPath; // tempBilletPath = tempBilletPath.Replace(Path.GetDirectoryName(tempBilletPath), Path.GetDirectoryName(Local_NewModelPartFullPath)); // File.Copy(labelWBilletPath, tempBilletPath, true); // status = CaxAsm.AddComponentToAsmByDefault(tempBilletPath, out newComponent); // if (!status) // { // CaxLog.ShowListingWindow("W階胚料檔組裝失敗"); // return; // } // } // //組立"料號_ME_OISxxx" // Local_CurrentOperPartFullPath = string.Format(@"{0}\{1}", Local_ShareStrPartFullPath, CurrentPartNo + "_ME_" + SeleOperValue); // if (!System.IO.File.Exists(Local_CurrentOperPartFullPath)) // { // status = CaxAsm.CreateNewEmptyComp(Local_CurrentOperPartFullPath, out newComponent); // if (!status) // { // CaxLog.ShowListingWindow("建立三階製程檔失敗"); // return; // } // } // #endregion //} #endregion CaxPart.Save(); this.Close(); }
private void OK_Click(object sender, EventArgs e) { //先關閉所有檔案 CaxPart.CloseAllParts(); try { if (Is_OldPart == true) { //定義總組立檔案、二階檔案、三階檔案名稱 string AsmCompFileFullPath = string.Format(@"{0}\{1}\{2}\{3}\{4}\{5}", CaxEnv.GetGlobaltekEnvDir(), "Task", comboBoxOldCusName.Text, comboBoxOldPartNo.Text, comboBoxOldCusRev.Text.ToUpper(), comboBoxOldPartNo.Text + "_MOT.prt"); string SecondFileFullPath = string.Format(@"{0}\{1}\{2}\{3}\{4}\{5}", CaxEnv.GetGlobaltekEnvDir(), "Task", comboBoxOldCusName.Text, comboBoxOldPartNo.Text, comboBoxOldCusRev.Text.ToUpper(), comboBoxOldPartNo.Text + "_OP" + "[Oper1]" + ".prt"); string ThirdFileFullPath_OIS = string.Format(@"{0}\{1}\{2}\{3}\{4}\{5}", CaxEnv.GetGlobaltekEnvDir(), "Task", comboBoxOldCusName.Text, comboBoxOldPartNo.Text, comboBoxOldCusRev.Text.ToUpper(), comboBoxOldPartNo.Text + "_OIS" + "[Oper1]" + ".prt"); string ThirdFileFullPath_CAM = string.Format(@"{0}\{1}\{2}\{3}\{4}\{5}", CaxEnv.GetGlobaltekEnvDir(), "Task", comboBoxOldCusName.Text, comboBoxOldPartNo.Text, comboBoxOldCusRev.Text.ToUpper(), comboBoxOldPartNo.Text + "_OP" + "[Oper1]" + "_CAM.prt"); string OPFolderPath = string.Format(@"{0}\{1}\{2}\{3}\{4}\{5}", CaxEnv.GetGlobaltekEnvDir(), "Task", comboBoxOldCusName.Text, comboBoxOldPartNo.Text, comboBoxOldCusRev.Text.ToUpper(), "OP" + "[Oper1]"); string tempSecondFileFullPath = SecondFileFullPath; string tempThirdFileFullPath_OIS = ThirdFileFullPath_OIS; string tempThirdFileFullPath_CAM = ThirdFileFullPath_CAM; string tempOPFolderPath = OPFolderPath; #region 開啟總組立 if (File.Exists(AsmCompFileFullPath)) { //組件存在,直接開啟任務組立 BasePart newAsmPart; status = CaxPart.OpenBaseDisplay(AsmCompFileFullPath, out newAsmPart); if (!status) { CaxLog.ShowListingWindow("組立開啟失敗,料號不可有中文字!"); return; } } else { CaxLog.ShowListingWindow("開啟失敗:找不到總組立" + Path.GetFileNameWithoutExtension(AsmCompFileFullPath)); return; } #endregion #region 建立新插入的製程 NXOpen.Assemblies.Component tempComp; foreach (string i in ListAddOper) { //設定一階為WorkComp CaxAsm.SetWorkComponent(null); //建立二階檔案 SecondFileFullPath = tempSecondFileFullPath; SecondFileFullPath = SecondFileFullPath.Replace("[Oper1]", i); status = CaxAsm.CreateNewEmptyComp(SecondFileFullPath, out tempComp); if (!status) { CaxLog.ShowListingWindow("建立二階製程檔失敗"); return; } //取得二階所有comp List <NXOpen.Assemblies.Component> ChildenComp = new List <NXOpen.Assemblies.Component>(); CaxAsm.GetCompChildren(out ChildenComp); foreach (NXOpen.Assemblies.Component ii in ChildenComp) { if (ii.Name == Path.GetFileNameWithoutExtension(SecondFileFullPath).ToUpper()) { CaxAsm.SetWorkComponent(ii); } } //建立三階檔案 ThirdFileFullPath_OIS = tempThirdFileFullPath_OIS; ThirdFileFullPath_CAM = tempThirdFileFullPath_CAM; ThirdFileFullPath_OIS = ThirdFileFullPath_OIS.Replace("[Oper1]", i); ThirdFileFullPath_CAM = ThirdFileFullPath_CAM.Replace("[Oper1]", i); status = CaxAsm.CreateNewEmptyComp(ThirdFileFullPath_OIS, out tempComp); if (!status) { CaxLog.ShowListingWindow("建立三階OIS檔失敗"); return; } status = CaxAsm.CreateNewEmptyComp(ThirdFileFullPath_CAM, out tempComp); if (!status) { CaxLog.ShowListingWindow("建立三階CAM檔失敗"); return; } } #endregion #region 建立新插入的製程資料夾 foreach (string i in ListAddOper) { OPFolderPath = tempOPFolderPath; OPFolderPath = OPFolderPath.Replace("[Oper1]", i); string OISFolderPath = string.Format(@"{0}\{1}", OPFolderPath, "OIS"); string CAMFolderPath = string.Format(@"{0}\{1}", OPFolderPath, "CAM"); if (!File.Exists(OISFolderPath)) { try { System.IO.Directory.CreateDirectory(OISFolderPath); } catch (System.Exception ex) { MessageBox.Show(ex.ToString()); return; } } if (!File.Exists(CAMFolderPath)) { try { System.IO.Directory.CreateDirectory(CAMFolderPath); } catch (System.Exception ex) { MessageBox.Show(ex.ToString()); return; } } } #endregion #region 將值儲存起來 cPECreateData.CusName = comboBoxOldCusName.Text; cPECreateData.PartNo = comboBoxOldPartNo.Text; cPECreateData.CusRev = comboBoxOldCusRev.Text.ToUpper(); cPECreateData.ListOperation = new List <Operation>(); Operation cOperation = new Operation(); cPECreateData.Oper1Ary = new List <string>(); cPECreateData.Oper2Ary = new List <string>(); for (int i = 0; i < panel.Rows.Count; i++) { if (panel.Rows.Count == 0) { MessageBox.Show("尚未選擇製程序與製程別!"); return; } if (panel.GetCell(i, 1).Value.ToString() == "") { MessageBox.Show("製程序" + panel.GetCell(i, 0).Value + "尚未選取製程別!"); return; } cOperation = new Operation(); cOperation.Oper1 = panel.GetCell(i, 0).Value.ToString(); cOperation.Oper2 = panel.GetCell(i, 1).Value.ToString(); cPECreateData.ListOperation.Add(cOperation); cPECreateData.Oper1Ary.Add(panel.GetCell(i, 0).Value.ToString()); cPECreateData.Oper2Ary.Add(panel.GetCell(i, 1).Value.ToString()); } #endregion #region 寫出PECreateData.dat string PECreateDataJsonDat = string.Format(@"{0}\{1}\{2}\{3}\{4}\{5}", CaxEnv.GetGlobaltekTaskDir(), CurrentOldCusName, CurrentOldPartNo, CurrentOldCusRev, "MODEL", "PECreateData.dat"); status = CaxFile.WriteJsonFileData(PECreateDataJsonDat, cPECreateData); if (!status) { MessageBox.Show("PECreateData.dat 輸出失敗..."); return; } #endregion } else { #region 取得客戶名稱 CusName = comboBoxCusName.Text; if (CusName == "") { MessageBox.Show("尚未填寫客戶!"); return; } #endregion #region 取得料號 PartNo = textPartNo.Text; if (PartNo == "") { MessageBox.Show("尚未填寫料號!"); return; } #endregion #region 取得客戶版次 CusRev = textCusRev.Text; if (CusRev == "") { MessageBox.Show("尚未填寫客戶版次!"); return; } #endregion #region 取得檔案路徑 if (PartPath == "-1") { MessageBox.Show("尚未選擇客戶檔案!"); return; } #endregion #region 定義根目錄 //定義MODEL資料夾路徑 string ModelFolderFullPath = string.Format(@"{0}\{1}\{2}\{3}\{4}\{5}", CaxEnv.GetGlobaltekEnvDir(), "Task", CusName, PartNo, CusRev.ToUpper(), "MODEL"); //定義總組立檔案名稱 string AsmCompFileFullPath = string.Format(@"{0}\{1}\{2}\{3}\{4}\{5}", CaxEnv.GetGlobaltekEnvDir(), "Task", CusName, PartNo, CusRev.ToUpper(), PartNo + "_MOT.prt"); //定義CAM資料夾路徑、OIS資料夾路徑、三階檔案路徑 string CAMFolderPath = "", OISFolderPath = "", ThridOperPartPath = ""; #endregion #region 建立MODEL資料夾 if (!File.Exists(ModelFolderFullPath)) { try { System.IO.Directory.CreateDirectory(ModelFolderFullPath); } catch (System.Exception ex) { MessageBox.Show(ex.ToString()); return; } } #endregion #region 複製客戶檔案到MODEL資料夾內 //判斷客戶的檔案是否存在 status = System.IO.File.Exists(PartPath); if (!status) { MessageBox.Show("指定的檔案不存在,請再次確認"); return; } //建立MODEL資料夾內客戶檔案路徑 string CustomerPartFullPath = string.Format(@"{0}\{1}", ModelFolderFullPath, PartNo + ".prt"); //開始複製 if (!System.IO.File.Exists(CustomerPartFullPath)) { File.Copy(PartPath, CustomerPartFullPath, true); } #endregion #region 將值儲存起來 cPECreateData.CusName = CusName; cPECreateData.PartNo = PartNo; cPECreateData.CusRev = CusRev.ToUpper(); //cPE_OutPutDat.PartPath = PartPath; cPECreateData.ListOperation = new List <Operation>(); Operation cOperation = new Operation(); cPECreateData.Oper1Ary = new List <string>(); cPECreateData.Oper2Ary = new List <string>(); for (int i = 0; i < panel.Rows.Count; i++) { if (panel.Rows.Count == 0) { MessageBox.Show("尚未選擇製程序與製程別!"); return; } if (panel.GetCell(i, 1).Value.ToString() == "") { MessageBox.Show("製程序" + panel.GetCell(i, 0).Value + "尚未選取製程別!"); return; } cOperation = new Operation(); cOperation.Oper1 = panel.GetCell(i, 0).Value.ToString(); cOperation.Oper2 = panel.GetCell(i, 1).Value.ToString(); //建立CAM資料夾路徑 CAMFolderPath = string.Format(@"{0}\{1}\{2}", Path.GetDirectoryName(AsmCompFileFullPath), "OP" + panel.GetCell(i, 0).Value.ToString(), "CAM"); //儲存CAM資料夾路徑 //cOperation.CAMFolderPath = CAMFolderPath; //建立CAM資料夾 if (!File.Exists(CAMFolderPath)) { try { System.IO.Directory.CreateDirectory(CAMFolderPath); } catch (System.Exception ex) { MessageBox.Show(ex.ToString()); return; } } //建立OIS資料夾路徑 OISFolderPath = string.Format(@"{0}\{1}\{2}", Path.GetDirectoryName(AsmCompFileFullPath), "OP" + panel.GetCell(i, 0).Value.ToString(), "OIS"); //儲存OIS資料夾路徑 //cOperation.OISFolderPath = OISFolderPath; //建立OIS資料夾 if (!File.Exists(OISFolderPath)) { try { System.IO.Directory.CreateDirectory(OISFolderPath); } catch (System.Exception ex) { MessageBox.Show(ex.ToString()); return; } } //建立三階檔案路徑 ThridOperPartPath = Path.GetDirectoryName(AsmCompFileFullPath); cPECreateData.ListOperation.Add(cOperation); cPECreateData.Oper1Ary.Add(panel.GetCell(i, 0).Value.ToString()); cPECreateData.Oper2Ary.Add(panel.GetCell(i, 1).Value.ToString()); } #endregion #region (註解中)複製MODEL內的客戶檔案到料號資料夾內,並更名XXX_MOT.prt /* * //判斷要複製的檔案是否存在 * status = System.IO.File.Exists(destFileName_Model); * if (!status) * { * MessageBox.Show("指定的檔案不存在,請再次確認"); * return; * } * * //建立目的地(客戶版次)檔案全路徑 * string destFileName_CusRev = string.Format(@"{0}\{1}\{2}\{3}", CaxEnv.GetGlobalTekEnvDir(), PartNo, CusRev.ToUpper(), PartNo + "_MOT.prt"); * * //開始複製 * File.Copy(destFileName_Model, destFileName_CusRev, true); */ #endregion #region 自動建立總組立檔案架構,並組立相關製程 status = CaxAsm.CreateNewAsm(AsmCompFileFullPath); if (!status) { CaxLog.ShowListingWindow("建立一階總組立檔失敗"); return; } CaxPart.Save(); string OPCompName = ""; NXOpen.Assemblies.Component tempComp; //List<double> ListOperDouble = new List<double>(); //for (int i = 0; i < cPE_OutPutDat.ListOperation.Count; i++) //{ // ListOperDouble.Add(Convert.ToDouble(cPE_OutPutDat.ListOperation[i].Oper1)); //} //ListOperDouble.Sort(); for (int i = 0; i < cPECreateData.ListOperation.Count; i++) { //設定一階為WorkComp CaxAsm.SetWorkComponent(null); //建立二階製程檔 OPCompName = string.Format(@"{0}\{1}", Path.GetDirectoryName(AsmCompFileFullPath), PartNo + "_OP" + cPECreateData.ListOperation[i].Oper1 + ".prt"); status = CaxAsm.CreateNewEmptyComp(OPCompName, out tempComp); if (!status) { CaxLog.ShowListingWindow("建立二階製程檔失敗"); return; } } string OISCompFullPath = "", CAMCompFullPath = ""; //取得二階所有comp List <NXOpen.Assemblies.Component> ChildenComp = new List <NXOpen.Assemblies.Component>(); CaxAsm.GetCompChildren(out ChildenComp); for (int i = 0; i < ChildenComp.Count; i++) { CaxAsm.SetWorkComponent(ChildenComp[i]); string OperStr = ChildenComp[i].Name.Split(new string[] { "OP" }, StringSplitOptions.RemoveEmptyEntries)[1]; #region 建立三階CAM檔 //建立三階CAM檔 CAMCompFullPath = string.Format(@"{0}\{1}", Path.GetDirectoryName(AsmCompFileFullPath), PartNo + "_OP" + OperStr + "_CAM.prt"); status = CaxAsm.CreateNewEmptyComp(CAMCompFullPath, out tempComp); if (!status) { CaxLog.ShowListingWindow("建立三階CAM檔失敗"); return; } #endregion #region 建立三階OIS檔 //先複製drafting_template.prt到OIS檔 string drafting_template_Path = string.Format(@"{0}\{1}", CaxEnv.GetGlobaltekEnvDir(), "drafting_template.prt"); OISCompFullPath = string.Format(@"{0}\{1}", Path.GetDirectoryName(AsmCompFileFullPath), PartNo + "_OIS" + OperStr + ".prt"); if (!File.Exists(drafting_template_Path)) { CaxLog.ShowListingWindow("drafting_template.prt遺失,請聯繫開發工程師"); return; } System.IO.File.Copy(drafting_template_Path, OISCompFullPath, true); //組立三階OIS檔 //status = CaxAsm.CreateNewEmptyComp(OISCompFullPath, out tempComp); status = CaxAsm.AddComponentToAsmByDefault(OISCompFullPath, out tempComp); if (!status) { CaxLog.ShowListingWindow("組立三階OIS檔失敗"); return; } #endregion } #endregion #region 寫出PECreateData.dat string PECreateDataJsonDat = string.Format(@"{0}\{1}", ModelFolderFullPath, "PECreateData.dat"); status = CaxFile.WriteJsonFileData(PECreateDataJsonDat, cPECreateData); if (!status) { MessageBox.Show("PECreateData.dat 輸出失敗..."); return; } #endregion #region (註解中)寫出METEDownloadData.dat //string METEDownloadData = string.Format(@"{0}\{1}", CaxEnv.GetGlobaltekTaskDir(), "METEDownloadData.dat"); //METEDownloadData cMETEDownloadData = new METEDownloadData(); //if (File.Exists(METEDownloadData)) //{ // #region METEDownloadData.dat檔案存在 // status = CaxPublic.ReadMETEDownloadData(METEDownloadData, out cMETEDownloadData); // if (!status) // { // MessageBox.Show("METEDownloadData.dat讀取失敗..."); // return; // } // int CusCount = 0, IndexOfCusName = -1; // for (int i = 0; i < cMETEDownloadData.EntirePartAry.Count; i++) // { // if (CusName != cMETEDownloadData.EntirePartAry[i].CusName) // { // CusCount++; // } // else // { // IndexOfCusName = i; // break; // } // } // //新的客戶且已經有METEDownloadDat.dat // if (CusCount == cMETEDownloadData.EntirePartAry.Count) // { // EntirePartAry cEntirePartAry = new EntirePartAry(); // cEntirePartAry.CusName = CusName; // cEntirePartAry.CusPart = new List<CusPart>(); // CusPart cCusPart = new CusPart(); // cCusPart.PartNo = PartNo; // cCusPart.CusRev = new List<CusRev>(); // CusRev cCusRev = new CusRev(); // cCusRev.RevNo = CusRev.ToUpper(); // cCusRev.OperAry1 = new List<string>(); // cCusRev.OperAry2 = new List<string>(); // cCusRev.OperAry1 = cPECreateData.Oper1Ary; // cCusRev.OperAry2 = cPECreateData.Oper2Ary; // cCusPart.CusRev.Add(cCusRev); // cEntirePartAry.CusPart.Add(cCusPart); // cMETEDownloadData.EntirePartAry.Add(cEntirePartAry); // } // //舊的客戶新增料號 // else // { // //判斷料號是否已存在 // int PartCount = 0; int IndexOfPartNo = -1; // for (int i = 0; i < cMETEDownloadData.EntirePartAry[IndexOfCusName].CusPart.Count; i++) // { // if (PartNo != cMETEDownloadData.EntirePartAry[IndexOfCusName].CusPart[i].PartNo) // { // PartCount++; // } // else // { // IndexOfPartNo = i; // break; // } // } // //舊的客戶且新的料號 PartCount == CusPart.Count 表示新的料號 // if (PartCount == cMETEDownloadData.EntirePartAry[IndexOfCusName].CusPart.Count) // { // CusPart cCusPart = new CusPart(); // cCusPart.PartNo = PartNo; // cCusPart.CusRev = new List<CusRev>(); // CusRev cCusRev = new CusRev(); // cCusRev.RevNo = CusRev.ToUpper(); // cCusRev.OperAry1 = new List<string>(); // cCusRev.OperAry2 = new List<string>(); // cCusRev.OperAry1 = cPECreateData.Oper1Ary; // cCusRev.OperAry2 = cPECreateData.Oper2Ary; // cCusPart.CusRev.Add(cCusRev); // cMETEDownloadData.EntirePartAry[IndexOfCusName].CusPart.Add(cCusPart); // } // //舊的客戶且舊的料號新增客戶版次 // else // { // CusRev cCusRev = new CusRev(); // cCusRev.RevNo = CusRev.ToUpper(); // cCusRev.OperAry1 = new List<string>(); // cCusRev.OperAry1 = cPECreateData.Oper1Ary; // cMETEDownloadData.EntirePartAry[IndexOfCusName].CusPart[IndexOfPartNo].CusRev.Add(cCusRev); // } // } // /* // int PartCount = 0; int IndexOfPartNo = -1; // for (int i = 0; i < cMETEDownloadData.EntirePartAry.Count; i++) // { // if (PartNo != cMETEDownloadData.EntirePartAry[i].PartNo) // { // PartCount++; // } // else // { // IndexOfPartNo = i; // break; // } // } // //新的料號且已經有METEDownloadDat.dat // if (PartCount == cMETEDownloadData.EntirePartAry.Count) // { // EntirePartAry cEntirePartAry = new EntirePartAry(); // cEntirePartAry.CusRev = new List<CusRev>(); // CusRev cCusRev = new CusRev(); // cCusRev.OperAry1 = new List<string>(); // cCusRev.RevNo = CusRev.ToUpper(); // cCusRev.OperAry1 = cPE_OutPutDat.Oper1Ary; // cEntirePartAry.CusName = CusName; // cEntirePartAry.PartNo = PartNo; // cEntirePartAry.CusRev.Add(cCusRev); // cMETEDownloadData.EntirePartAry.Add(cEntirePartAry); // } // //舊的料號新增客戶版次 // else // { // CusRev cCusRev = new CusRev(); // cCusRev.OperAry1 = new List<string>(); // cCusRev.RevNo = CusRev.ToUpper(); // cCusRev.OperAry1 = cPE_OutPutDat.Oper1Ary; // cMETEDownloadData.EntirePartAry[IndexOfPartNo].CusRev.Add(cCusRev); // } // */ // #endregion //} //else //{ // #region METEDownloadData.dat檔案不存在 // cMETEDownloadData.EntirePartAry = new List<EntirePartAry>(); // EntirePartAry cEntirePartAry = new EntirePartAry(); // cEntirePartAry.CusName = CusName; // cEntirePartAry.CusPart = new List<CusPart>(); // CusPart cCusPart = new CusPart(); // cCusPart.PartNo = PartNo; // cCusPart.CusRev = new List<CusRev>(); // CusRev cCusRev = new CusRev(); // cCusRev.RevNo = CusRev.ToUpper(); // cCusRev.OperAry1 = new List<string>(); // cCusRev.OperAry2 = new List<string>(); // cCusRev.OperAry1 = cPECreateData.Oper1Ary; // cCusRev.OperAry2 = cPECreateData.Oper2Ary; // cCusPart.CusRev.Add(cCusRev); // cEntirePartAry.CusPart.Add(cCusPart); // cMETEDownloadData.EntirePartAry.Add(cEntirePartAry); // #endregion //} //status = CaxFile.WriteJsonFileData(METEDownloadData, cMETEDownloadData); //if (!status) //{ // MessageBox.Show("METEDownloadData.dat輸出失敗..."); // return; //} #endregion } CaxAsm.SetWorkComponent(null); CaxPart.Save(); this.DialogResult = DialogResult.OK; this.Close(); } catch (System.Exception ex) { CaxLog.ShowListingWindow(ex.ToString()); } }
public void aabb(object sender, EventArgs e) { CaxLog.ShowListingWindow("5656"); }
//------------------------------------------------------------------------------ // Explicit Activation // This entry point is used to activate the application explicitly //------------------------------------------------------------------------------ public static int Main(string[] args) { int retValue = 0; try { theProgram = new Program(); Session theSession = Session.GetSession(); Part workPart = theSession.Parts.Work; Part displayPart = theSession.Parts.Display; int module_id; theUfSession.UF.AskApplicationModule(out module_id); if (module_id != UFConstants.UF_APP_DRAFTING) { MessageBox.Show("請先轉換為製圖模組後再執行!"); return(retValue); } bool status, Is_Keep; //抓取目前圖紙數量和Tag //取得全部尺寸資料,並整理出尺寸落在的圖紙&尺寸設定的自定義泡泡再填入Panel中(當使用者點自定義時使用) int SheetCount = 0; NXOpen.Tag[] SheetTagAry = null; theUfSession.Draw.AskDrawings(out SheetCount, out SheetTagAry); Dictionary <NXObject, Sheet_DefineNum> DicUserDefine = new Dictionary <NXObject, Sheet_DefineNum>(); for (int i = 0; i < SheetCount; i++) { NXOpen.Drawings.DrawingSheet CurrentSheet = (NXOpen.Drawings.DrawingSheet)NXObjectManager.Get(SheetTagAry[i]); CurrentSheet.Open(); CurrentSheet.View.UpdateDisplay(); NXObject[] SheetObj = CaxME.FindObjectsInView(CurrentSheet.View.Tag).ToArray(); GetUserDefineData(SheetObj, CurrentSheet.Name, ref DicUserDefine); } NXOpen.Drawings.DrawingSheet DefaultSheet = (NXOpen.Drawings.DrawingSheet)NXObjectManager.Get(SheetTagAry[0]); DefaultSheet.Open(); Application.EnableVisualStyles(); CreateBallonDlg cCreateBallonDlg = new CreateBallonDlg(DicUserDefine); FormUtilities.ReparentForm(cCreateBallonDlg); System.Windows.Forms.Application.Run(cCreateBallonDlg); if (cCreateBallonDlg.DialogResult == DialogResult.Yes) { Is_Keep = cCreateBallonDlg.Is_Keep; cCreateBallonDlg.Dispose(); } else { ((NXOpen.Drawings.DrawingSheet)NXObjectManager.Get(SheetTagAry[0])).Open(); cCreateBallonDlg.Dispose(); theProgram.Dispose(); return(retValue); } #region 前置處理 string Is_Local = Environment.GetEnvironmentVariable("UGII_ENV_FILE"); CoordinateData cCoordinateData = new CoordinateData(); if (Is_Local != null) { //取得圖紙範圍資料Data status = CaxGetDatData.GetDraftingCoordinateData(out cCoordinateData); if (!status) { return(retValue); } } else { string DraftingCoordinate_dat = "DraftingCoordinate.dat"; string DraftingCoordinate_Path = string.Format(@"{0}\{1}", "D:", DraftingCoordinate_dat); CaxPublic.ReadCoordinateData(DraftingCoordinate_Path, out cCoordinateData); } //圖紙長、高 double SheetLength = 0; double SheetHeight = 0; //取得最後一顆泡泡的數字 int MaxBallonNum; try { MaxBallonNum = Convert.ToInt32(workPart.GetStringAttribute(CaxME.DimenAttr.BallonNum)); } catch (System.Exception ex) { MaxBallonNum = 0; } #endregion //重新產生泡泡 if (Is_Keep == false) { #region 刪除全部泡泡 IdSymbolCollection BallonCollection = workPart.Annotations.IdSymbols; IdSymbol[] BallonAry = BallonCollection.ToArray(); foreach (IdSymbol i in BallonAry) { try { i.GetStringAttribute("BalloonAtt"); } catch (System.Exception ex) { continue; } CaxPublic.DelectObject(i); } workPart.DeleteAttributeByTypeAndTitle(NXObject.AttributeType.String, "BALLONNUM"); #endregion #region 存DicDimenData(string=檢具名稱,DimenData=尺寸物件、泡泡座標) DefineParam.DicDimenData = new Dictionary <string, List <DimenData> >(); for (int i = 0; i < SheetCount; i++) { //打開Sheet並記錄所有OBJ NXOpen.Drawings.DrawingSheet CurrentSheet = (NXOpen.Drawings.DrawingSheet)NXObjectManager.Get(SheetTagAry[i]); //string SheetName = "S" + (i + 1).ToString(); //CaxME.SheetRename(CurrentSheet, SheetName); CurrentSheet.Open(); if (i == 0) { DefineParam.FirstDrawingSheet = CurrentSheet; } //取得圖紙長、高 SheetLength = CurrentSheet.Length; SheetHeight = CurrentSheet.Height; //DisplayableObject[] SheetObj = CurrentSheet.View.AskVisibleObjects(); NXObject[] SheetObj = CaxME.FindObjectsInView(CurrentSheet.View.Tag).ToArray(); foreach (NXObject singleObj in SheetObj) { #region 刪除尺寸數量產生的文字(ex:a-c) string dicount = "", chekcLevel = ""; try { dicount = singleObj.GetStringAttribute(CaxME.DimenAttr.DiCount); } catch (System.Exception ex) { dicount = ""; } try { chekcLevel = singleObj.GetStringAttribute(CaxME.DimenAttr.CheckLevel); } catch (System.Exception ex) { chekcLevel = ""; } if (dicount != "" && chekcLevel == "") { CaxPublic.DelectObject(singleObj); } #endregion string Gauge = "", AssignExcelType = ""; #region 判斷是否有屬性,沒有屬性就跳下一個 try{ AssignExcelType = singleObj.GetStringAttribute(CaxME.DimenAttr.AssignExcelType); } catch (System.Exception ex) { continue; } try{ Gauge = singleObj.GetStringAttribute(CaxME.DimenAttr.Gauge); } catch (System.Exception ex) { } #endregion //事先塞入該尺寸所在Sheet singleObj.SetAttribute("SheetName", CurrentSheet.Name); //string DimeType = singleObj.GetType().ToString(); CaxME.BoxCoordinate cBoxCoordinate = new CaxME.BoxCoordinate(); //GetTextBoxCoordinate(DimeType, singleObj, out cBoxCoordinate); //可以將NXOpen直接轉型成Annotation CaxME.GetTextBoxCoordinate(((NXOpen.Annotations.Annotation)singleObj).Tag, out cBoxCoordinate); #region 計算泡泡座標 DimenData sDimenData = new DimenData(); sDimenData.Obj = singleObj; sDimenData.CurrentSheet = CurrentSheet; Functions.CalculateBallonCoordinate(cBoxCoordinate, ref sDimenData); #endregion if (Gauge != "") { List <DimenData> ListDimenData = new List <DimenData>(); status = DefineParam.DicDimenData.TryGetValue(Gauge, out ListDimenData); if (!status) { ListDimenData = new List <DimenData>(); } ListDimenData.Add(sDimenData); DefineParam.DicDimenData[Gauge] = ListDimenData; } } } #endregion //插入泡泡 int BallonNum = 0; InsertBallon(ref BallonNum, cCoordinateData, SheetHeight, SheetLength, "BalloonAtt"); //將最後一顆泡泡的數字插入零件中 workPart.SetAttribute(CaxME.DimenAttr.BallonNum, BallonNum.ToString()); } //保留泡泡 else { #region 存DicDimenData(string=檢具名稱,DimenData=尺寸物件、泡泡座標) DefineParam.DicDimenData = new Dictionary <string, List <DimenData> >(); for (int i = 0; i < SheetCount; i++) { //打開Sheet並記錄所有OBJ NXOpen.Drawings.DrawingSheet CurrentSheet = (NXOpen.Drawings.DrawingSheet)NXObjectManager.Get(SheetTagAry[i]); CurrentSheet.Open(); if (i == 0) { DefineParam.FirstDrawingSheet = CurrentSheet; } //取得圖紙長、高 SheetLength = CurrentSheet.Length; SheetHeight = CurrentSheet.Height; //DisplayableObject[] SheetObj = CurrentSheet.View.AskVisibleObjects(); NXObject[] SheetObj = CaxME.FindObjectsInView(CurrentSheet.View.Tag).ToArray(); foreach (NXObject singleObj in SheetObj) { //判斷是否取到舊的尺寸,如果是就跳下一個 string OldBallonNum = ""; try { OldBallonNum = singleObj.GetStringAttribute(CaxME.DimenAttr.BallonNum); continue; } catch (System.Exception ex) { } //判斷是否有屬性,沒有屬性就跳下一個 string Gauge = "", AssignExcelType = ""; try { AssignExcelType = singleObj.GetStringAttribute(CaxME.DimenAttr.AssignExcelType); } catch (System.Exception ex) { continue; } try { Gauge = singleObj.GetStringAttribute(CaxME.DimenAttr.Gauge); } catch (System.Exception ex) { } //事先塞入該尺寸所在Sheet singleObj.SetAttribute("SheetName", CurrentSheet.Name); //string DimeType = ""; //DimeType = singleObj.GetType().ToString(); CaxME.BoxCoordinate cBoxCoordinate = new CaxME.BoxCoordinate(); //GetTextBoxCoordinate(DimeType, singleObj, out cBoxCoordinate); //CaxLog.ShowListingWindow(cBoxCoordinate.lower_left[0].ToString()); CaxME.GetTextBoxCoordinate(((NXOpen.Annotations.Annotation)singleObj).Tag, out cBoxCoordinate); //CaxLog.ShowListingWindow(cBoxCoordinate.lower_left[0].ToString()); #region 計算泡泡座標 DimenData sDimenData = new DimenData(); sDimenData.Obj = singleObj; sDimenData.CurrentSheet = CurrentSheet; Functions.CalculateBallonCoordinate(cBoxCoordinate, ref sDimenData); #endregion if (Gauge != "") { List <DimenData> ListDimenData = new List <DimenData>(); status = DefineParam.DicDimenData.TryGetValue(Gauge, out ListDimenData); if (!status) { ListDimenData = new List <DimenData>(); } ListDimenData.Add(sDimenData); DefineParam.DicDimenData[Gauge] = ListDimenData; } } } #endregion if (DefineParam.DicDimenData.Count != 0) { //插入泡泡 InsertBallon(ref MaxBallonNum, cCoordinateData, SheetHeight, SheetLength, "BalloonAtt"); //將最後一顆泡泡的數字插入零件中 workPart.SetAttribute(CaxME.DimenAttr.BallonNum, MaxBallonNum.ToString()); } } //切回第一張Sheet DefineParam.FirstDrawingSheet.Open(); MessageBox.Show("完成"); theProgram.Dispose(); } catch (NXOpen.NXException ex) { // ---- Enter your exception handling code here ----- CaxLog.ShowListingWindow(ex.ToString()); } return(retValue); }
private void PostProcessorDlg_Load(object sender, EventArgs e) { int module_id; theUfSession.UF.AskApplicationModule(out module_id); if (module_id != UFConstants.UF_APP_CAM) { MessageBox.Show("請先轉換為加工模組後再執行!"); this.Close(); } //取得METEDownload_Upload資料 status = CaxGetDatData.GetMETEDownload_Upload(out cMETE_Download_Upload_Path); if (!status) { MessageBox.Show("取得METEDownload_Upload失敗"); return; } //取得所有GroupAry,用來判斷Group的Type決定是NC、Tool、Geometry NCGroupAry = displayPart.CAMSetup.CAMGroupCollection.ToArray(); //取得所有operationAry OperationAry = displayPart.CAMSetup.CAMOperationCollection.ToArray(); #region 取得相關資訊,填入Dic DicNCData = new Dictionary <string, string>(); 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; } foreach (NXOpen.CAM.Operation item in OperationAry) { //取得父層的群組(回傳:NCGroup XXXX) string NCProgramTag = item.GetParent(CAMSetup.View.ProgramOrder).ToString(); NCProgramTag = Regex.Replace(NCProgramTag, "[^0-9]", ""); if (NCProgramTag == ncGroup.Tag.ToString()) { bool cheValue; string OperName = ""; cheValue = DicNCData.TryGetValue(ncGroup.Name, out OperName); if (!cheValue) { OperName = item.Name; DicNCData.Add(ncGroup.Name, OperName); } else { OperName = OperName + "," + item.Name; DicNCData[ncGroup.Name] = OperName; } } } } #endregion //將DicProgName的key存入程式群組下拉選單中 comboBoxNCgroup.Items.AddRange(DicNCData.Keys.ToArray()); #region 將控制器名稱填入SuperGridPostPanel GridRow row = new GridRow(); //-----暫時使用版本(路徑指向UG) //string TemplateRoot = string.Format(@"{0}\{1}\{2}\{3}", Environment.GetEnvironmentVariable("UGII_BASE_DIR"), "MACH", "resource", "postprocessor"); //string TemplatePostPath = string.Format(@"{0}\{1}", TemplateRoot, "template_post.dat"); //TemplatePostData = System.IO.File.ReadAllLines(TemplatePostPath); //-----發佈使用版本(Server需有MACH檔案) TemplatePostData = CaxGetDatData.GetTemplatePostData(); if (TemplatePostData.Length == 0) { CaxLog.ShowListingWindow("template_post.dat為空,請檢查!"); } //string empty = ""; //row = new GridRow(empty); //PostPanel.Rows.Add(row); //for (int i = 0; i < TemplatePostData.Length;i++ ) //{ // if (i>6) // { // string PostName = TemplatePostData[i].Split(',')[0]; // row = new GridRow(PostName); // PostPanel.Rows.Add(row); // } //} #endregion }
private void buttonDownload_Click(object sender, EventArgs e) { //建立Local路徑資料 //string Local_IP = cMETE_Download_Upload_Path.Local_IP; //string Local_ShareStr = cMETE_Download_Upload_Path.Local_ShareStr; //Local_Folder_MODEL = cMETE_Download_Upload_Path.Local_Folder_MODEL; //Local_Folder_CAM = cMETE_Download_Upload_Path.Local_Folder_CAM; //Local_Folder_OIS = cMETE_Download_Upload_Path.Local_Folder_OIS; //取代字串成正確路徑 //Local_ShareStr = Local_ShareStr.Replace("[Local_IP]", Local_IP); //Local_ShareStr = Local_ShareStr.Replace("[CusName]", CurrentCusName); //Local_ShareStr = Local_ShareStr.Replace("[PartNo]", CurrentPartNo); //Local_ShareStr = Local_ShareStr.Replace("[CusRev]", CurrentCusRev); //Local_ShareStr = Local_ShareStr.Replace("[OpRev]", CurrentOpRev); //Local_Folder_MODEL = Local_Folder_MODEL.Replace("[Local_ShareStr]", Local_ShareStr); //Local_Folder_CAM = Local_Folder_CAM.Replace("[Local_ShareStr]", Local_ShareStr); //Local_Folder_OIS = Local_Folder_OIS.Replace("[Local_ShareStr]", Local_ShareStr); #region (2016.12.30註解)建立Local_Folder_MODEL資料夾 //if (!File.Exists(Local_Folder_MODEL)) //{ // try // { // System.IO.Directory.CreateDirectory(Local_Folder_MODEL); // } // catch (System.Exception ex) // { // MessageBox.Show(ex.ToString()); // return; // } //} #endregion #region (2016.12.30註解)複製Server客戶檔案到Local_Folder_MODEL資料夾內 /* * //判斷客戶檔案是否存在 * status = System.IO.File.Exists(Server_Folder_MODEL); * if (!status) * { * MessageBox.Show("指定的檔案不存在,請再次確認"); * return; * } * * //建立Local_Folder_MODEL資料夾內客戶檔案路徑 * string Local_CusPartFullPath = string.Format(@"{0}\{1}", Local_Folder_MODEL, Path.GetFileName(Server_Folder_MODEL)); * * //判斷是否存在,不存在則開始複製 * if (!File.Exists(Local_CusPartFullPath)) * { * try * { * File.Copy(Server_Folder_MODEL, Local_CusPartFullPath, true); * } * catch (System.Exception ex) * { * CaxLog.ShowListingWindow("客戶檔案複製失敗"); * this.Close(); * } * } */ #endregion #region (註解)複製ShopDoc.xls到Local_Folder_MODEL資料夾內 /* * //判斷ShopDoc.xls是否存在 * if (!File.Exists(Server_ShopDoc)) * { * listBox1.Items.Add("刀具路徑與清單樣板(ShopDoc.xls)不存在,無法下載"); * return; * } * * //建立Local_Folder_MODEL資料夾內客戶檔案路徑 * string Local_ShopDocFullPath = string.Format(@"{0}\{1}", Local_Folder_MODEL, Path.GetFileName(Server_ShopDoc)); * * //判斷是否存在,不存在則開始複製 * if (!File.Exists(Local_ShopDocFullPath)) * { * try * { * File.Copy(Server_ShopDoc, Local_ShopDocFullPath, true); * } * catch (System.Exception ex) * { * CaxLog.ShowListingWindow("ShopDoc.xls下載失敗"); * this.Close(); * } * } */ #endregion #region 先刪除本機中該製程的OPxxx->CAM資料夾、TEpart檔 //刪除本機OPxxx資料夾路徑 foreach (string i in Oper1comboBox.Items) { if (Oper1comboBox.Text == "全部下載") { if (i == "全部下載") { continue; } } else { if (i != Oper1comboBox.Text) { continue; } } Local_Folder_CAM = sDownUpLoadDat.Local_Folder_CAM; Local_Folder_CAM = Local_Folder_CAM.Replace("[Oper1]", i); if (Directory.Exists(Local_Folder_CAM)) { Directory.Delete(Local_Folder_CAM, true); } } /* * for (int i = 0; i < Oper1comboBox.Items.Count; i++) * { * if (CurrentOper1 != Oper1comboBox.Items[i].ToString() & CurrentOper1 != "全部下載") * { * continue; * } * string Local_OPxxxPath = string.Format(@"{0}\{1}\{2}", Local_ShareStr, "OP" + Oper1comboBox.Items[i].ToString(), "CAM"); * if (Directory.Exists(Local_OPxxxPath)) * { * Directory.Delete(Local_OPxxxPath, true); * } * string Local_TEpartPath = string.Format(@"{0}\{1}", Local_ShareStr, CurrentPartNo + "_TE_" + Oper1comboBox.Items[i].ToString() + ".prt"); * if (File.Exists(Local_TEpartPath)) * { * File.Delete(Local_TEpartPath); * } * } */ /* * string Local_OPxxxPath = string.Format(@"{0}\{1}\{2}", Local_ShareStr, "OP" + CurrentOper1, "CAM"); * if (Directory.Exists(Local_OPxxxPath)) * { * Directory.Delete(Local_OPxxxPath, true); * } * string Local_TEpartPath = string.Format(@"{0}\{1}", Local_ShareStr, CurrentPartNo + "_TE_" + CurrentOper1 + ".prt"); * if (File.Exists(Local_TEpartPath)) * { * File.Delete(Local_TEpartPath); * } */ #endregion #region 建立Local_Folder_CAM、Local_Folder_OIS資料夾 //暫存一個tempLocal_Folder_CAM、Local_Folder_OIS,目的要讓程式每次都能有[Oper1]可取代 //tempLocal_Folder_CAM = Local_Folder_CAM; //tempLocal_Folder_OIS = Local_Folder_OIS; //tempServer_Folder_CAM = Server_Folder_CAM; ListDownloadCAMPath = new List <CAMPath>(); foreach (string i in Oper1comboBox.Items) { if (Oper1comboBox.Text == "全部下載") { if (i == "全部下載") { continue; } } else { if (i != Oper1comboBox.Text) { continue; } } Local_Folder_CAM = sDownUpLoadDat.Local_Folder_CAM; Local_Folder_OIS = sDownUpLoadDat.Local_Folder_OIS; Local_Folder_CAM = Local_Folder_CAM.Replace("[Oper1]", i); Local_Folder_OIS = Local_Folder_OIS.Replace("[Oper1]", i); if (!File.Exists(Local_Folder_CAM)) { System.IO.Directory.CreateDirectory(Local_Folder_CAM); } if (!File.Exists(Local_Folder_OIS)) { System.IO.Directory.CreateDirectory(Local_Folder_OIS); } Server_Folder_CAM = sDownUpLoadDat.Server_Folder_CAM; Server_Folder_CAM = Server_Folder_CAM.Replace("[Oper1]", i.ToString()); CAMPath sCAMPath = new CAMPath(); sCAMPath.L_CAM_Path = Local_Folder_CAM; sCAMPath.S_CAM_Path = Server_Folder_CAM; ListDownloadCAMPath.Add(sCAMPath); } /* * if (CurrentOper1 == "全部下載") * { * for (int i = 0; i < Oper1comboBox.Items.Count; i++) * { * if (Oper1comboBox.Items[i].ToString() == "全部下載") * { * continue; * } * Local_Folder_CAM = tempLocal_Folder_CAM; * Local_Folder_OIS = tempLocal_Folder_OIS; * Local_Folder_CAM = Local_Folder_CAM.Replace("[Oper1]", Oper1comboBox.Items[i].ToString()); * Local_Folder_OIS = Local_Folder_OIS.Replace("[Oper1]", Oper1comboBox.Items[i].ToString()); * if (!File.Exists(Local_Folder_CAM)) * { * try * { * System.IO.Directory.CreateDirectory(Local_Folder_CAM); * } * catch (System.Exception ex) * { * MessageBox.Show(ex.ToString()); * return; * } * } * if (!File.Exists(Local_Folder_OIS)) * { * try * { * System.IO.Directory.CreateDirectory(Local_Folder_OIS); * } * catch (System.Exception ex) * { * MessageBox.Show(ex.ToString()); * return; * } * } * Server_Folder_CAM = tempServer_Folder_CAM; * Server_Folder_CAM = Server_Folder_CAM.Replace("[Oper1]", Oper1comboBox.Items[i].ToString()); * CAMPath sCAMPath = new CAMPath(); * sCAMPath.L_CAM_Path = Local_Folder_CAM; * sCAMPath.S_CAM_Path = Server_Folder_CAM; * ListDownloadCAMPath.Add(sCAMPath); * } * } * else * { * Local_Folder_CAM = tempLocal_Folder_CAM; * Local_Folder_OIS = tempLocal_Folder_OIS; * Local_Folder_CAM = Local_Folder_CAM.Replace("[Oper1]", CurrentOper1); * Local_Folder_OIS = Local_Folder_OIS.Replace("[Oper1]", CurrentOper1); * if (!File.Exists(Local_Folder_CAM)) * { * try * { * System.IO.Directory.CreateDirectory(Local_Folder_CAM); * } * catch (System.Exception ex) * { * MessageBox.Show(ex.ToString()); * return; * } * } * if (!File.Exists(Local_Folder_OIS)) * { * try * { * System.IO.Directory.CreateDirectory(Local_Folder_OIS); * } * catch (System.Exception ex) * { * MessageBox.Show(ex.ToString()); * return; * } * } * Server_Folder_CAM = tempServer_Folder_CAM; * Server_Folder_CAM = Server_Folder_CAM.Replace("[Oper1]", CurrentOper1); * CAMPath sCAMPath = new CAMPath(); * sCAMPath.L_CAM_Path = Local_Folder_CAM; * sCAMPath.S_CAM_Path = Server_Folder_CAM; * ListDownloadCAMPath.Add(sCAMPath); * } */ /* * //DicSeleOper1(Key = 製程序,Value = ServerPartPath) * foreach (KeyValuePair<string, string> kvp in DicSeleOper1) * { * Local_Folder_CAM = tempLocal_Folder_CAM; * Local_Folder_OIS = tempLocal_Folder_OIS; * Local_Folder_CAM = Local_Folder_CAM.Replace("[Oper1]", kvp.Key); * Local_Folder_OIS = Local_Folder_OIS.Replace("[Oper1]", kvp.Key); * if (!File.Exists(Local_Folder_CAM)) * { * try * { * System.IO.Directory.CreateDirectory(Local_Folder_CAM); * } * catch (System.Exception ex) * { * MessageBox.Show(ex.ToString()); * return; * } * } * if (!File.Exists(Local_Folder_OIS)) * { * try * { * System.IO.Directory.CreateDirectory(Local_Folder_OIS); * } * catch (System.Exception ex) * { * MessageBox.Show(ex.ToString()); * return; * } * } * } */ #endregion #region 複製Server製程序檔案到Local資料夾內 foreach (string i in ListDownloadPartPath) { //刪除本機TEpart string Local_TEpart = string.Format(@"{0}\{1}", sDownUpLoadDat.Local_ShareStr, Path.GetFileName(i)); if (File.Exists(Local_TEpart)) { File.Delete(Local_TEpart); } //判斷Part檔案是否存在 if (!File.Exists(i)) { CaxLog.ShowListingWindow("製程序檔案" + Path.GetFileName(i) + "不存在,請再次確認"); this.Close(); } //建立Local_ShareStr資料夾內製程序檔案路徑 string Local_Oper1PartFullPath = string.Format(@"{0}\{1}", sDownUpLoadDat.Local_ShareStr, Path.GetFileName(i)); //開始複製 try { File.Copy(i, Local_Oper1PartFullPath, true); } catch (System.Exception ex) { CaxLog.ShowListingWindow(Path.GetFileName(i) + "下載失敗"); this.Close(); } } /* * foreach (KeyValuePair<string, string> kvp in DicSeleOper1) * { * //判斷製程序檔案是否存在 * Server_TEDownloadPart = tempServer_TEDownloadPart; * Server_TEDownloadPart = Server_TEDownloadPart.Replace("[Oper1]", kvp.Key); * status = System.IO.File.Exists(Server_TEDownloadPart); * if (!status) * { * MessageBox.Show("製程序檔案" + Path.GetFileName(Server_TEDownloadPart) + "不存在,請再次確認"); * return; * } * * //建立Local_ShareStr資料夾內製程序檔案路徑 * string Local_Oper1PartFullPath = string.Format(@"{0}\{1}", Local_ShareStr, Path.GetFileName(Server_TEDownloadPart)); * * //開始複製 * File.Copy(Server_TEDownloadPart, Local_Oper1PartFullPath, true); * } */ #endregion #region 複製ServerCAM資料夾到Local資料夾內 foreach (CAMPath i in ListDownloadCAMPath) { status = CaxPublic.DirectoryCopy(i.S_CAM_Path, i.L_CAM_Path, true); if (!status) { MessageBox.Show("CAM資料夾複製失敗,請聯繫開發工程師"); this.Close(); } } #endregion MessageBox.Show("下載完成!"); this.Close(); }
private void Ins_OK_Click(object sender, EventArgs e) { try { status = DataChecked(); if (!status) { MessageBox.Show("Data檢查失敗"); return; } string AssignExcelType = ""; if (FAIcheckBox.Checked == true) { AssignExcelType = FAIcheckBox.Text; } if (IQCcheckBox.Checked == true) { AssignExcelType = IQCcheckBox.Text; } if (IPQCcheckBox.Checked == true) { AssignExcelType = IPQCcheckBox.Text; } if (FQCcheckBox.Checked == true) { AssignExcelType = FQCcheckBox.Text; } foreach (KeyValuePair <NXObject, string> kvp in DicSelDimension) { //取得原始顏色 int oldColor = CaxME.GetDimensionColor(kvp.Key); if (oldColor == -1) { oldColor = 125; } //取得檢具顏色 AssignGaugeDlg.GaugeData cGaugeData = new AssignGaugeDlg.GaugeData(); if (SelfCheckGauge.Text != "") { status = DicGaugeData.TryGetValue(SelfCheckGauge.Text, out cGaugeData); if (!status) { CaxLog.ShowListingWindow("此檢具資料可能有誤"); return; } } if (Gauge.Text != "") { status = DicGaugeData.TryGetValue(Gauge.Text, out cGaugeData); if (!status) { CaxLog.ShowListingWindow("此檢具資料可能有誤"); return; } } //改變標註尺寸顏色 CaxME.SetDimensionColor(kvp.Key, Convert.ToInt32(cGaugeData.Color)); //塞屬性 kvp.Key.SetAttribute(CaxME.DimenAttr.OldColor, oldColor.ToString());//舊顏色 kvp.Key.SetAttribute(CaxME.DimenAttr.AssignExcelType, AssignExcelType); if (Gauge.Text != "") { kvp.Key.SetAttribute(CaxME.DimenAttr.Gauge, Gauge.Text);//檢具名稱 } if (Freq_0.Text != "" & Freq_1.Text != "" & Freq_Units.Text != "") { kvp.Key.SetAttribute(CaxME.DimenAttr.Frequency, Freq_0.Text + "PC/" + Freq_1.Text + Freq_Units.Text);//頻率 } if (SelfCheckGauge.Text != "") { kvp.Key.SetAttribute("SelfCheckExcel", "SelfCheck"); kvp.Key.SetAttribute(CaxME.DimenAttr.SelfCheck_Gauge, SelfCheckGauge.Text); //檢具名稱 kvp.Key.SetAttribute(CaxME.DimenAttr.SelfCheck_Freq, SelfCheck_0.Text + "PC/" + SelfCheck_1.Text + SelfCheck_Units.Text); //SelfCheck } } //對零件塞上excelType屬性,說明此次尺寸是出哪一張excel(此屬性是給MEUpload時插入資料庫所使用) string excelType = ""; if (FAIcheckBox.Checked == true) { try { excelType = workPart.GetStringAttribute("ExcelType"); } catch (System.Exception ex) { excelType = ""; } if (excelType != "" && !excelType.Contains("FAI")) { excelType = excelType + "," + "FAI"; workPart.SetAttribute("ExcelType", excelType); } if (excelType == "") { workPart.SetAttribute("ExcelType", "FAI"); } } if (IQCcheckBox.Checked == true) { try { excelType = workPart.GetStringAttribute("ExcelType"); } catch (System.Exception ex) { excelType = ""; } if (excelType != "" && !excelType.Contains("IQC")) { excelType = excelType + "," + "IQC"; workPart.SetAttribute("ExcelType", excelType); } if (excelType == "") { workPart.SetAttribute("ExcelType", "IQC"); } } if (IPQCcheckBox.Checked == true) { try { excelType = workPart.GetStringAttribute("ExcelType"); } catch (System.Exception ex) { excelType = ""; } if (excelType != "" && !excelType.Contains("IPQC")) { excelType = excelType + "," + "IPQC"; workPart.SetAttribute("ExcelType", excelType); } if (excelType == "") { workPart.SetAttribute("ExcelType", "IPQC"); } } if (FQCcheckBox.Checked == true) { try { excelType = workPart.GetStringAttribute("ExcelType"); } catch (System.Exception ex) { excelType = ""; } if (excelType != "" && !excelType.Contains("FQC")) { excelType = excelType + "," + "FQC"; workPart.SetAttribute("ExcelType", excelType); } if (excelType == "") { workPart.SetAttribute("ExcelType", "FQC"); } } if (SelfCheckGauge.Text != "") { try { excelType = workPart.GetStringAttribute("ExcelType"); } catch (System.Exception ex) { excelType = ""; } if (excelType != "" && !excelType.Contains("SelfCheck")) { excelType = excelType + "," + "SelfCheck"; workPart.SetAttribute("ExcelType", excelType); } if (excelType == "") { workPart.SetAttribute("ExcelType", "SelfCheck"); } } } catch (System.Exception ex) { return; } MessageBox.Show("Assign成功"); SelDimen.Text = "選擇物件(0)"; }
private void OK_Click(object sender, EventArgs e) { //Part上傳 List <string> ListPartName = new List <string>(); string[] PartText; foreach (KeyValuePair <string, PartDirData> kvp in DicPartDirData) { //判斷Part是否存在 if (!File.Exists(kvp.Value.PartLocalDir)) { CaxLog.ShowListingWindow("Part不存在,無法上傳"); return; } try { File.Copy(kvp.Value.PartLocalDir, kvp.Value.PartServer1Dir, true); } catch (System.Exception ex) { CaxLog.ShowListingWindow(Path.GetFileName(kvp.Value.PartLocalDir) + "上傳失敗"); this.Close(); } ListPartName.Add(kvp.Key + ".prt"); } PartText = ListPartName.ToArray(); System.IO.File.WriteAllLines(string.Format(@"{0}\{1}", Server_OP_Folder, "PartNameText_OIS.txt"), PartText); //Excel上傳 if (File.Exists(sExcelDirData.ExcelIPQCLocalDir)) { try { File.Copy(sExcelDirData.ExcelIPQCLocalDir, sExcelDirData.ExcelIPQCServerDir, true); } catch (System.Exception ex) { CaxLog.ShowListingWindow("IPQC.xls上傳失敗"); this.Close(); } } if (File.Exists(sExcelDirData.ExcelSelfCheckLocalDir)) { try { File.Copy(sExcelDirData.ExcelSelfCheckLocalDir, sExcelDirData.ExcelSelfCheckServerDir, true); } catch (System.Exception ex) { CaxLog.ShowListingWindow("SelfCheck.xls上傳失敗"); this.Close(); } } if (File.Exists(sExcelDirData.ExcelIQCLocalDir)) { try { File.Copy(sExcelDirData.ExcelIQCLocalDir, sExcelDirData.ExcelIQCServerDir, true); } catch (System.Exception ex) { CaxLog.ShowListingWindow("IQC.xls上傳失敗"); this.Close(); } } if (File.Exists(sExcelDirData.ExcelFAILocalDir)) { try { File.Copy(sExcelDirData.ExcelFAILocalDir, sExcelDirData.ExcelFAIServerDir, true); } catch (System.Exception ex) { CaxLog.ShowListingWindow("FAI.xls上傳失敗"); this.Close(); } } MessageBox.Show("上傳完成!"); this.Close(); }
//------------------------------------------------------------------------------ // Explicit Activation // This entry point is used to activate the application explicitly //------------------------------------------------------------------------------ public static int Main(string[] args) { int retValue = 0; try { theProgram = new Program(); Session theSession = Session.GetSession(); Part workPart = theSession.Parts.Work; Part displayPart = theSession.Parts.Display; DefineVariable.Is_Local = Environment.GetEnvironmentVariable("UGII_ENV_FILE"); if (DefineVariable.Is_Local != "") { //取得本機"FAI.xls路徑 DefineVariable.FAIPath = string.Format(@"{0}\{1}\{2}", Path.GetDirectoryName(displayPart.FullPath), "MODEL", "FAI.xls"); } //取得料號 string PartNo = Path.GetFileNameWithoutExtension(displayPart.FullPath); //取得零件名稱 string PartDescription = ""; try { PartDescription = displayPart.GetStringAttribute("PARTDESCRIPTIONPOS"); } catch (System.Exception ex) { PartDescription = ""; } int SheetCount = 0; NXOpen.Tag[] SheetTagAry = null; theUfSession.Draw.AskDrawings(out SheetCount, out SheetTagAry); DefineVariable.DicDimenData = new Dictionary <string, TextData>(); for (int i = 0; i < SheetCount; i++) { //打開Sheet並記錄所有OBJ NXOpen.Drawings.DrawingSheet CurrentSheet = (NXOpen.Drawings.DrawingSheet)NXObjectManager.Get(SheetTagAry[i]); CurrentSheet.Open(); if (i == 0) { //記錄第一張Sheet DefineVariable.FirstDrawingSheet = CurrentSheet; } DisplayableObject[] SheetObj = CurrentSheet.View.AskVisibleObjects(); foreach (DisplayableObject singleObj in SheetObj) { TextData cTextData = new TextData(); string singleObjType = singleObj.GetType().ToString(); string FAI_Gauge = "", BallonNum = "", Frequency = "", Location = ""; string[] mainText; string[] dualText; #region 取FAI共用屬性(泡泡值、檢具名稱、檢驗頻率、泡泡所在區域),如果都沒屬性就找下一個 try { FAI_Gauge = singleObj.GetStringAttribute(CaxME.DimenAttr.FAI_Gauge); BallonNum = singleObj.GetStringAttribute(CaxME.DimenAttr.BallonNum); Frequency = singleObj.GetStringAttribute(CaxME.DimenAttr.FAI_Freq); Location = singleObj.GetStringAttribute(CaxME.DimenAttr.BallonLocation); } catch (System.Exception ex) { FAI_Gauge = ""; } if (FAI_Gauge == "") { continue; } #endregion #region 紀錄共用屬性(泡泡值、檢具名稱、檢驗頻率、泡泡所在區域) //取得泡泡值 cTextData.BallonNum = BallonNum; //取得檢具名稱 cTextData.Gauge = FAI_Gauge; //取得檢驗頻率 cTextData.Frequency = Frequency; //取得泡泡所在區域 cTextData.Location = Location; #endregion if (singleObjType == "NXOpen.Annotations.VerticalDimension") { #region VerticalDimension取Text cTextData.Type = "NXOpen.Annotations.VerticalDimension"; NXOpen.Annotations.VerticalDimension temp = (NXOpen.Annotations.VerticalDimension)singleObj; temp.GetDimensionText(out mainText, out dualText); if (mainText.Length > 0) { cTextData.MainText = mainText[0]; } if (temp.GetAppendedText().GetBeforeText().Length > 0) { cTextData.BeforeText = temp.GetAppendedText().GetBeforeText()[0].ToString(); } if (temp.GetAppendedText().GetAfterText().Length > 0) { cTextData.AfterText = temp.GetAppendedText().GetAfterText()[0].ToString(); } if (temp.GetAppendedText().GetAboveText().Length > 0) { cTextData.AboveText = temp.GetAppendedText().GetAboveText()[0].ToString(); } if (temp.GetAppendedText().GetBelowText().Length > 0) { cTextData.BelowText = temp.GetAppendedText().GetBelowText()[0].ToString(); } if (temp.ToleranceType.ToString() == "BilateralOneLine") { cTextData.TolType = "BilateralOneLine"; cTextData.UpperTol = temp.UpperMetricToleranceValue.ToString(); cTextData.LowerTol = (-1 * temp.UpperMetricToleranceValue).ToString(); } #endregion } else if (singleObjType == "NXOpen.Annotations.PerpendicularDimension") { #region PerpendicularDimension取Text cTextData.Type = "NXOpen.Annotations.PerpendicularDimension"; NXOpen.Annotations.PerpendicularDimension temp = (NXOpen.Annotations.PerpendicularDimension)singleObj; temp.GetDimensionText(out mainText, out dualText); if (mainText.Length > 0) { cTextData.MainText = mainText[0]; } if (temp.GetAppendedText().GetBeforeText().Length > 0) { cTextData.BeforeText = temp.GetAppendedText().GetBeforeText()[0].ToString(); } if (temp.GetAppendedText().GetAfterText().Length > 0) { cTextData.AfterText = temp.GetAppendedText().GetAfterText()[0].ToString(); } if (temp.GetAppendedText().GetAboveText().Length > 0) { cTextData.AboveText = temp.GetAppendedText().GetAboveText()[0].ToString(); } if (temp.GetAppendedText().GetBelowText().Length > 0) { cTextData.BelowText = temp.GetAppendedText().GetBelowText()[0].ToString(); } if (temp.ToleranceType.ToString() == "BilateralOneLine") { cTextData.TolType = "BilateralOneLine"; cTextData.UpperTol = temp.UpperMetricToleranceValue.ToString(); cTextData.LowerTol = (-1 * temp.UpperMetricToleranceValue).ToString(); } #endregion } else if (singleObjType == "NXOpen.Annotations.MinorAngularDimension") { #region MinorAngularDimension取Text cTextData.Type = "NXOpen.Annotations.MinorAngularDimension"; NXOpen.Annotations.MinorAngularDimension temp = (NXOpen.Annotations.MinorAngularDimension)singleObj; temp.GetDimensionText(out mainText, out dualText); if (mainText.Length > 0) { cTextData.MainText = mainText[0]; } if (temp.GetAppendedText().GetBeforeText().Length > 0) { cTextData.BeforeText = temp.GetAppendedText().GetBeforeText()[0].ToString(); } if (temp.GetAppendedText().GetAfterText().Length > 0) { cTextData.AfterText = temp.GetAppendedText().GetAfterText()[0].ToString(); } if (temp.GetAppendedText().GetAboveText().Length > 0) { cTextData.AboveText = temp.GetAppendedText().GetAboveText()[0].ToString(); } if (temp.GetAppendedText().GetBelowText().Length > 0) { cTextData.BelowText = temp.GetAppendedText().GetBelowText()[0].ToString(); } if (temp.ToleranceType.ToString() == "BilateralOneLine") { cTextData.TolType = "BilateralOneLine"; cTextData.UpperTol = temp.UpperMetricToleranceValue.ToString(); cTextData.LowerTol = (-1 * temp.UpperMetricToleranceValue).ToString(); } #endregion } else if (singleObjType == "NXOpen.Annotations.RadiusDimension") { #region MinorAngularDimension取Text cTextData.Type = "NXOpen.Annotations.RadiusDimension"; NXOpen.Annotations.RadiusDimension temp = (NXOpen.Annotations.RadiusDimension)singleObj; temp.GetDimensionText(out mainText, out dualText); if (mainText.Length > 0) { cTextData.MainText = mainText[0]; } if (temp.GetAppendedText().GetBeforeText().Length > 0) { cTextData.BeforeText = temp.GetAppendedText().GetBeforeText()[0].ToString(); } if (temp.GetAppendedText().GetAfterText().Length > 0) { cTextData.AfterText = temp.GetAppendedText().GetAfterText()[0].ToString(); } if (temp.GetAppendedText().GetAboveText().Length > 0) { cTextData.AboveText = temp.GetAppendedText().GetAboveText()[0].ToString(); } if (temp.GetAppendedText().GetBelowText().Length > 0) { cTextData.BelowText = temp.GetAppendedText().GetBelowText()[0].ToString(); } if (temp.ToleranceType.ToString() == "BilateralOneLine") { cTextData.TolType = "BilateralOneLine"; cTextData.UpperTol = temp.UpperMetricToleranceValue.ToString(); cTextData.LowerTol = (-1 * temp.UpperMetricToleranceValue).ToString(); } #endregion } else if (singleObjType == "NXOpen.Annotations.HorizontalDimension") { #region HorizontalDimension取Text cTextData.Type = "NXOpen.Annotations.HorizontalDimension"; NXOpen.Annotations.HorizontalDimension temp = (NXOpen.Annotations.HorizontalDimension)singleObj; temp.GetDimensionText(out mainText, out dualText); if (mainText.Length > 0) { cTextData.MainText = mainText[0]; } if (temp.GetAppendedText().GetBeforeText().Length > 0) { cTextData.BeforeText = temp.GetAppendedText().GetBeforeText()[0].ToString(); } if (temp.GetAppendedText().GetAfterText().Length > 0) { cTextData.AfterText = temp.GetAppendedText().GetAfterText()[0].ToString(); } if (temp.GetAppendedText().GetAboveText().Length > 0) { cTextData.AboveText = temp.GetAppendedText().GetAboveText()[0].ToString(); } if (temp.GetAppendedText().GetBelowText().Length > 0) { cTextData.BelowText = temp.GetAppendedText().GetBelowText()[0].ToString(); } if (temp.ToleranceType.ToString() == "BilateralOneLine") { cTextData.TolType = "BilateralOneLine"; cTextData.UpperTol = temp.UpperMetricToleranceValue.ToString(); cTextData.LowerTol = (-1 * temp.UpperMetricToleranceValue).ToString(); } if (temp.ToleranceType.ToString() == "BilateralTwoLines") { cTextData.TolType = "BilateralOneLine"; cTextData.UpperTol = temp.UpperMetricToleranceValue.ToString(); cTextData.LowerTol = temp.LowerMetricToleranceValue.ToString(); } if (temp.ToleranceType.ToString() == "UnilateralAbove") { cTextData.TolType = "UnilateralAbove"; cTextData.UpperTol = temp.UpperMetricToleranceValue.ToString(); cTextData.LowerTol = "0"; } if (temp.ToleranceType.ToString() == "UnilateralBelow") { cTextData.TolType = "UnilateralBelow"; cTextData.UpperTol = "0"; cTextData.LowerTol = temp.LowerMetricToleranceValue.ToString(); } #endregion } else if (singleObjType == "NXOpen.Annotations.IdSymbol") { #region IdSymbol取Text cTextData.Type = "NXOpen.Annotations.IdSymbol"; NXOpen.Annotations.IdSymbol temp = (NXOpen.Annotations.IdSymbol)singleObj; #endregion } else if (singleObjType == "NXOpen.Annotations.Note") { #region Note取Text cTextData.Type = "NXOpen.Annotations.Note"; NXOpen.Annotations.Note temp = (NXOpen.Annotations.Note)singleObj; //判斷是否由CAX產生的Note string createby = ""; try { createby = temp.GetStringAttribute("Createby"); } catch (System.Exception ex) { createby = ""; } if (createby == "") { string tempStr = temp.GetText()[0].Replace("<F2>", ""); tempStr = tempStr.Replace("<F>", ""); cTextData.MainText = tempStr; } else { cTextData.MainText = temp.GetText()[0]; } #endregion } else if (singleObjType == "NXOpen.Annotations.DraftingFcf") { #region DraftingFcf取Text NXOpen.Annotations.DraftingFcf temp = (NXOpen.Annotations.DraftingFcf)singleObj; CaxME.FcfData sFcfData = new CaxME.FcfData(); CaxME.GetFcfData(temp, out sFcfData); cTextData.Type = "NXOpen.Annotations.DraftingFcf"; cTextData.Characteristic = sFcfData.Characteristic; cTextData.ZoneShape = sFcfData.ZoneShape; cTextData.ToleranceValue = sFcfData.ToleranceValue; cTextData.MaterialModifier = sFcfData.MaterialModifier; cTextData.PrimaryDatum = sFcfData.PrimaryDatum; cTextData.PrimaryMaterialModifier = sFcfData.PrimaryMaterialModifier; cTextData.SecondaryDatum = sFcfData.SecondaryDatum; cTextData.SecondaryMaterialModifier = sFcfData.SecondaryMaterialModifier; cTextData.TertiaryDatum = sFcfData.TertiaryDatum; cTextData.TertiaryMaterialModifier = sFcfData.TertiaryMaterialModifier; #endregion } else if (singleObjType == "NXOpen.Annotations.Label") { #region Label取Text cTextData.Type = "NXOpen.Annotations.Label"; NXOpen.Annotations.Label temp = (NXOpen.Annotations.Label)singleObj; cTextData.MainText = temp.GetText()[0]; #endregion } else if (singleObjType == "NXOpen.Annotations.DraftingDatum") { #region DraftingDatum取Text cTextData.Type = "NXOpen.Annotations.DraftingDatum"; NXOpen.Annotations.DraftingDatum temp = (NXOpen.Annotations.DraftingDatum)singleObj; #endregion } else if (singleObjType == "NXOpen.Annotations.DiameterDimension") { #region DiameterDimension取Text cTextData.Type = "NXOpen.Annotations.DiameterDimension"; NXOpen.Annotations.DiameterDimension temp = (NXOpen.Annotations.DiameterDimension)singleObj; temp.GetDimensionText(out mainText, out dualText); if (mainText.Length > 0) { cTextData.MainText = mainText[0]; } if (temp.GetAppendedText().GetBeforeText().Length > 0) { cTextData.BeforeText = temp.GetAppendedText().GetBeforeText()[0].ToString(); } if (temp.GetAppendedText().GetAfterText().Length > 0) { cTextData.AfterText = temp.GetAppendedText().GetAfterText()[0].ToString(); } if (temp.GetAppendedText().GetAboveText().Length > 0) { cTextData.AboveText = temp.GetAppendedText().GetAboveText()[0].ToString(); } if (temp.GetAppendedText().GetBelowText().Length > 0) { cTextData.BelowText = temp.GetAppendedText().GetBelowText()[0].ToString(); } if (temp.ToleranceType.ToString() == "BilateralOneLine") { cTextData.TolType = "BilateralOneLine"; cTextData.UpperTol = temp.UpperMetricToleranceValue.ToString(); cTextData.LowerTol = (-1 * temp.UpperMetricToleranceValue).ToString(); } #endregion } else if (singleObjType == "NXOpen.Annotations.AngularDimension") { #region AngularDimension取Text cTextData.Type = "NXOpen.Annotations.AngularDimension"; NXOpen.Annotations.AngularDimension temp = (NXOpen.Annotations.AngularDimension)singleObj; temp.GetDimensionText(out mainText, out dualText); if (mainText.Length > 0) { cTextData.MainText = mainText[0]; } if (temp.GetAppendedText().GetBeforeText().Length > 0) { cTextData.BeforeText = temp.GetAppendedText().GetBeforeText()[0].ToString(); } if (temp.GetAppendedText().GetAfterText().Length > 0) { cTextData.AfterText = temp.GetAppendedText().GetAfterText()[0].ToString(); } if (temp.GetAppendedText().GetAboveText().Length > 0) { cTextData.AboveText = temp.GetAppendedText().GetAboveText()[0].ToString(); } if (temp.GetAppendedText().GetBelowText().Length > 0) { cTextData.BelowText = temp.GetAppendedText().GetBelowText()[0].ToString(); } if (temp.ToleranceType.ToString() == "BilateralOneLine") { cTextData.TolType = "BilateralOneLine"; cTextData.UpperTol = temp.UpperMetricToleranceValue.ToString(); cTextData.LowerTol = (-1 * temp.UpperMetricToleranceValue).ToString(); } #endregion } else if (singleObjType == "NXOpen.Annotations.CylindricalDimension") { #region CylindricalDimension取Text cTextData.Type = "NXOpen.Annotations.CylindricalDimension"; NXOpen.Annotations.CylindricalDimension temp = (NXOpen.Annotations.CylindricalDimension)singleObj; temp.GetDimensionText(out mainText, out dualText); if (mainText.Length > 0) { cTextData.MainText = mainText[0]; } if (temp.GetAppendedText().GetBeforeText().Length > 0) { cTextData.BeforeText = temp.GetAppendedText().GetBeforeText()[0].ToString(); } if (temp.GetAppendedText().GetAfterText().Length > 0) { cTextData.AfterText = temp.GetAppendedText().GetAfterText()[0].ToString(); } if (temp.GetAppendedText().GetAboveText().Length > 0) { cTextData.AboveText = temp.GetAppendedText().GetAboveText()[0].ToString(); } if (temp.GetAppendedText().GetBelowText().Length > 0) { cTextData.BelowText = temp.GetAppendedText().GetBelowText()[0].ToString(); } if (temp.ToleranceType.ToString() == "BilateralOneLine") { cTextData.TolType = "BilateralOneLine"; cTextData.UpperTol = temp.UpperMetricToleranceValue.ToString(); cTextData.LowerTol = (-1 * temp.UpperMetricToleranceValue).ToString(); } if (temp.ToleranceType.ToString() == "BilateralTwoLines") { cTextData.TolType = "BilateralOneLine"; cTextData.UpperTol = temp.UpperMetricToleranceValue.ToString(); cTextData.LowerTol = temp.LowerMetricToleranceValue.ToString(); } if (temp.ToleranceType.ToString() == "UnilateralAbove") { cTextData.TolType = "UnilateralAbove"; cTextData.UpperTol = temp.UpperMetricToleranceValue.ToString(); cTextData.LowerTol = "0"; } if (temp.ToleranceType.ToString() == "UnilateralBelow") { cTextData.TolType = "UnilateralBelow"; cTextData.UpperTol = "0"; cTextData.LowerTol = temp.LowerMetricToleranceValue.ToString(); } #endregion } else if (singleObjType == "NXOpen.Annotations.ChamferDimension") { #region ChamferDimension取Text cTextData.Type = "NXOpen.Annotations.ChamferDimension"; NXOpen.Annotations.ChamferDimension temp = (NXOpen.Annotations.ChamferDimension)singleObj; temp.GetDimensionText(out mainText, out dualText); if (mainText.Length > 0) { cTextData.MainText = mainText[0] + "X" + "45" + "<$s>"; } if (temp.GetAppendedText().GetBeforeText().Length > 0) { cTextData.BeforeText = temp.GetAppendedText().GetBeforeText()[0].ToString(); } if (temp.GetAppendedText().GetAfterText().Length > 0) { cTextData.AfterText = temp.GetAppendedText().GetAfterText()[0].ToString(); } if (temp.GetAppendedText().GetAboveText().Length > 0) { cTextData.AboveText = temp.GetAppendedText().GetAboveText()[0].ToString(); } if (temp.GetAppendedText().GetBelowText().Length > 0) { cTextData.BelowText = temp.GetAppendedText().GetBelowText()[0].ToString(); } if (temp.ToleranceType.ToString() == "BilateralOneLine") { cTextData.TolType = "BilateralOneLine"; cTextData.UpperTol = temp.UpperMetricToleranceValue.ToString(); cTextData.LowerTol = (-1 * temp.UpperMetricToleranceValue).ToString(); } if (temp.ToleranceType.ToString() == "BilateralTwoLines") { cTextData.TolType = "BilateralOneLine"; cTextData.UpperTol = temp.UpperMetricToleranceValue.ToString(); cTextData.LowerTol = temp.LowerMetricToleranceValue.ToString(); } if (temp.ToleranceType.ToString() == "UnilateralAbove") { cTextData.TolType = "UnilateralAbove"; cTextData.UpperTol = temp.UpperMetricToleranceValue.ToString(); cTextData.LowerTol = "0"; } if (temp.ToleranceType.ToString() == "UnilateralBelow") { cTextData.TolType = "UnilateralBelow"; cTextData.UpperTol = "0"; cTextData.LowerTol = temp.LowerMetricToleranceValue.ToString(); } #endregion } //計算泡泡總數 DefineVariable.BallonCount++; DefineVariable.DicDimenData[BallonNum] = cTextData; } } //設定輸出路徑--Local //string[] FolderFile = System.IO.Directory.GetFileSystemEntries(Path.GetDirectoryName(displayPart.FullPath), "*.xls"); //string OutputPath = string.Format(@"{0}\{1}", Path.GetDirectoryName(displayPart.FullPath), // Path.GetFileNameWithoutExtension(displayPart.FullPath) + "_" + "IPQC" + "_" + (FolderFile.Length + 1) + ".xls"); //設定輸出路徑--Server string OperNum = Regex.Replace(Path.GetFileNameWithoutExtension(displayPart.FullPath).Split('_')[1], "[^0-9]", ""); string Local_Folder_OIS = string.Format(@"{0}\{1}\{2}", Path.GetDirectoryName(displayPart.FullPath), "OP" + OperNum, "OIS"); if (!File.Exists(Local_Folder_OIS)) { System.IO.Directory.CreateDirectory(Local_Folder_OIS); } string[] FolderFile = System.IO.Directory.GetFileSystemEntries(Local_Folder_OIS, "*.xls"); List <string> ListFolderFileWithFAI = new List <string>(); foreach (string i in FolderFile) { if (i.Contains("FAI")) { ListFolderFileWithFAI.Add(i); } } string OutputPath = string.Format(@"{0}\{1}", Local_Folder_OIS, Path.GetFileNameWithoutExtension(displayPart.FullPath) + "_" + "FAI" + "_" + (ListFolderFileWithFAI.Count + 1) + ".xls"); //檢查PC有無Excel在執行 foreach (var item in Process.GetProcesses()) { if (item.ProcessName == "EXCEL") { CaxLog.ShowListingWindow("請先關閉所有Excel再重新執行輸出,如沒有EXCEL在執行,請開啟工作管理員關閉背景EXCEL"); return(retValue); } else { continue; } } Excel.ApplicationClass x = new Excel.ApplicationClass(); Excel.Workbook book = null; Excel.Worksheet sheet = null; Excel.Range oRng = null; try { x.Visible = false; if (DefineVariable.Is_Local != "") { if (File.Exists(DefineVariable.FAIPath)) { book = x.Workbooks.Open(DefineVariable.FAIPath); } else { book = x.Workbooks.Open(@"D:\FAI.xls"); } } else { book = x.Workbooks.Open(@"D:\FAI.xls"); } //取得第一頁sheet sheet = (Excel.Worksheet)book.Sheets[1]; #region 處理第一頁 oRng = (Excel.Range)sheet.Cells; oRng[10, 1] = PartNo; oRng[10, 2] = PartDescription; #endregion //取得第二頁sheet sheet = (Excel.Worksheet)book.Sheets[2]; #region 處理第二頁 oRng = (Excel.Range)sheet.Cells; oRng[10, 1] = PartNo; oRng[10, 2] = PartDescription; #endregion //取得第三頁sheet sheet = (Excel.Worksheet)book.Sheets[3]; #region 處理第三頁 oRng = (Excel.Range)sheet.Cells; oRng[10, 1] = PartNo; oRng[10, 5] = PartDescription; //Insert所需欄位並填入資料 int CurrentRow = 16, BallonColumn = 1, LocationColumn = 2, DimenColumn = 4, GaugeColumn = 6; for (int i = 1; i < DefineVariable.BallonCount; i++) { oRng = (Excel.Range)sheet.Range["A17"].EntireRow; oRng.Insert(Excel.XlInsertShiftDirection.xlShiftDown, Excel.XlInsertFormatOrigin.xlFormatFromRightOrBelow); } //填表 for (int i = 1; i < 1000; i++) { TextData cTextData; DefineVariable.DicDimenData.TryGetValue(i.ToString(), out cTextData); if (cTextData == null) { continue; } oRng = (Excel.Range)sheet.Cells; //取得Row,Column CurrentRow = CurrentRow + 1; if (cTextData.Type == "NXOpen.Annotations.DraftingFcf") { #region DraftingFcf填資料 if (cTextData.Characteristic != "") { oRng[CurrentRow, DimenColumn] = DefineVariable.GetCharacteristicSymbol(cTextData.Characteristic); //oRng[sRowColumn.CharacteristicRow, sRowColumn.CharacteristicColumn] = DefineVariable.GetCharacteristicSymbol(cTextData.Characteristic); } if (cTextData.ZoneShape != "") { oRng[CurrentRow, DimenColumn] = ((Excel.Range)oRng[CurrentRow, DimenColumn]).Value + DefineVariable.GetZoneShapeSymbol(cTextData.ZoneShape); //oRng[sRowColumn.ZoneShapeRow, sRowColumn.ZoneShapeColumn] = DefineVariable.GetZoneShapeSymbol(cTextData.ZoneShape); } oRng[CurrentRow, DimenColumn] = ((Excel.Range)oRng[CurrentRow, DimenColumn]).Value + cTextData.ToleranceValue; //oRng[sRowColumn.ToleranceValueRow, sRowColumn.ToleranceValueColumn] = cTextData.ToleranceValue; if (cTextData.MaterialModifier != "" & cTextData.MaterialModifier != "None") { string ValueStr = cTextData.MaterialModifier; if (ValueStr == "LeastMaterialCondition") { ValueStr = "l"; } else if (ValueStr == "MaximumMaterialCondition") { ValueStr = "m"; } else if (ValueStr == "RegardlessOfFeatureSize") { ValueStr = "s"; } oRng[CurrentRow, DimenColumn] = ((Excel.Range)oRng[CurrentRow, DimenColumn]).Value + ValueStr; //oRng[sRowColumn.MaterialModifierRow, sRowColumn.MaterialModifierColumn] = ValueStr; } //Primary oRng[CurrentRow, DimenColumn] = ((Excel.Range)oRng[CurrentRow, DimenColumn]).Value + cTextData.PrimaryDatum; //oRng[sRowColumn.PrimaryDatumRow, sRowColumn.PrimaryDatumColumn] = cTextData.PrimaryDatum; if (cTextData.PrimaryMaterialModifier != "" & cTextData.PrimaryMaterialModifier != "None") { string ValueStr = cTextData.PrimaryMaterialModifier; if (ValueStr == "LeastMaterialCondition") { ValueStr = "l"; } else if (ValueStr == "MaximumMaterialCondition") { ValueStr = "m"; } else if (ValueStr == "RegardlessOfFeatureSize") { ValueStr = "s"; } oRng[CurrentRow, DimenColumn] = ((Excel.Range)oRng[CurrentRow, DimenColumn]).Value + ValueStr; //oRng[sRowColumn.PrimaryMaterialModifierRow, sRowColumn.PrimaryMaterialModifierColumn] = ValueStr; } //Secondary oRng[CurrentRow, DimenColumn] = ((Excel.Range)oRng[CurrentRow, DimenColumn]).Value + cTextData.SecondaryDatum; //oRng[sRowColumn.SecondaryDatumRow, sRowColumn.SecondaryDatumColumn] = cTextData.SecondaryDatum; if (cTextData.SecondaryMaterialModifier != "" & cTextData.SecondaryMaterialModifier != "None") { string ValueStr = cTextData.SecondaryMaterialModifier; if (ValueStr == "LeastMaterialCondition") { ValueStr = "l"; } else if (ValueStr == "MaximumMaterialCondition") { ValueStr = "m"; } else if (ValueStr == "RegardlessOfFeatureSize") { ValueStr = "s"; } oRng[CurrentRow, DimenColumn] = ((Excel.Range)oRng[CurrentRow, DimenColumn]).Value + ValueStr; //oRng[sRowColumn.SecondaryMaterialModifierRow, sRowColumn.SecondaryMaterialModifierColumn] = ValueStr; } //Tertiary oRng[CurrentRow, DimenColumn] = ((Excel.Range)oRng[CurrentRow, DimenColumn]).Value + cTextData.TertiaryDatum; //oRng[sRowColumn.TertiaryDatumRow, sRowColumn.TertiaryDatumColumn] = cTextData.TertiaryDatum; if (cTextData.TertiaryMaterialModifier != "" & cTextData.TertiaryMaterialModifier != "None") { string ValueStr = cTextData.TertiaryMaterialModifier; if (ValueStr == "LeastMaterialCondition") { ValueStr = "l"; } else if (ValueStr == "MaximumMaterialCondition") { ValueStr = "m"; } else if (ValueStr == "RegardlessOfFeatureSize") { ValueStr = "s"; } oRng[CurrentRow, DimenColumn] = ((Excel.Range)oRng[CurrentRow, DimenColumn]).Value + ValueStr; //oRng[sRowColumn.TertiaryMaterialModifierRow, sRowColumn.TertiaryMaterialModifierColumn] = ValueStr; } #endregion } else if (cTextData.Type == "NXOpen.Annotations.Label") { oRng[CurrentRow, DimenColumn] = cTextData.MainText; //((Range)oRng[sRowColumn.MainTextRow, sRowColumn.MainTextColumn]).Interior.ColorIndex = 50; } else { #region Dimension填資料 if (cTextData.BeforeText != null) { oRng[CurrentRow, DimenColumn] = ((Excel.Range)oRng[CurrentRow, DimenColumn]).Value + DefineVariable.GetGDTWord(cTextData.BeforeText); //oRng[sRowColumn.BeforeTextRow, sRowColumn.BeforeTextColumn] = DefineVariable.GetGDTWord(cTextData.BeforeText); } oRng[CurrentRow, DimenColumn] = ((Excel.Range)oRng[CurrentRow, DimenColumn]).Value + DefineVariable.GetGDTWord(cTextData.MainText); //oRng[sRowColumn.MainTextRow, sRowColumn.MainTextColumn] = DefineVariable.GetGDTWord(cTextData.MainText); //Range a = (Range)oRng[sRowColumn.MainTextRow, sRowColumn.MainTextColumn]; //a.Interior.ColorIndex = 39; if (cTextData.UpperTol != "" & cTextData.TolType == "BilateralOneLine") { oRng[CurrentRow, DimenColumn] = ((Excel.Range)oRng[CurrentRow, DimenColumn]).Value + "±"; oRng[CurrentRow, DimenColumn] = ((Excel.Range)oRng[CurrentRow, DimenColumn]).Value + cTextData.UpperTol; string MaxMinStr = "(" + (Convert.ToDouble(cTextData.MainText) + Convert.ToDouble(cTextData.UpperTol)).ToString() + "-" + (Convert.ToDouble(cTextData.MainText) - Convert.ToDouble(cTextData.UpperTol)).ToString() + ")"; oRng[CurrentRow, DimenColumn] = ((Excel.Range)oRng[CurrentRow, DimenColumn]).Value + MaxMinStr; //oRng[sRowColumn.ToleranceSymbolRow, sRowColumn.ToleranceSymbolColumn] = "±"; //oRng[sRowColumn.UpperTolRow, sRowColumn.UpperTolColumn] = cTextData.UpperTol; } else if (cTextData.UpperTol != "" & cTextData.TolType == "BilateralTwoLines") { oRng[CurrentRow, DimenColumn] = ((Excel.Range)oRng[CurrentRow, DimenColumn]).Value + "+"; oRng[CurrentRow, DimenColumn] = ((Excel.Range)oRng[CurrentRow, DimenColumn]).Value + cTextData.UpperTol; oRng[CurrentRow, DimenColumn] = ((Excel.Range)oRng[CurrentRow, DimenColumn]).Value + "/"; oRng[CurrentRow, DimenColumn] = ((Excel.Range)oRng[CurrentRow, DimenColumn]).Value + cTextData.LowerTol; string MaxMinStr = "(" + (Convert.ToDouble(cTextData.MainText) + Convert.ToDouble(cTextData.UpperTol)).ToString() + "-" + (Convert.ToDouble(cTextData.MainText) + Convert.ToDouble(cTextData.LowerTol)).ToString() + ")"; oRng[CurrentRow, DimenColumn] = ((Excel.Range)oRng[CurrentRow, DimenColumn]).Value + MaxMinStr; } else if (cTextData.UpperTol != "" & cTextData.TolType == "UnilateralAbove") { oRng[CurrentRow, DimenColumn] = ((Excel.Range)oRng[CurrentRow, DimenColumn]).Value + "+"; oRng[CurrentRow, DimenColumn] = ((Excel.Range)oRng[CurrentRow, DimenColumn]).Value + cTextData.UpperTol; } else if (cTextData.UpperTol != "" & cTextData.TolType == "UnilateralBelow") { //oRng[CurrentRow, DimenColumn] = ((Excel.Range)oRng[CurrentRow, DimenColumn]).Value + "-"; oRng[CurrentRow, DimenColumn] = ((Excel.Range)oRng[CurrentRow, DimenColumn]).Value + cTextData.LowerTol; } #endregion } #region 檢具、頻率、Max、Min、泡泡、泡泡位置、料號、日期 oRng[CurrentRow, GaugeColumn] = cTextData.Gauge; //oRng[sRowColumn.FrequencyRow, sRowColumn.FrequencyColumn] = cTextData.Frequency; oRng[CurrentRow, BallonColumn] = cTextData.BallonNum; oRng[CurrentRow, LocationColumn] = cTextData.Location; //oRng[sRowColumn.PartNoRow, sRowColumn.PartNoColumn] = PartNo; //oRng[sRowColumn.DateRow, sRowColumn.DateColumn] = CurrentDate; #endregion } #endregion book.SaveAs(OutputPath, Excel.XlFileFormat.xlWorkbookNormal, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Excel.XlSaveAsAccessMode.xlNoChange, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing); book.Close(Type.Missing, Type.Missing, Type.Missing); x.Quit(); //切回第一張Sheet DefineVariable.FirstDrawingSheet.Open(); UI.GetUI().NXMessageBox.Show("FAI", NXMessageBox.DialogType.Information, "輸出完成"); } catch (System.Exception ex) { book.SaveAs(OutputPath, Excel.XlFileFormat.xlWorkbookNormal, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Excel.XlSaveAsAccessMode.xlNoChange, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing); book.Close(Type.Missing, Type.Missing, Type.Missing); x.Quit(); } } catch (NXOpen.NXException ex) { // ---- Enter your exception handling code here ----- } theProgram.Dispose(); return(retValue); }
private void buttonDownload_Click(object sender, EventArgs e) { //建立Local路徑資料 //string Local_IP = cMETE_Download_Upload_Path.Local_IP; //string Local_ShareStr = cMETE_Download_Upload_Path.Local_ShareStr; //Local_Folder_MODEL = cMETE_Download_Upload_Path.Local_Folder_MODEL; //Local_Folder_CAM = cMETE_Download_Upload_Path.Local_Folder_CAM; //Local_Folder_OIS = cMETE_Download_Upload_Path.Local_Folder_OIS; //取代字串成正確路徑 //Local_ShareStr = Local_ShareStr.Replace("[Local_IP]", Local_IP); //Local_ShareStr = Local_ShareStr.Replace("[CusName]", CurrentCusName); //Local_ShareStr = Local_ShareStr.Replace("[PartNo]", CurrentPartNo); //Local_ShareStr = Local_ShareStr.Replace("[CusRev]", CurrentCusRev); //Local_ShareStr = Local_ShareStr.Replace("[OpRev]", CurrentOpRev); //Local_Folder_MODEL = Local_Folder_MODEL.Replace("[Local_ShareStr]", Local_ShareStr); //Local_Folder_CAM = Local_Folder_CAM.Replace("[Local_ShareStr]", Local_ShareStr); //Local_Folder_OIS = Local_Folder_OIS.Replace("[Local_ShareStr]", Local_ShareStr); #region (2016.12.29註解)建立Local_Folder_MODEL資料夾 //if (!File.Exists(Local_Folder_MODEL)) //{ // try // { // System.IO.Directory.CreateDirectory(Local_Folder_MODEL); // } // catch (System.Exception ex) // { // MessageBox.Show(ex.ToString()); // return; // } //} #endregion #region (2016.12.29註解)複製Server客戶檔案到Local_Folder_MODEL資料夾內 //判斷客戶檔案是否存在 //status = System.IO.File.Exists(Server_Folder_MODEL); //if (!status) //{ // CaxLog.ShowListingWindow("指定的檔案不存在,請再次確認"); // this.Close(); //} //建立Local_Folder_MODEL資料夾內客戶檔案路徑 //string Local_CusPartFullPath = string.Format(@"{0}\{1}", Local_Folder_MODEL, Path.GetFileName(Server_Folder_MODEL)); //判斷是否存在,不存在則開始複製 //if (!File.Exists(Local_CusPartFullPath)) //{ // try // { // File.Copy(Server_Folder_MODEL, Local_CusPartFullPath, true); // } // catch (System.Exception ex) // { // CaxLog.ShowListingWindow("客戶檔案複製失敗"); // this.Close(); // } //} #endregion #region (註解)複製IPQC.xls到Local_Folder_MODEL資料夾內 ////判斷IPQC.xls是否存在 //if (!File.Exists(Server_IPQC)) //{ // listView.Items.Add("IPQC樣板(IPQC.xls)不存在,無法下載"); // return; //} ////建立Local_Folder_MODEL資料夾內客戶檔案路徑 //string Local_IPQCFullPath = string.Format(@"{0}\{1}", Local_Folder_MODEL, Path.GetFileName(Server_IPQC)); ////判斷是否存在,不存在則開始複製 //if (!File.Exists(Local_IPQCFullPath)) //{ // try // { // File.Copy(Server_IPQC, Local_IPQCFullPath, true); // } // catch (System.Exception ex) // { // CaxLog.ShowListingWindow("IPQC.xls下載失敗"); // this.Close(); // } //} #endregion #region (註解)複製SelfCheck.xls到Local_Folder_MODEL資料夾內 ////判斷SelfCheck.xls是否存在 //if (!File.Exists(Server_SelfCheck)) //{ // listView.Items.Add("SelfCheck樣板(SelfCheck.xls)不存在,無法下載"); // return; //} ////建立Local_Folder_MODEL資料夾內客戶檔案路徑 //string Local_SelfCheckFullPath = string.Format(@"{0}\{1}", Local_Folder_MODEL, Path.GetFileName(Server_SelfCheck)); ////判斷是否存在,不存在則開始複製 //if (!File.Exists(Local_SelfCheckFullPath)) //{ // try // { // File.Copy(Server_SelfCheck, Local_SelfCheckFullPath, true); // } // catch (System.Exception ex) // { // CaxLog.ShowListingWindow("SelfCheck.xls下載失敗"); // this.Close(); // } //} #endregion #region (註解)複製IQC.xls到Local_Folder_MODEL資料夾內 ////判斷IPQC.xls是否存在 //if (!File.Exists(Server_IQC)) //{ // listView.Items.Add("IQC樣板(IQC.xls)不存在,無法下載"); // return; //} ////建立Local_Folder_MODEL資料夾內客戶檔案路徑 //string Local_IQCFullPath = string.Format(@"{0}\{1}", Local_Folder_MODEL, Path.GetFileName(Server_IQC)); ////判斷是否存在,不存在則開始複製 //if (!File.Exists(Local_IQCFullPath)) //{ // try // { // File.Copy(Server_IQC, Local_IQCFullPath, true); // } // catch (System.Exception ex) // { // CaxLog.ShowListingWindow("IQC.xls複製失敗"); // this.Close(); // } //} #endregion #region (註解)複製FAI.xls到Local_Folder_MODEL資料夾內 ////判斷IPQC.xls是否存在 //if (!File.Exists(Server_FAI)) //{ // listView.Items.Add("FAI樣板(FAI.xls)不存在,無法下載"); // return; //} ////建立Local_Folder_MODEL資料夾內客戶檔案路徑 //string Local_FAIFullPath = string.Format(@"{0}\{1}", Local_Folder_MODEL, Path.GetFileName(Server_FAI)); ////判斷是否存在,不存在則開始複製 //if (!File.Exists(Local_FAIFullPath)) //{ // try // { // File.Copy(Server_FAI, Local_FAIFullPath, true); // } // catch (System.Exception ex) // { // CaxLog.ShowListingWindow("FAI.xls複製失敗"); // this.Close(); // } //} #endregion #region 先刪除本機中該製程的OPxxx->OIS資料夾 //刪除本機OPxxx資料夾路徑 foreach (string i in Oper1comboBox.Items) { if (Oper1comboBox.Text == "全部下載") { if (i == "全部下載") { continue; } } else { if (i != Oper1comboBox.Text) { continue; } } Local_Folder_OIS = sDownUpLoadDat.Local_Folder_OIS; Local_Folder_OIS = Local_Folder_OIS.Replace("[Oper1]", i); if (Directory.Exists(Local_Folder_OIS)) { Directory.Delete(Local_Folder_OIS, true); } } //for (int i = 0; i < Oper1comboBox.Items.Count; i++) //{ // if (Oper1comboBox.Text != Oper1comboBox.Items[i].ToString() & Oper1comboBox.Text != "全部下載") // { // continue; // } // string Local_OPxxxPath = string.Format(@"{0}\{1}\{2}", sDownUpLoadDat.Local_ShareStr, "OP" + Oper1comboBox.Items[i].ToString(), "OIS"); // if (Directory.Exists(Local_OPxxxPath)) // { // Directory.Delete(Local_OPxxxPath, true); // } // string Local_MEpartPath = string.Format(@"{0}\{1}", sDownUpLoadDat.Local_ShareStr, PartNocomboBox.Text + "_ME_" + Oper1comboBox.Items[i].ToString() + ".prt"); // if (File.Exists(Local_MEpartPath)) // { // File.Delete(Local_MEpartPath); // } //} #endregion #region 建立Local_Folder_CAM、Local_Folder_OIS資料夾 foreach (string i in Oper1comboBox.Items) { if (Oper1comboBox.Text == "全部下載") { if (i == "全部下載") { continue; } } else { if (i != Oper1comboBox.Text) { continue; } } Local_Folder_CAM = sDownUpLoadDat.Local_Folder_CAM; Local_Folder_OIS = sDownUpLoadDat.Local_Folder_OIS; Local_Folder_CAM = Local_Folder_CAM.Replace("[Oper1]", i); Local_Folder_OIS = Local_Folder_OIS.Replace("[Oper1]", i); if (!File.Exists(Local_Folder_CAM)) { System.IO.Directory.CreateDirectory(Local_Folder_CAM); } if (!File.Exists(Local_Folder_OIS)) { System.IO.Directory.CreateDirectory(Local_Folder_OIS); } } //暫存一個tempLocal_Folder_CAM、Local_Folder_OIS,目的要讓程式每次都能有[Oper1]可取代 /* * tempLocal_Folder_CAM = Local_Folder_CAM; * tempLocal_Folder_OIS = Local_Folder_OIS; * * if (CurrentOper1 == "全部下載") * { * for (int i = 0; i < Oper1comboBox.Items.Count; i++) * { * if (Oper1comboBox.Items[i].ToString() == "全部下載") * { * continue; * } * Local_Folder_CAM = tempLocal_Folder_CAM; * Local_Folder_OIS = tempLocal_Folder_OIS; * Local_Folder_CAM = Local_Folder_CAM.Replace("[Oper1]", Oper1comboBox.Items[i].ToString()); * Local_Folder_OIS = Local_Folder_OIS.Replace("[Oper1]", Oper1comboBox.Items[i].ToString()); * if (!File.Exists(Local_Folder_CAM)) * { * try * { * System.IO.Directory.CreateDirectory(Local_Folder_CAM); * } * catch (System.Exception ex) * { * MessageBox.Show(ex.ToString()); * return; * } * } * if (!File.Exists(Local_Folder_OIS)) * { * try * { * System.IO.Directory.CreateDirectory(Local_Folder_OIS); * } * catch (System.Exception ex) * { * MessageBox.Show(ex.ToString()); * return; * } * } * } * } * else * { * Local_Folder_CAM = tempLocal_Folder_CAM; * Local_Folder_OIS = tempLocal_Folder_OIS; * Local_Folder_CAM = Local_Folder_CAM.Replace("[Oper1]", CurrentOper1); * Local_Folder_OIS = Local_Folder_OIS.Replace("[Oper1]", CurrentOper1); * if (!File.Exists(Local_Folder_CAM)) * { * try * { * System.IO.Directory.CreateDirectory(Local_Folder_CAM); * } * catch (System.Exception ex) * { * MessageBox.Show(ex.ToString()); * return; * } * } * if (!File.Exists(Local_Folder_OIS)) * { * try * { * System.IO.Directory.CreateDirectory(Local_Folder_OIS); * } * catch (System.Exception ex) * { * MessageBox.Show(ex.ToString()); * return; * } * } * } */ /* * //DicSeleOper1(Key = 製程序,Value = ServerPartPath) * foreach (KeyValuePair<string,string> kvp in DicSeleOper1) * { * Local_Folder_CAM = tempLocal_Folder_CAM; * Local_Folder_OIS = tempLocal_Folder_OIS; * Local_Folder_CAM = Local_Folder_CAM.Replace("[Oper1]", kvp.Key); * Local_Folder_OIS = Local_Folder_OIS.Replace("[Oper1]", kvp.Key); * if (!File.Exists(Local_Folder_CAM)) * { * try * { * System.IO.Directory.CreateDirectory(Local_Folder_CAM); * } * catch (System.Exception ex) * { * MessageBox.Show(ex.ToString()); * return; * } * } * if (!File.Exists(Local_Folder_OIS)) * { * try * { * System.IO.Directory.CreateDirectory(Local_Folder_OIS); * } * catch (System.Exception ex) * { * MessageBox.Show(ex.ToString()); * return; * } * } * } */ #endregion #region 複製Server製程序檔案到Local資料夾內 foreach (string i in ListDownloadPartPath) { //刪除本機檔案,_ME_的檔案已經在前面有刪除了,可能要修改一下統一在這邊刪除 string Local_Part = string.Format(@"{0}\{1}", sDownUpLoadDat.Local_ShareStr, Path.GetFileName(i)); if (File.Exists(Local_Part)) { File.Delete(Local_Part); } //判斷Part檔案是否存在 if (!File.Exists(i)) { CaxLog.ShowListingWindow("製程序檔案" + Path.GetFileName(i) + "不存在,無法下載"); continue; } //建立Local_ShareStr資料夾內製程序檔案路徑 string Local_Oper1PartFullPath = string.Format(@"{0}\{1}", sDownUpLoadDat.Local_ShareStr, Path.GetFileName(i)); //開始複製 try { File.Copy(i, Local_Oper1PartFullPath, true); } catch (System.Exception ex) { CaxLog.ShowListingWindow("製程序檔案" + Path.GetFileName(i) + "下載失敗"); continue; } } /* * foreach (string i in ListDownloadPartPath) * { * //刪除本機OISpart * string Local_OISpart = string.Format(@"{0}\{1}", Local_ShareStr, Path.GetFileName(i)); * if (File.Exists(Local_OISpart)) * { * File.Delete(Local_OISpart); * } * * //判斷Part檔案是否存在 * if (!File.Exists(i)) * { * CaxLog.ShowListingWindow("製程序檔案" + Path.GetFileName(i) + "不存在,請再次確認"); * //MessageBox.Show("製程序檔案" + Path.GetFileName(i) + "不存在,請再次確認"); * this.Close(); * } * //建立Local_ShareStr資料夾內製程序檔案路徑 * string Local_Oper1PartFullPath = string.Format(@"{0}\{1}", Local_ShareStr, Path.GetFileName(i)); * //開始複製 * try * { * File.Copy(i, Local_Oper1PartFullPath, true); * } * catch (System.Exception ex) * { * CaxLog.ShowListingWindow(Path.GetFileName(i) + "下載失敗"); * this.Close(); * } * } */ #endregion MessageBox.Show("下載完成!"); this.Close(); }