How to purge unused entities in SketchUp API?

i want to purge unused entities in skp file, such as “Purge Unused” in SketchUp, how to do it? is there any API in SketchUp API?

1

There are purge API methods for components, tags[layers], materials and styles.
You need to do them in that order - because components can keep materials etc, resulting in the purging being only partial…
You should look at, and get inspiration from, my well established extension, available here…
https://sketchucation.com/pluginstore?pln=PurgeAll

2 Likes

This is posted in the C SDK category.
Do you need to do this outside a SketchUp application process?

I can only find 2 function about purge:
SU_RESULT SUModelPurgeUnusedLayers(SUModelRef model, size_t* count);
SU_RESULT SUModelPurgeEmptyLayerFolders(SUModelRef model, size_t* count);
just in model.h file.

is there anyother function about purge?

where are the purge API methods for components, tags[layers], materials and styles?

If you notice in the subsequent post you referred to the API and I replied to that assuming you meant Ruby.
In that API there are the methods I mentioned.
I don’t know about the C SDK methods…
If the method ...SUModelPurgeUnusedLayers(...
etc exists, then logically there should be some equivalent methods for Components [Definitions], Materials and Styles ??

Except for Layers (aka Tags,) they do not exist in the C API.

You must write your own iterator functions that determine whether the resource is used or not. If not then you can queue it up for removal.