admin 发表于 2017-12-22 13:51:55

CATIA二次开发入门教程---21 创建草图几何图形

CATIA二次开发入门教程---21 创建草图几何图形



////////获得Editor、Document、Container、设置GSMFactory
        CATFrmEditor* pEditor = CATFrmEditor::GetCurrentEditor();
        CATDocument *pDoc = pEditor->GetDocument();
        CATIContainerOfDocument_var spConODocs = pDoc;

        CATIContainer*            pContainer;                //Container
        CATIPrtContainer*   pPrtContainer;//PartContainer
        CATIGSMFactory_var      spGSMFactory;                //GSM工厂

        CATIPrtPart_var      spPrt   ;//
        HRESULT hr = spConODocs->GetSpecContainer(pContainer);//获取Container

        hr =pContainer->QueryInterface(IID_CATIPrtContainer,(void **)&pPrtContainer);//获取PrtContainer
        spPrt = pPrtContainer->GetPart();
        CATListValCATISpecObject_var spListRefPlanes = spPrt->GetReferencePlanes();//获取3个参考平面

        CATISpecObject_var spSketchPlane = spListRefPlanes;//第三个平面
        CATISketchFactory_var spSketchFactOnPrtCont(pPrtContainer);//草图工厂
        CATISketch_var spSketch = spSketchFactOnPrtCont->CreateSketch( spSketchPlane );        //创建草图
        CATI2DWFFactory_var spWF2DFactOnSketch(spSketch);

        spSketch->OpenEdition();        //进入草图开始绘图

        double p1   = {0,0};
   double p2   = {100,0};
   double p3   = {100,100};
   double p4   = {0,100};

   CATI2DPoint_var spP1,spP2,spP3,spP4;

spP1 = spWF2DFactOnSketch->CreatePoint(p1);
spP2 = spWF2DFactOnSketch->CreatePoint(p2);
spP3 = spWF2DFactOnSketch->CreatePoint(p3);
spP4 = spWF2DFactOnSketch->CreatePoint(p4);

CATI2DLine_var spLine1 = spWF2DFactOnSketch->CreateLine(p1,p2);
CATI2DLine_var spLine2 = spWF2DFactOnSketch->CreateLine(p2,p3);
CATI2DLine_var spLine3= spWF2DFactOnSketch->CreateLine(p3,p4);
CATI2DLine_var spLine4 = spWF2DFactOnSketch->CreateLine(p4,p1);

CATI2DCurve_var spCurve1,spCurve2,spCurve3,spCurve4;
spCurve1 = spLine1;
spCurve2 = spLine2;
spCurve3 = spLine3;
spCurve4 = spLine4;

spCurve1->SetStartPoint(spP1);
spCurve1->SetEndPoint(spP2);
spCurve2->SetStartPoint(spP2);
spCurve2->SetEndPoint(spP3);
spCurve3->SetStartPoint(spP3);
spCurve3->SetEndPoint(spP4);
spCurve4->SetStartPoint(spP4);
spCurve4->SetEndPoint(spP1);


spSketch->CloseEdition(); //退出草图


CATISpecObject_var spObject = spSketch;
spObject->Update();

admin 发表于 2017-12-22 13:52:59

在上一节的基础上,开始创建草图。首先创建草图工厂:
CATI2DWFFactory_var sketch2DFactory(spSketch);
下面创建点:
CATI2DPoint_var spPt_bottom_left, spPt_bottom_right, spPt_top_right, spPt_top_left;
double pt_bottom_left= {10., 10.};
double pt_bottom_right = {50., 10.};
double pt_top_right    = {50., 50.};
double pt_top_left   = {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);
开始创建线:
CATI2DLine_var spLine1, spLine2, spLine3, spLine4;
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);
将线连接起来:
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);
然后退出草图:
spSketch->CloseEdition();


visionace 发表于 2024-3-12 20:17:25

非常棒,有没有接口之间的关系导图呀
页: [1]
查看完整版本: CATIA二次开发入门教程---21 创建草图几何图形