private void textBox1_MouseClick(object sender, MouseEventArgs e) { // 카티아가 실행중? if (Catia == null) { //MessageBox.Show("Please run CATIA"); label3.Text = "Please run CATIA"; return; } // 활성 문서가 있는가? if (Catia.ActiveDocument == null) { //MessageBox.Show("활성 문서가 없습니다"); label3.Text = "활성 문서가 없습니다"; } // 선택 기능 실행 Sel = Catia.ActiveDocument.Selection; Object[] InputObjectType = { "HybridBody" }; string Status; Sel.Clear(); Status = Sel.SelectElement2(InputObjectType, "Select a Geometrical Set", false); if (Status != "Normal") { label3.Text = "취소"; return; } if (Sel.Count < 1) { label3.Text = "선택"; return; } SelGS = (HybridBody)Sel.Item(1).Value; textBox1.Text = SelGS.get_Name(); int ptCount = 0; for (int i = 1; i <= SelGS.HybridShapes.Count; i++) { ptCount++; Pts.Add(SelGS.HybridShapes.Item(i)); } label4.Text = ptCount + ""; }
//1.Gs 선택----------------------------------------------------------- private void button2_Click(object sender, EventArgs e) { // 카티아가 실행중? if (catia == null) { MessageBox.Show("Please run the CATIA"); return; } // 활성 문서가 있는가? if (catia.ActiveDocument == null) { MessageBox.Show("document를 열어주세요."); return; } try { // 선택 기능 실행 sel = catia.ActiveDocument.Selection; //Gs만 선택해주라~~ Object[] intype = { "HybridBody" }; //sel.Clear(); string status = sel.SelectElement2(intype, "Select a Geometrical set", true); /*The state of the selection command once SelectElement2 returns. * It can be either "Normal" (the selection has succeeded), * "Cancel" (the user wants to cancel the VB command, * which must exit immediately), "Undo" or "Redo". */ if (status != "Normal") { MessageBox.Show("Cancel"); return; } if (sel.Count < 1) { MessageBox.Show("GS를 선택해주세요"); return; } // GS이름 표시한다--- hbdy = (HybridBody)sel.Item(1).Value; textBox1.Text = hbdy.get_Name(); //point 수 표시한다--- int ptCount = 0; for (int i = 1; i <= hbdy.HybridShapes.Count; i++) //i=1부타 시작~~ { ptCount++; Pts.Add(hbdy.HybridShapes.Item(i)); } textBox2.Text = ptCount + ""; } catch (Exception) { MessageBox.Show("선택된 정보가 없습니다."); return; } }
private void ReadCoord_Click(object sender, EventArgs e) { progressBar.Value = 0; if (datatable.Columns.Count < 1) { InitDataTable(); } this.WindowState = FormWindowState.Minimized; RepeatNum = 0; Array.Clear(GetRepeatRef, 0, GetRepeatRef.Length); ReadType = 2; Selection SelectArc = null; CATIA_Class.GetSelect(CatDocument, ref SelectArc, this); if (SelectArc == null || SelectArc.Count2 == 0) { this.WindowState = FormWindowState.Normal; this.StartPosition = FormStartPosition.CenterScreen; this.TopMost = true; return; } int ERR = 0; progressBar.Maximum = SelectArc.Count2; progressBar.Step = 1; try { HybridShape product = (HybridShape)SelectArc.Item(1).Value; HybridBody hybridBody = (HybridBody)product.Parent; xlsFileName = hybridBody.get_Name(); } catch (Exception) { throw; } for (int i = 1; i < SelectArc.Count2 + 1; i++) { object[] PointCoord = new object[] { -99, -99, -99, -99, -99, -99 }; HybridShapeFactory PartHyb = (HybridShapeFactory)PartID.HybridShapeFactory; SPAWorkbench TheSPAWorkbench = null; TheSPAWorkbench = (SPAWorkbench)CatDocument.GetWorkbench("SPAWorkbench"); // Default Get Coordxyz From Word Reference referenceObject; String ObjType = SelectArc.Item(i).Type; Boolean LeafProductProcessed; string TName = string.Empty; switch (ObjType) { case "HybridShape": { referenceObject = SelectArc.Item(i).Reference; //!=null? SelectArc.Item(i).Reference: Temp; TName = referenceObject.get_Name(); //读取选择的曲面名称 break; } case "Shape": { string Name = string.Empty; Shape shape = (Shape)SelectArc.Item(i).Value; Product product = (Product)SelectArc.Item(i).LeafProduct; TName = product.get_PartNumber(); //读取选择的曲面名称 String RefStr = product.GetMasterShapeRepresentationPathName(); //获取零件路径地址 string[] RefStrArry = RefStr.Split('\\'); if (RefStrArry.Length > 1) { RefStr = RefStrArry.Last(); } Part RefPart = ((PartDocument)CatApplication.Documents.Item(RefStr)).Part; //通过总文档将当前零件转换成PartDocumet TName = RefPart.get_Name(); ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// if (getJTCoord.Checked) { try { //Product PCompoments = (Product)product.Parent; //TName = PCompoments.get_Name(); //referenceObject = PCompoments.CreateReferenceFromName(TName); //Measurable TheMeasurable1 = TheSPAWorkbench.GetMeasurable(referenceObject); } catch (Exception) { throw; } } //String RefStr1 = productPre.GetMasterShapeRepresentationPathName(); //获取零件路径地址 //string[] RefStrArry1 = RefStr1.Split('\\'); //if (RefStrArry.Length > 1) //{ // RefStr1 = RefStrArry1.Last(); //} //string tname= productPre.get_PartNumber(); //referenceObject= productPre.CreateReferenceFromName(TName); //Product RefProduct = ((ProductDocument)CatApplication.Documents.Item("70918")).Product;//通过总文档将当前零件转换成PartDocumet ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// try { //RefPart = (Part)RefPart.Parent; referenceObject = RefPart.CreateReferenceFromObject(shape); } catch (Exception) { MessageBox.Show("请确认当前是否打开了多个窗口,软件识别的零件和您选择的零件不在一个集合!"); return; } break; } default: { AnyObject Feature = (AnyObject)SelectArc.Item(i).Value; try { String Name = string.Empty; Shape GE = (Shape)SelectArc.Item(i).Value; //Name = GE.get_Name(); //Pad Spad = (Pad)GE.GetItem("Face1"); //Name = Spad.get_Name(); referenceObject = PartID.CreateReferenceFromObject(Feature); PartHyb.AddNewPointCenter(referenceObject); } catch (Exception) { ERR += 1; var LeafProduct = SelectArc.Item(i).LeafProduct; LeafProductProcessed = true; if (LeafProduct.get_Name() == "InvalidLeafProduct") { LeafProductProcessed = false; } if (LeafProductProcessed) { String ShapeName = Feature.get_Name(); VisPropertySet VPS = SelectArc.VisProperties; VPS.SetVisibleColor(255, 0, 0, 0); continue; } else { String ShapeName = Feature.get_Name(); VisPropertySet VPS = SelectArc.VisProperties; VPS.SetVisibleColor(255, 0, 0, 0); continue; } } } break; } Measurable TheMeasurable = TheSPAWorkbench.GetMeasurable(referenceObject); try { TheMeasurable.GetPoint(PointCoord); //读取选择的曲面坐标 } catch (Exception) { try { TheMeasurable.GetCOG(PointCoord); } catch (Exception) { ERR += 1; } } if (!KeepName.Checked) { TName = "Rx_" + (datatable.Rows.Count + 1); } WriteObjectToDataGrid(TName, PointCoord, referenceObject, IgRepeat.Checked); //记录数据到DataGridView try { this.Update(); //Updata Draw } catch (Exception) { } progressBar.PerformStep(); } SetDataGrid(); if (ERR > 0) { MessageBox.Show("共计:" + ERR + "个点创建新参考点失败!"); } if (RepeatCheck.Checked) { CheckRepeat(SelectArc); } DataGrid.AllowUserToAddRows = false; }