Community Tip - Learn all about the Community Ranking System, a fun gamification element of the PTC Community. X
Hi All,
I'm trying to get geometry parameters from sketch inside the Part (like this:)
I'm doing this in following way:
ProError GeomDataExporter::GetModelGeometry(const ProSolid& solid)
{
ProError status{};
ProGeomitem* itemsOut = nullptr;
ProFeature* features = nullptr;
status = GeomDataExporter::GetAllFeatures(solid, &features);
int featuresSize{};
status = ProArraySizeGet(features, &featuresSize);
for (int i = 0; i < featuresSize; i++)
{
ProCurvedata* items = nullptr;
status = ProFeatureGeomitemVisit(&features[i], ProType::PRO_CURVE, GeomVisitAction, nullptr, items);
int featuresSize{};
status = ProArraySizeGet((ProArray*)items, &featuresSize);
if (status != PRO_TK_NO_ERROR)
return status;
}
}
ProError GeomDataExporter::GetAllFeatures(const ProSolid& solid, ProFeature** features)
{
if (features == nullptr)
return PRO_TK_INVALID_PTR;
ProError status{};
status = ProArrayAlloc(0, sizeof(ProFeature), 1, (ProArray*)features);
if (status != PRO_TK_NO_ERROR)
return status;
status = ProSolidFeatVisit(solid, FeatureVisitAction, FeatureFilter, features);
if (status != PRO_TK_NO_ERROR)
ProArrayFree((ProArray*)features);
return status;
}
ProError GeomDataExporter::GeomVisitAction(ProGeomitem* p_geomitem, ProError err, ProAppData app_data)
{
ProError status;
ProGeomitemdata* curveItemData = nullptr;
ProCurvedata* curveData = nullptr;
ProCurve curve;
if (app_data == NULL)
return PRO_TK_BAD_INPUTS;
status = PRO_TK_NO_ERROR;
if (status == PRO_TK_NO_ERROR)
status = ProGeomitemToCurve(p_geomitem, &curve);
if (status == PRO_TK_NO_ERROR)
status = ProCurveDataGet(curve, &curveItemData);
if (status == PRO_TK_NO_ERROR)
curveData = curveItemData->data.p_curve_data;
if (status == PRO_TK_NO_ERROR)
{
status = ProArrayObjectAdd((ProArray*)&curveData,
PRO_VALUE_UNUSED, 1, &app_data);
}
return status;
}
In two words, I'm starting Solid feature visit and then for each feature I'm starting geomitem feature visit with hope to convert geom item to ProCurve and then get ProCurvedata. BUT when I run my code for sketch above, I'm getting 5 features but only one of that features is PRO_FEAT_CURVE. When I'm trying to get geom item for each feature - 4 of the is PRO_FEAT_CSYS and only one is PRO_CURVE. And that one PRO_CURVE returns PRO_TK_NOT_IMPLEMENTED when I'm calling ProGeomitemToCurve which means that this curve is composite.
I have a feel that I'm doing something wrong OR API do not designed to get geometry data from sketch.
If somebody had some similar issue or know some another way to do what I want, please help.
IN conclusion I want to get for circle the coordinates of center and the radius , for each line the start point and end point, and the corresponding data for the curve.
Solved! Go to Solution.
code needs to be refactored.
use filter function with either PRO_TK_CONTINUE or PRO_TK_NO_ERROR return statuses. return PRO_TK_NO_ERROR when ProGeomitemToCurve (...) returns PRO_TK_NO_ERROR. Otherwise return PRO_TK_CONTINUE.
use visiting function to add ProGeomitems to a ProArray of ProGeomitems. return PRO_TK_NO_ERROR at each iteration. nothing else.
after visiting stops, loop through the populated ProArray and examine its members.
HIH.
I would question the validity of this code snippet:
your visiting function gets into sketch entities, the first sketch entity is a 'ref-zero' - which is not a curve therefore the returned status is anything but PRO_TK_NO_ERROR, the code falls through to the end of the function, visitor returns the status value, visiting stops...
Hello,
I think in your description you mean that ProCurveDataGet returns PRO_TK_NOT_IMPLEMENTED instead of ProGeomitemToCurve, right?
You should be able to check the type of the curve via ProCurveTypeGet. A composite curve is indicated by ProEnttype::PRO_ENT_CMP_CRV.
Then check out function ProCurveCompVisit to visit each "component" or rather sub-curve and process them accordingly.
Ok, I have found that the my visit action now works and I get there entities that I have in sketch and also PRO_ENT_CMP_CRV. And now I have an weird issue.
First two arks I'm getting and able to add to the app_data without error, but all next entities I unable to add to the out array:
Why this is happening?
code needs to be refactored.
use filter function with either PRO_TK_CONTINUE or PRO_TK_NO_ERROR return statuses. return PRO_TK_NO_ERROR when ProGeomitemToCurve (...) returns PRO_TK_NO_ERROR. Otherwise return PRO_TK_CONTINUE.
use visiting function to add ProGeomitems to a ProArray of ProGeomitems. return PRO_TK_NO_ERROR at each iteration. nothing else.
after visiting stops, loop through the populated ProArray and examine its members.
HIH.
Yeah, you're right. I found the reason for the issue. Now the code works as expected. I messed up with pointers and that's why the code wasn't working.