CATIA CAA 二次开发 详细教程(5)添加一个点
在创建任何几何对象之前,必须在激活的函数命令中添加以下代码,:
CATFrmEditor* pEditor = CATFrmEditor::GetCurrentEditor();
if(pEditor == NULL)
{
printf("error getting the FRM editor");
}
CATDocument *pDoc = pEditor->GetDocument();
CATIContainerOfDocument_var spConODocs = pDoc;
CATIContainer* pSpecContainer = NULL;
HRESULT hr = spConODocs->GetSpecContainer(pSpecContainer);
if(spConODocs == NULL_var)
{
printf("error getting the container 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[3];
Coords[0] = 0;
Coords[1] = 0;
Coords[2] = 0;
(2)创建一个CATIGSMPoint并将其转换为CATISpecObject
CATIGSMPoint_var spPoint1 = spGSMFactory->CreatePoint(Coords); //Creates a point
CATISpecObject_var spSpecPoint1 = spPoint1; //Casts the point as a CATISpecObject
merge函数(3)为了在CATIA显示你创建的点,必须将其添加到视图中。
spSpecPoint1->Update();
CATIGSMProceduralView_var spPntObj = spSpecPoint1;
spPntObj->InsertInProceduralView();
所有的源代码如下:
// &ama
// ----------------------------------------------------
CATStatusChangeRC MyCommand::Activate( CATCommand * iFromClient, CATNotification * iEvtDat)
{
CATFrmEditor* pEditor = CATFrmEditor::GetCurrentEditor();
if(pEditor == NULL)
{
printf("error getting the FRM editor");
}
CATDocument *pDoc = pEditor->GetDocument();
CATIContainerOfDocument_var spConODocs = pDoc;
CATIContainer* pSpecContainer = NULL;
HRESULT hr = spConODocs->GetSpecContainer(pSpecContainer);
if(spConODocs == NULL_var)
{
printf("error getting the container of documents");
}
CATIGSMFactory_var spGSMFactory = NULL_var;
CATIPrtFactory_var spPrtFactory = NULL_var;
CATICkeParmFactory_var spParmFactory = NULL_var;
spGSMFactory = pSpecContainer;
spPrtFactory = pSpecContainer;
spParmFactory = pSpecContainer;
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;
2) 利用创建的点创建一条线,并将其转换为CATISpecObject
CATISpecObject_var spSupport = NULL_var;
CATIGSMLinePtPt_var spLine1 = spGSMFactory->CreateLine(spSpecPoint1, spSpecPoint
2, spSupport);
CATISpecObject_var spSpecLine1 = spLine1;
3) 更新创建的线,并将其添加到视图中。
spSpecLine1->Update();
CATIGSMProceduralView_var spCurObj = spLine1;
spCurObj->InsertInProceduralView();
CATIA CAA 二次开发 详细教程(7)创建草图Sketch
有两种方式可以创建草图:
1)通过参考平面创建
首先获取一个CATIPrtPart变量:
CATIPrtPart_var spPart(pIPrtContOnDocument->GetPart());
pIPrtContOnDocument->Release();
有了CATIPrtPart变量就可以利用其方法GetReferencePlanes(),获取参考平面
CATLISTV(CATISpecObject_var) spRefPlanes = spPart->GetReferencePlanes();
然后创建XY plane (spRefPlanes[1])
CATISketchFactory_var spSketchFactory(pSpecContainer);
if ( NULL_var == spSketchFactory ) return (CATStatusChangeRCCompleted);
CATISketch_var spSketch(spSketchFactory->CreateSketch(spRefPlanes[1]));
if ( NULL_var == spSketch ) return (CATStatusChangeRCCompleted);
spSketch->OpenEdition();
2) 通过原点和两个矢量方向
该方法是通过定义一个原点和两个方向pH、pV 进行创建。
定义原点和方向:
double origin[3]={0.0,0.0,10.0};
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系QQ:729038198,我们将在24小时内删除。
发表评论