We encounter two issues in the import, to our application, of SketchUp files via SketchUp C API. The issues are related to SUArcCurve, SUCurve, and SUDrawingElementRef. Could you please advise?
To illustrate the issues, in SketuchUp application, created a polygon with 6 segments and a circle only without faces. Polygon created on ‘P’ layer and Circle on ‘C’ layer. The SketchUp file named sample.skp.
when I import this file in our application through SketchUp C API found the two issues:
Issue (1) as shown in the code below, for SUArcCurve and SUCurve SUDrawingElementFromEntity() always returns nullptr. Please see the comment inside the function
// Import curves
void ImportSketchUpImpl::ImportCurves(const SUEntitiesRef &entities, Dbms::LayerPtr parentLayer, const ColourValid &parentColour)
{
size_t curveCount = 0;
SUEntitiesGetNumCurves(entities, &curveCount);
if (curveCount > 0)
{
std::vector<SUCurveRef> curves(curveCount);
SUEntitiesGetCurves(entities, curveCount, &curves[0], &curveCount);
ColourValid colourValid;
for (size_t i = 0; i < curveCount; ++i)
{
if (IsCancelled())
{
return;
}
SUDrawingElementRef drawingElementRef = SUDrawingElementFromEntity(SUCurveToEntity(curves[i]));
if (SUIsValid(drawingElementRef))
{
// Never reached here. SUDrawingElementFromEntity always returns nullptr even though there is always a valid entity as curve is an entity (upcast). Need SUDrawingElementRef to get the layer colour, ...etc
// colour, layer..
}
}
}
//....
}
Issue (2) I didn’t find away to tell whether the curve is a polygon or circle. Here is the code snippet that shows the import. Please see the comments.
// Get curve
Dbms::LinePtr ImportSketchUpImpl::GetCurve(const SUCurveRef &curve)
{
if (SUIsInvalid(curve))
{
Assert(false);
return nullptr;
}
size_t curveEdges = 0;
SUResult result = SUCurveGetNumEdges(curve, &curveEdges);
if (result != SUResult::SU_ERROR_NONE)
{
Assert(false);
return nullptr;
}
Dbms::LinePtr curveLine;
if (curveEdges > 0)
{
curveLine = Dbms::CreateLine();
SUCurveType curveType = SUCurveType::SUCurveType_Simple;
SUCurveGetType(curve, &curveType);
SUArcCurveRef arcCurve = SUArcCurveFromCurve(curve);
if (SUIsValid(arcCurve) && curveType == SUCurveType::SUCurveType_Arc)
{
// Reach here for both the polygon and circle. i.e the circle and polygon has SUCurveType::SUCurveType_Arc even the downcast is successful to SUArcCurveRef
// So how to tell whether this a polygon or circle. Here if is a circle and we need to deal with it different than a polygon.
}
else
{
// Line segments....
}
}
return curveLine;
}
Thanks,Issue2PolygonOrCircle.skp (103.3 KB)