SketchUp SDK C SUCurve polygon or circle issue

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)

ArcCurve and Curves aren’t derived from DrawingElement. They are derived directly from Entity (similar to Vertex). Curves in SketchUp are meta-entities composed of a set of edges - a means to store their curve relationship. Edges are DrawingElements - as they are seen and manipulated directly in the viewport.

Can you provide an example model to accompany this code example?

Thanks. I will use one of the edges to get a drawing element as they should be the same for all edges within the same curve or arccurve. is that right?

Sure. Attached “Issue2PolygonOrCircle.skp”

I see now. There’s a short coming in the C API. A hexagonal curve is represented in SketchUp as an ArcCurve - but there’s an internal flag to indicate whether to treat it as a polygon or arc.

In the Ruby API there is an method for that: Class: Sketchup::Curve — SketchUp Ruby API Documentation

Turns out that the C API SUCurveGetType is an entity type check. The polygon flag appear to be omitted.

I logged this as an issue: C API missing function to detect polygons · Issue #194 · SketchUp/api-issue-tracker · GitHub

I wasn’t able to find any workarounds I’m afraid.

1 Like