CATIA使用CAA二次开发:创建草图

2014-07-18 19:06:53|?次阅读|上传:wustguangh【已有?条评论】发表评论

关键词:C/C++, CAA, CATIA|来源:唯设编程网

2.2 创建并打开草图编辑器

    CATLISTV(CATISpecObject_var) spRefPlanes = spPart->GetReferencePlanes();

  //------------------------------------------------------------------------------------------

  // SKETCH CREATION and EDIT:Instantiates the sketch with the plane XY (refPlanes[1])

  //------------------------------------------------------------------------------------------

  CATISketchFactory_var spSketchFactory(piContainer);

  if ( NULL_var == spSketchFactory ) return 6;

  CATISketch_var spSketch(spSketchFactory->CreateSketch(spRefPlanes[1]));

  if ( NULL_var == spSketch ) return 7;
    spSketch->OpenEdition(); 

     在得到零件的参考平面以后,我们在第一平面(xy 平面)创建一个草图,并使它准备进入编辑状态。使用草图工厂(sketch factory)创建草图(草图工厂由容器实现)。

2.3 获取几何元素工厂并且创建2D直线

 

     CATI2DWFFactory_var sketch2DFactory(spSketch); // Retrieves the 2D factory to create elements
     CATI2DPoint_var spPt_bottom_left, spPt_bottom_right, spPt_top_right, spPt_top_left;
     CATI2DLine_var spLine1, spLine2, spLine3, spLine4;
     double pt_bottom_left[2]  = {10., 10.};
     double pt_bottom_right[2] = {50., 10.};
     double pt_top_right[2]    = {50., 50.};
     double pt_top_left[2]     = {10., 50.};

     spPt_bottom_left = sketch2DFactory->CreatePoint(pt_bottom_left);
     spPt_bottom_right = sketch2DFactory->CreatePoint(pt_bottom_right);
     spPt_top_right = sketch2DFactory->CreatePoint(pt_top_right);
     spPt_top_left = sketch2DFactory->CreatePoint(pt_top_left);
     spLine1 = sketch2DFactory->CreateLine(pt_bottom_left,pt_bottom_right);
     spLine2 = sketch2DFactory->CreateLine(pt_bottom_right,pt_top_right);
     spLine3 = sketch2DFactory->CreateLine(pt_top_right,pt_top_left);
     spLine4 = sketch2DFactory->CreateLine(pt_top_left,pt_bottom_left);

     // connectivity
     CATI2DCurve_var spCurve1 (spLine1);
     CATI2DCurve_var spCurve2 (spLine2);
     CATI2DCurve_var spCurve3 (spLine3);
     CATI2DCurve_var spCurve4 (spLine4);
     spCurve1->SetStartPoint(spPt_bottom_left);
     spCurve1->SetEndPoint(spPt_bottom_right);
     spCurve2->SetStartPoint(spPt_bottom_right);
     spCurve2->SetEndPoint(spPt_top_right);
     spCurve3->SetStartPoint(spPt_top_right);
     spCurve3->SetEndPoint(spPt_top_left);
     spCurve4->SetStartPoint(spPt_top_left);
     spCurve4->SetEndPoint(spPt_bottom_left);

几何元素工厂有草图(sketch)直接实现。在得到2D工厂以后,我们创建4个点,然后是通过这些点的4条直线(这4条直线和交点一起组成一个矩形)我们在这些点上面创建联结。每一条曲线共享一个起点和终点。

发表评论0条 】
网友评论(共?条评论)..
CATIA使用CAA二次开发:创建草图