admin 发表于 2018-2-22 13:28:03

Catia二次开发源码分享:创建圆柱体实例

获得零件指针
// 获得文件指针
CATDocument * pDoc= NULL;
CATFrmEditor * _pEditor = CATFrmEditor::GetCurrentEditor();
pDoc = _pEditor->GetDocument();//这里得到了PART 环境下的文档指针
CATInit_var spInitOnDoc(pDoc);
// 得到零件根容器

CATIPrtContainer * piPrtCont =
(CATIPrtContainer*) spInitOnDoc->GetRootContainer("CATIPrtContainer");
// 得到零件指针
CATIPrtPart_var spPart = piPrtCont->GetPart();

创建草图
//初始化草图工厂
CATISketchFactory_var spSketchFactory(piPrtCont);
//在XY plane 上创建草图
CATISketch_var spSketch = spSketchFactory->CreateSketch(spRefPlanes));

创建草图几何
//首先声明编辑草图
spSketch->OpenEdition();
CATI2DWFFactory_var sp2DFactory(spSketch);
//这里表示圆心点
double iPoint = {0.,0.};
//下面创建圆圈
CATISpecObject_var spLine = spSketch ->CreateCircle(iPoint,_Editor003->GetFloatValue());
CATI2DCurve_var spCurveOnLine(spLine);
spCurveOnLine->GetStartPoint();
spCurveOnLine->GetEndPoint();
//然后退出草图:
spSketch->CloseEdition();


创建约束
CATI2DConstraintFactory_var spConstraint2DFactory(spSketch);
//定义spLine1 的半径约束
spConstraint2DFactory->CreateConstraint(spLine, NULL, NULL, NULL, NULL, NULL,
NULL, Cst2DType_Radius, 0, 0 );
//定义spLine1 与坐标原点的同心约束
CATI2DAxis_var spSupport = NULL_var;
spSketch->GetAbsolute2DAxis(spSupport);

spConstraint2DFactory->CreateConstraint(spLine, NULL, spSupport->GetOriginPoint(),
NULL, NULL, NULL, NULL, Cst2DType_Concentric, 0, 0 );


创建凸台
// 从编辑框中获得援助的高度
double firstLimit = _Editor004->GetFloatValue();
double secondLimit = 0.;
//圆柱的轴向方向为Z 轴方向
CATMathDirection dirZ(0., 0., 1.);
//初始化零件工厂
CATIPrtFactory_var spPrtFactOnPrtCont(piPrtCont);
//创建凸台
CATISpecObject_var spSpecObj = spPrtFactOnPrtCont->CreatePad(spSketch);
CATIPad_var spPadOnSpecObj(spSpecObj);
//设置拉伸方向
spPadOnSpecObj->ModifyDirection(dirZ);
//设置凸台第一限制类型
spPadOnSpecObj->ModifyEndType(catOffsetLimit);
//设置凸台的高度
spPadOnSpecObj->ModifyEndOffset(firstLimit);
//设置凸台第二限制类型
spPadOnSpecObj->ModifyStartType(catOffsetLimit);
spPadOnSpecObj->ModifyStartOffset(secondLimit);
//将凸台添加在结构树中
spSpecObj->Update();
CATIGSMProceduralView_var ispProcView = spSpecObj;
if (NULL_var != ispProcView ) {HResult rc = ispProcView ->InsertInProceduralView();}

页: [1]
查看完整版本: Catia二次开发源码分享:创建圆柱体实例