//create3Dline-------------------------------------------- private void button5_Click(object sender, EventArgs e) { // object[] HpCrd1 = new object[3]; // object[] HpCrd2 = new object[3]; try { sel = catia.ActiveDocument.Selection; HyShpPtCoord1 = (HybridShapeTypeLib.Point)sel.FindObject("CATIAHybridShapePoint"); //sel = catia.ActiveDocument.Selection; HyShpPtCoord2 = (HybridShapeTypeLib.Point)sel.FindObject("CATIAHybridShapePoint"); //HyShpPtCoord1.GetCoordinates(HpCrd1); //HyShpPtCoord1.GetCoordinates(HpCrd2); PartDocument prtDoc = (PartDocument)catia.ActiveDocument; Part prt = prtDoc.Part; HybridBody hbdy = prt.HybridBodies.Item(1); HybridShapeFactory hfac = (HybridShapeFactory)prt.HybridShapeFactory; INFITF.Reference ref1 = prt.CreateReferenceFromGeometry(HyShpPtCoord1); INFITF.Reference ref2 = prt.CreateReferenceFromGeometry(HyShpPtCoord2); HybridShapeTypeLib.Line lin = hfac.AddNewLinePtPt(ref1, ref2); hbdy.AppendHybridShape(lin); prt.Update(); } catch (Exception) { MessageBox.Show("선택된 정보가 없습니다."); return; } }
// create lines private void button1_Click(object sender, EventArgs e) { try { prtDoc = (PartDocument)catia.ActiveDocument; Part prt = prtDoc.Part; hbdy = prt.HybridBodies.Item(1); HybridShapeFactory hfac = (HybridShapeFactory)prt.HybridShapeFactory; //SelGS = (HybridBody)Sel.Item(1).Value; //INFITF.AnyObject aaa = Pts[0]; for (int i = 0; i <= (Pts.Count - 1); i++) { for (int j = i + 1; j < Pts.Count; j++) { HybridShapeTypeLib.Point pt1 = (HybridShapeTypeLib.Point)Pts.ElementAt(i); HybridShapeTypeLib.Point pt2 = (HybridShapeTypeLib.Point)Pts.ElementAt(j); INFITF.Reference ref1 = prt.CreateReferenceFromGeometry(pt1); INFITF.Reference ref2 = prt.CreateReferenceFromGeometry(pt2); HybridShapeTypeLib.Line lin = hfac.AddNewLinePtPt(ref1, ref2); hbdy.AppendHybridShape(lin); } } prt.Update(); } catch (Exception) { MessageBox.Show("선택된 정보가 없습니다."); return; } }
//create a line private void button3_Click(object sender, EventArgs e) { try { prtDoc = (PartDocument)catia.ActiveDocument; HybridBody hbdy = (HybridBody)ptStrt.Parent; HybridShapeFactory hfac = (HybridShapeFactory)prtDoc.Part.HybridShapeFactory; Line lin = hfac.AddNewLinePtPt(ptStrt, ptEnd); hbdy.AppendHybridShape(lin); prtDoc.Part.Update(); } catch (Exception) { MessageBox.Show("error"); return; } }
internal void PrintTriangles(Vector <double> x, List <int[]> triangles, MathNet.Spatial.Euclidean.Point3D oRoot, MathNet.Spatial.Euclidean.UnitVector3D vDir1, MathNet.Spatial.Euclidean.UnitVector3D vDir2, int iTrans, MathNet.Spatial.Euclidean.Point3D oTrans, bool just2D = false) { Part oPart = oPartDoc.Part; HybridShapeFactory hsf = (HybridShapeFactory)oPart.HybridShapeFactory; HybridBody hb1; try { hb1 = (HybridBody)oPart.HybridBodies.GetItem("Blank Calculator Result"); hb1.get_Name(); oSel.Clear(); oSel.Add(hb1); oSel.Delete(); } catch (Exception) {} hb1 = (HybridBody)oPart.HybridBodies.Add(); hb1.set_Name("Blank Calculator Result"); //CATIA.RefreshDisplay = false; //CATIA.Interactive = false; List <Reference> RsltPoints = new List <Reference>(); MathNet.Spatial.Euclidean.CoordinateSystem Axis = new MathNet.Spatial.Euclidean.CoordinateSystem(oRoot, vDir1, vDir2, vDir1.CrossProduct(vDir2)); if (just2D) { for (int i = 0; i < x.Count / 2; i++) { MathNet.Spatial.Euclidean.Point3D PtMath = new MathNet.Spatial.Euclidean.Point3D(new double[] { x[i * 2], x[i * 2 + 1], 0 }); Point PTCat = hsf.AddNewPointCoord(PtMath.X, PtMath.Y, PtMath.Z); PTCat.Compute(); RsltPoints.Add(oPart.CreateReferenceFromObject(PTCat)); } } else { MathNet.Spatial.Euclidean.Point3D PtMath = new MathNet.Spatial.Euclidean.Point3D(new double[] { x[iTrans * 2], x[iTrans * 2 + 1], 0 }); PtMath = Axis.TransformToCoordSys(PtMath); double[] vecTranslation = new double[] { oTrans.X - PtMath.X, oTrans.Y - PtMath.Y, oTrans.Z - PtMath.Z }; for (int i = 0; i < x.Count / 2; i++) { PtMath = new MathNet.Spatial.Euclidean.Point3D(new double[] { x[i * 2], x[i * 2 + 1], 0 }); PtMath = Axis.TransformToCoordSys(PtMath); Point PTCat = hsf.AddNewPointCoord(PtMath.X + vecTranslation[0], PtMath.Y + vecTranslation[1], PtMath.Z + vecTranslation[2]); PTCat.Compute(); RsltPoints.Add(oPart.CreateReferenceFromObject(PTCat)); } } foreach (int[] item in triangles) { Line lUp = hsf.AddNewLinePtPt(RsltPoints[item[0]], RsltPoints[item[1]]); lUp.Compute(); hb1.AppendHybridShape(lUp); Line l0 = hsf.AddNewLinePtPt(RsltPoints[item[1]], RsltPoints[item[2]]); l0.Compute(); hb1.AppendHybridShape(l0); Line lDown = hsf.AddNewLinePtPt(RsltPoints[item[2]], RsltPoints[item[0]]); lDown.Compute(); hb1.AppendHybridShape(lDown); } //CATIA.RefreshDisplay = true; //CATIA.Interactive = true; }