Catia 二次开发源码分享: 获取所有的平面并着色
个人认为,比较常见吧,如何遍历得到几何体,通过几何体获取到拓扑体,通过体获取到几何元素,通过几何元素获取到单元,单元再到几何进行判断面的种类,对于BrepAccess的获取需要借用 全局函数 CATBrepAccess !
//get the main body
---- -----
{
CATIPartRequest_var spPrtRequest = spPrtPart;
if (NULL_var == spPrtRequest)
{
printMessage("NULL_var == spPrtRequest");
return;
}
CATBaseUnknown_var spMainBody;
rc = spPrtRequest->GetMainBody("",spMainBody);
if (FAILED(rc))
{
printMessage("Failed spPrtRequest");
return;
}
CATIAlias_var spAliasBody = spMainBody;
printMessage("Main Body" + spAliasBody->GetAlias());
CATIBodyRequest_var spBodyRequest = spMainBody;
if (NULL_var == spBodyRequest)
{
printMessage("NULL_var == spBodyRequest");
return;
}
CATLISTV(CATBaseUnknown_var) ListResult;
rc = spBodyRequest->GetResults("",ListResult);
if (FAILED(rc)|| 0 == ListResult.Size())
{
printMessage("ListResult failed spBodyRequest");
return;
}
CATIGeometricalElement_var spFeatureResultGeomElement = ListResult;
if (NULL_var == spFeatureResultGeomElement)
{
printMessage("NULL_var == spFeatureResultGeomElement");
return;
}
CATBody_var spTopoBody = spFeatureResultGeomElement->GetBodyResult();
if (NULL_var == spTopoBody)
{
printMessage("NULL_var == spTopoBody");
return;
}
CATLISTP(CATCell) cells;
spTopoBody->GetAllCells(cells,2); //get all the faces
char msg;
sprintf_s(msg,sizeof(msg),"Face Number :%d",cells.Size());
printMessage(msg);
for (int i = 1; i <= cells.Size();i++)
{
CATCell_var pCell = cells;
if (NULL_var!=pCell)
{
CATGeometry *pGeometry = pCell->GetGeometry();
if (NULL!=pGeometry && pGeometry->IsATypeOf(CATPlaneType)) //plane face
{
//CATMathPoint CenterPoint;
//pGeometry->GetBoundingBox().GetBoxCenter(CenterPoint);
//sprintf_s(msg,sizeof(msg),"Face center :%f,%f,%f",CenterPoint.GetX(),CenterPoint.GetY(),CenterPoint.GetZ());
//printMessage(msg);
CATIBRepAccess_var spBrepAccess = CATBRepDecode(pCell, spFeatureResultGeomElement);
if (spBrepAccess != NULL_var)
{
//assign color
CATIVisProperties * pVisProperties = NULL;
rc = spBrepAccess->QueryInterface(IID_CATIVisProperties,(void **) &pVisProperties);
if (SUCCEEDED(rc))
{
CATVisPropertiesValues ivalues;
ivalues.SetColor(0,0,255);
pVisProperties->SetPropertiesAtt(ivalues,CATVPColor,CATVPMesh );
}
pVisProperties->Release();
pVisProperties = NULL;
}
}
//get alias name and persistentTag to add in the list
}
}
// End of User Code
}
页:
[1]