CATIA CAA 二次开发 详细教程
CATIA CAA 二次开发 详细教程(5)添加一个点
在创建任何几何对象之前,必须在激活的函数命令中添加以下代码,: CATFrmEditor* pEditor = CATFrmEditor::GetCurrentEditor(); if(pEditor == NULL) {
printf(\ }
CATDocument *pDoc = pEditor->GetDocument(); CATIContainerOfDocument_var spConODocs = pDoc; CATIContainer* pSpecContainer = NULL;
HRESULT hr = spConODocs->GetSpecContainer(pSpecContainer); if(spConODocs == NULL_var) {
printf(\ }
以上代码的主要功能是获取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[3]; Coords[0] = 0; Coords[1] = 0; Coords[2] = 0;
(2)创建一个CATIGSMPoint并将其转换为CATISpecObject
CATIGSMPoint_var spPoint1 = spGSMFactory->CreatePoint(Coords); //Creates a point
30
CATIA CAA 二次开发 详细教程
CATISpecObject_var spSpecPoint1 = spPoint1; //Casts the point as a CATISpecObject
(3)为了在CATIA显示你创建的点,必须将其添加到视图中。 spSpecPoint1->Update();
CATIGSMProceduralView_var spPntObj = spSpecPoint1; spPntObj->InsertInProceduralView(); 所有的源代码如下: // www.mememama.cn
// ----------------------------------------------------
CATStatusChangeRC MyCommand::Activate( CATCommand * iFromClient, CATNotification * iEvtDat)
{
CATFrmEditor* pEditor = CATFrmEditor::GetCurrentEditor();
if(pEditor == NULL) {
printf(\r\
}
CATDocument *pDoc = pEditor->GetDocument(); CATIContainerOfDocument_var spConODocs = pDoc; CATIContainer* pSpecContainer = NULL;
HRESULT hr = spConODocs->GetSpecContainer(pSpecContainer);
if(spConODocs == NULL_var) {
printf(\ of documents\
}
CATIGSMFactory_var spGSMFactory = NULL_var; CATIPrtFactory_var spPrtFactory = NULL_var; CATICkeParmFactory_var spParmFactory = NULL_var; spGSMFactory = pSpecContainer; spPrtFactory = pSpecContainer; spParmFactory = pSpecContainer;
31
CATIA CAA 二次开发 详细教程
double Coords[3]; Coords[0] = 0; Coords[1] = 0; Coords[2] = 0;
CATIGSMPoint_var spPoint1 = spGSMFactory->CreatePoint(Coords); //Creates a point
CATISpecObject_var spSpecPoint1 = spPoint1; //Casts the point as a CATISpecObject
spSpecPoint1->Update();
CATIGSMProceduralView_var spPntObj = spSpecPoint1;
spPntObj->InsertInProceduralView();
return (CATStatusChangeRCCompleted); }
CATIA CAA 二次开发 详细教程(6)创建一条线
初始的设定请参考上一讲《CATIA CAA 二次开发 详细教程(5)添加一个点》。在此基础上,创建线的步骤如下:
1)创建两个点并将其转换为CATISpecObjects。 double Coords[3]; Coords[0] = 0; Coords[1] = 0; Coords[2] = 0;
CATIGSMPoint_var spPoint1 = spGSMFactory->CreatePoint(Coords); CATISpecObject_var spSpecPoint1 =
spPoint1;
Coords[0] = 8; Coords[1] = 6; Coords[2] = 7;
CATIGSMPoint_var spPoint2 = spGSMFactory->CreatePoint(Coords); CATISpecObject_var spSpecPoint2 = spPoint2;
32