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; 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; }
private void ReadCoord_Click(object sender, EventArgs e) { if (datatable.Columns.Count < 1) { InitDataTable(); } this.WindowState = FormWindowState.Minimized; RepeatNum = 0; Array.Clear(GetRepeatRef, 0, GetRepeatRef.Length); ReadType = 2; Selection SelectArc = GetSelect(); if (SelectArc == null || SelectArc.Count2 == 0) { this.WindowState = FormWindowState.Normal; this.StartPosition = FormStartPosition.CenterScreen; this.TopMost = true; return; } int ERR = 0; for (int i = 1; i <= SelectArc.Count2; i++) { object[] PointCoord = new object[] { -99, -99, -99, -99, -99, -99 }; HybridShapeFactory PartHyb = (HybridShapeFactory)PartID.HybridShapeFactory; SPAWorkbench TheSPAWorkbench = (SPAWorkbench)CatDocument.GetWorkbench("SPAWorkbench"); Reference referenceObject; try { //Temp = PartID.CreateReferenceFromGeometry((AnyObject)SelectArc.Item(i).Value); referenceObject = SelectArc.Item(i).Reference;//!=null? SelectArc.Item(i).Reference: Temp; } catch (Exception) { Boolean LeafProductProcessed; 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; } } } Measurable TheMeasurable = TheSPAWorkbench.GetMeasurable(referenceObject); var TName = referenceObject.get_Name(); //读取选择的曲面名称 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 } SetDataGrid(); if (ERR > 0) { MessageBox.Show("共计:" + ERR + "个点创建新参考点失败!"); } if (RepeatCheck.Checked) { CheckRepeat(SelectArc); } }