admin 发表于 2017-12-20 22:57:06

CATIA二次开发入门教程---18 创建一个点


CATIA二次开发入门教程---18 创建一个点




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

        CATIContainer*            _pContainer;                //Container
        CATIGSMFactory_var      spGSMFactory;                //GSM工厂

        _pContainer = NULL;
        HRESULT hr = spConODocs->GetSpecContainer(_pContainer);
        spGSMFactory = NULL_var;
        spGSMFactory = _pContainer;
        //设置点的坐标
        CATMathPoint _Point;
        _Point.SetCoord(10,10,10 );
        /////////////////////用以上得到的Point3D画点
        CATIGSMPoint_var spPoint1 = spGSMFactory->CreatePoint(_Point); //创建一个点
        CATISpecObject_var                spSpecPoint1;
        spSpecPoint1 = spPoint1;                                //Casts the point as a CATISpecObject
        CATIGSMProceduralView_var spSndPntObj = spSpecPoint1;
        spSndPntObj->InsertInProceduralView();
    spSpecPoint1->Update();
        // Add your code here

admin 发表于 2017-12-22 11:04:14

在创建任何几何对象之前,必须在激活的函数命令中添加以下代码,:CATFrmEditor* pEditor = CATFrmEditor::GetCurrentEditor();if(pEditor == NULL){   printf("error getting the FRMeditor");}CATDocument *pDoc = pEditor->GetDocument();CATIContainerOfDocument_var spConODocs = pDoc;CATIContainer* pSpecContainer = NULL;HRESULT hr =spConODocs->GetSpecContainer(pSpecContainer);if(spConODocs == NULL_var){   printf("error getting thecontainer of documents");}以上代码的主要功能是获取editor, the document and the container。CATIGSMFactory_var spGSMFactory = NULL_var;CATIPrtFactory_var spPrtFactory = NULL_var;CATICkeParmFactory_var spParmFactory = NULL_var;spGSMFactory = pSpecContainer;spPrtFactory = pSpecContainer;spParmFactory = pSpecContainer;以上代码设置工厂,在这基础上你才可以造型,GSMFactory用于创建底层的几何对象比如点、线等。PrtFactory包含创建孔特征、拉伸特征实体等函数。ParmFactory 包含设定参数的函数。在以上的基础上可以创建点了,步骤如下:(1)创建一个三维数组(x,y,z)定义点坐标。double Coords;Coords = 0;Coords = 0;Coords = 0;(2)创建一个CATIGSMPoint并将其转换为CATISpecObjectCATIGSMPoint_var spPoint1 = spGSMFactory->CreatePoint(Coords);//Creates a point
CATISpecObject_var spSpecPoint1 = spPoint1; //Casts thepoint as a CATISpecObject(3)为了在CATIA显示你创建的点,必须将其添加到视图中。spSpecPoint1->Update();CATIGSMProceduralView_var spPntObj = spSpecPoint1;
spPntObj->InsertInProceduralView();
页: [1]
查看完整版本: CATIA二次开发入门教程---18 创建一个点