Could someone post an example of how to use the c api to create a face and extrude it in a new skp file

I’ve just started to learn the C API and need to use it to draw boxes, which in Sketchup would be done by drawing a face and the PushPull (extruding) it. Could someone provide an example of how to do this in code?

Thanks,
Jason

Refer to the examples provided in the SDK’s “samples” directory.

Specifically, the “Texture Mapping” example will show you how to add faces to a new model file, using the SUGeommetryInputRef builder object. (This builder merges vertices and edges, etc. whereas the individual entity creation functions do not. Ie, contrast this “Texture Mapping” example with the “WritingToAskpFile” example that uses the SUFaceCreate function that would not merge the face with exiting geometry.)

Sorry about the need for extrusion, but this is not a feature of the standalone C API. It is a GUI tool of the SketchUp application. So you’ll just need to write the code in C to create all 6 sides of your boxes at the size desired.

If you are using the C API for a “live” C extension within SketchUp, please note that the C API is read-only for the active model object. But since Ruby is implemented in C, it is possible to call SketchUp’s Ruby API methods from C to cause a PushPull operation.

1 Like

Make sure you read thoroughly the introduction page:

SketchUp C API: SketchUp C API

Hi Dan, thanks for the really quick reply and for the guidance - I’ll take a look at the example that you mentioned. I have one other question - when I looked in the SDK folder I found a project that is written in C# - is it possible to perform all of the C API functions using C#? I’m guessing that the sketchup dll and lib files are wrappers around the C API? The reason I ask is that my preferred language is C#. And, if this is the case is there any documentation for the C# libraries (or is everything just a mirror of the equivalent C items)? Thanks again, Jason.

What project was that?

They are the C API.

We (Trimble) don’t have an official C# wrapper. But there is a couple of community driven wrappers.

Please be specific and include links when making these statements of fact.

Ie, … I myself find that all of the examples are C++/C in the SDK “samples” directory.
There are no .cs files that I can see anywhere in the SDK versions I have downloaded.

Perhaps, if you use a C# wrapper around the SketchUp C API(s).

The couple of guys who had made wrappers are on GitHub.
I see Thomas has provided the links.

I haven’t found the time to try them yet so I do not know if “all the C API functions” are wrapped.

The former linked wrapper does not quite follow the correct class hierarchy and it uses coordinates as used in Unity. I also think it only wrapped what Mr. Miller needed.

Ken’s wrapper is likely closer to how the SketchUp APIs are organized and is more comprehensive.

Also … are you wanting to use the APIs for files or in the “live” SketchUp application scenario ?

Hi Dan, thanks for getting back to me and for providing further guidance. I’m writing a stand-alone application that creates skp files - I don’t have a need just now to interact with a live model.

I’ll take a look at the two alternative C# solutions - thanks again.

Thanks for the links to the C# wrappers - I’ll take a look at them. Really appreciate the reply. Cheers, Jason.

Re ‘What project was that?’ - it’s a project called ‘SketchUpNET’, which I found in my Sketchup SDK folder. I downloaded the SDK some time ago, so can’t remember now if I downloaded this C# wrapper from somewhere else, but I assumed it came with the SDK - sorry if I’ve caused confusion?

Okay then, I think you can use a C# wrapper.

I was told that we cannot wrap .lib with C# which we must use with the “live” application process.
Know any online information to this effect ?

That is a 3rd party offering, not from Trimble.

The repository (last update 17 months ago) is here:

… Oh I remember now a possible drawback to the last mentioned C# wrapper.

It redistributes Trimble’s C SDK, so it may not be the latest up to date version.

Thanks for confirming. Cheers.

Thanks for letting me know. I think I’m going to just write it in C++ - I’m thinking of it as a learning opportunity!

1 Like

It’s not a confirmation as I’m not a C or C# programmer myself. It’s just what I heard.
You can still wrap the DLLs in C#.

But the reason I was wanting confirmation regarding .lib files is that another modeler DesignSpark (aka SpaceClaim) has C# APIs for their live applications. So I wonder what did they do differently?