// this is the function that I created to get the return as ProSelection plane_sel and Datum plane ID (note it doenst give feature ID it gives datum plane ID).
// this we can use it in the API where we want ProSelection as datum plane or int plane id.
// for theory read the API docs for datum plane, in short they are treated as PRO_SURFACE in the CREO.
// here's the function
ProError err = GetPlaneSelectionFromFeatureID(drw_solid_mdl, 1, &plane_sel, &plane_surface_id);
//------------------------------------------------------------------------------------------------------------
// START OF PLANE SURFACE ACTION FUNCTION
static ProError PlaneSurfaceAction(ProGeomitem* p_handle, ProError status, ProAppData app_data) {
//---------------------------------------------------------
// Skip inactive geometry
//---------------------------------------------------------
ProBoolean inactive;
status = ProGeomitemIsInactive(p_handle, &inactive);
if (status != PRO_TK_NO_ERROR)
return PRO_TK_NO_ERROR;
if (inactive == PRO_B_TRUE)
return PRO_TK_NO_ERROR;
//---------------------------------------------------------
// Output selection
//---------------------------------------------------------
ProSelection* out_sel = (ProSelection*)app_data;
//---------------------------------------------------------
// Create selection
//---------------------------------------------------------
status = ProSelectionAlloc(NULL, (ProModelitem*)p_handle, out_sel);
if (status == PRO_TK_NO_ERROR)
{
logger::log_info("Plane selection allocated.");
return PRO_TK_USER_ABORT;
}
return PRO_TK_NO_ERROR;
}
ProError GetPlaneSelectionFromFeatureID(ProSolid solid, int feature_id, ProSelection* out_selection, int* out_surface_id) {
//---------------------------------------------------------
// Init feature
//---------------------------------------------------------
ProFeature plane_feat;
ProError err = ProFeatureInit(solid, feature_id, &plane_feat);
error_utils::CheckError(err, "ProFeatureInit");
if (err != PRO_TK_NO_ERROR)
return err;
//---------------------------------------------------------
// Temp data structure
//---------------------------------------------------------
struct PlaneData
{
ProSelection* selection;
int* surface_id;
};
PlaneData data;
data.selection = out_selection;
data.surface_id = out_surface_id;
//---------------------------------------------------------
// Visitor
//---------------------------------------------------------
auto PlaneSurfaceAction = [](ProGeomitem* p_handle, ProError status, ProAppData app_data) -> ProError
{
//-----------------------------------------------------
// Access data
//-----------------------------------------------------
PlaneData* data = (PlaneData*)app_data;
//-----------------------------------------------------
// Skip inactive
//-----------------------------------------------------
ProBoolean inactive;
status = ProGeomitemIsInactive(p_handle, &inactive);
if (status != PRO_TK_NO_ERROR)
return PRO_TK_NO_ERROR;
if (inactive == PRO_B_TRUE)
return PRO_TK_NO_ERROR;
//-----------------------------------------------------
// Surface
//-----------------------------------------------------
ProSurface surface;
status = ProGeomitemToSurface(p_handle, &surface);
if (status != PRO_TK_NO_ERROR)
{
return PRO_TK_NO_ERROR;
}
//-----------------------------------------------------
// Get surface ID
//-----------------------------------------------------
status = ProSurfaceIdGet(surface, data->surface_id);
if (status == PRO_TK_NO_ERROR)
{
logger::log_info("Plane surface ID: " + std::to_string(*(data->surface_id)));
}
//-----------------------------------------------------
// Create selection
//-----------------------------------------------------
status = ProSelectionAlloc(NULL, (ProModelitem*)p_handle, data->selection);
if (status == PRO_TK_NO_ERROR)
{
logger::log_info("Plane selection allocated.");
return PRO_TK_USER_ABORT;
}
return PRO_TK_NO_ERROR;
};
//---------------------------------------------------------
// Visit geometry
//---------------------------------------------------------
err = ProFeatureGeomitemVisit(&plane_feat, PRO_SURFACE, PlaneSurfaceAction, NULL, &data);
if (err != PRO_TK_USER_ABORT &&
err != PRO_TK_NO_ERROR)
{
return err;
}
if (*out_selection == NULL)
{
return PRO_TK_E_NOT_FOUND;
}
logger::log_info("Plane selection + surface ID created.");
return PRO_TK_NO_ERROR;
}
// END OF PLANE SURFACE ACTION FUNCTION
//------------------------------------------------------------------------------------------------------------