[C API] Is there a way to create an arc?

I’m trying to make a cylinder (and other curved shapes, eventually). Step 1 is to create an arc, and I’m failing at that. Here is what I’ve tried:

SUPoint3D ac_from{ 5, 0, -1 };
SUPoint3D ac_to{ 3, 4, -1 };
SUPoint3D ac_center{ 0, 0, -1 };
SUVector3D normal{ 0, 0, 1 };
SUGeometryInputAddVertex(gi, &ac_from);
SUGeometryInputAddVertex(gi, &ac_to);
SUGeometryInputAddArcCurve(gi, 0, 1, &ac_center, &normal, 3, nullptr, nullptr);

This creates a piecewise linear path, which is something I can do that with a LoopInput. That lets me create a regular polygon that approximates a circle, which results in very large model files.

Is there a way to create a circle using the C API the way it can be done using the SketchUp user interface?

Yes, you can add ArcCurves directly into an Entities collection …

But, FYI there are differences between the Ruby API method and the C API function, see:

SUEntitiesAddArcCurves warns that it will create invalid models and suggests instead to use GeometryInput. That’s what I’m doing in my example, and it doesn’t create any curves, only polygons.

If you did not want it to merge, and say you were working within an empty entities context like that of a group or component definition then the non merging wouldn’t be an issue.

With the Ruby API, we often create geometry in a group context and then explode it to control when the merging happens. However, the C API has yet to implement context exploding. I logged the issue some time ago …


I’m not a guru on GeometryInput but I wonder if the indices are 0 or 1 based ? There are some collections in the APIs that use 1 based indices.

EDIT: And in the SketchUp world, closed ArcCurves actually are polygons.

Pretty sure they are 0-based. Changing the “0, 1” to “1, 2” causes a crash.

I also added a face like this:

SULoopInputRef loop = SU_INVALID;
SU_CHECK(SULoopInputCreate(&loop));
SU_CHECK(SULoopInputAddVertexIndex(loop, 0));
SU_CHECK(SULoopInputAddVertexIndex(loop, 2));
SU_CHECK(SULoopInputAddVertexIndex(loop, 3));
SU_CHECK(SULoopInputAddVertexIndex(loop, 1));
SU_CHECK(SUGeometryInputAddFace(gi, &loop, nullptr));

and I get a polygon with the correct coordinates instead of a circle segment.

[SU_CHECK() is my macro for checking the return code.]

I tried calling SULoopInputAddCurve(), SULoopInputEdgeSetSoft(), and SULoopInputEdgeSetSmooth(), but these don’t seem to have any effect. The comments for these functions also don’t explain what “soft” and “smooth” mean. I’m just stabbing in the dark at this point.

SketchUp’s API docs are kind of terse dictionaries or programmer’s references. They’ve never been called “teaching aides”.

Refer to the online SketchUp User manual.
https://help.sketchup.com/en/sketchup/softening-smoothing-and-hiding-geometry

When the C API’s docs fail you, have a look at how the comparable way of doing things in the Ruby API docs. https://ruby.sketchup.com/index.html

Thanks. That’s a helpful page. It looks like I want to make some edges soft and smooth. Now I just need to figure out how to do that by using the C API. There seems to be two ways of doing everything, and I’ve only tried one of the two so far.