How to export each object using c++ api?

Hi all.
I need to export each separate object from a sketchup file.

I found and using the function SUModelGetEntities to retrieve all the entities, then for them I execute SUEntitiesGetFaces to retrieve all the faces in the model.
The problem is that if I have for example a cube and a circle, I retrieve 7 faces but I don’t know how two create two separate object.

Should I traverse the model in another way to retrieve the objects?

Someone could help me, please?

That is fine for the faces. Now do the same for all the other types of primitive entities at the toplevel (in the model’s entities collection.) Ie, edges, guidelines, guidepoints, etc.

Afterward repeat for complex objects that have their own entities collections, ie, groups and (component) instances.

Refer to the documents for the functions you can call upon the Entities collection:

ok for the other entities.

But if I want to know what are the entities ’ to which belong faces, how can I do?
I need to import them in separate object:
for example a cube has 6 faces and a circle has 1 face,
I’ve tried to export as obj model and I have two meshes (one for cube and one for circle)… I have to do the same in my source code.
Is it clear which is the problem?

There is no “cube” type object in the SketchUp Object Model.

You’ll just have to write your own code to determine which face objects share common edges.

In the SketchUp Object Model, a circle is a sub-type of Curve, called an Arc Curve, whose start and end vertices are the same. (Ie, the arc’s sweep angle is 360 degrees or 2*Pi Radians.)

So get one of the face’s edges.

And then check to see if the edge is part of a curve:

Check the curve type, to see if it is an Arc, if it is, it might be a circle. To test, get it’s collection of edges, and compare the start vertex of the first edge, with the end vertex of the last edge.

You need to clarify what you mean by “object”. As @DanRathbun has pointed out, SketchUp has geometric primitives and isolated collections of them (groups and components) but it has no larger or more structured notion of “object”. So, what does it mean to export an object?

Perhaps what you are looking for is an SDK equivalent to the GUI’s triple-click or context menu Select->all connected and the Ruby API’s #all_connected methods on Edge and Face Entities. These recursively find all the Entities that share geometry with the starting Entity and anything it touches. They will gather in everything that is not spatially isolated from the argument or in a different Entities collection (group or component). This is as close as SketchUp has to a notion of non-primitive “object”.

Alas, so far as I can tell (@DanRathbun please correct me if I’m wrong) the C/C++ SDK has no such pre-written method. If you want such, you are expected to write it yourself using the sorts of functions Dan listed to follow the links between touching entities.

So far, I haven’t found one nice utility function as part of the API.
(But there might be some example code in the samples.)

There is:
which tells you if the edge is shared. A single face or 1 if not, more if so.

There is also the SUEdgeUse objects.
which can be accessed via a SUEntityRef or a SULoop object.
This type of object has functions
to find the linked edge uses. And the following to help in iterating edge uses of loops:

So it looks like you’d get the outer loop for a face:
… then get it’s edge uses array:
… iterate this, checking for partners, and collecting the partner EdgeUses’s face:
… repeat until you have collected arrays of all the connected edges and faces for a single “spatial object”.

Then process this collected set of edge and face references for export, as whatever kind of object it needs to be in the destination Object Model.

I try to explain better…
I’m doing the following in sketchup:

  • create a rectangle and push pull (->create a sort of cube)
  • create a circle

If I export these geometries using OBJ format, I have two meshes: one contains the push pulled rectangle and the other that contains the circle.

Now my problem is that I have to do the same thing importing this sketchup file:
I have to create an entity that contains the push pulled rectangle and another entity that contains the circle.

Should I write the code to determine which face objects share common edges and create one entity, from my side, using this behavior?

Is it clear now?

Yes this is what we have been advocating.

But since, you never said what format “your side” is, we can only go on guessing. We do not know if “your side” has groups or components, or only “mesh objects”.

In SketchUp’s world, if primitives are not part of a group or component instance, then they are primitive geometry that belong to the model’s entities collection. They will however interact and “stick to each other” and share vertices, etc.

The APIs do have a Polygon Mesh helper (virtual) class, which is often used to facilitate import and export. The samples show using this.

Have you looked at the samples for export to, and import from XML ?