How to delete the specific style with C API?

Hey, all:

As mentioned in the title, I want to know how to delete a selected style what I retrieved from the styles object.

And the get selected API is in:
SU_RESULT SUStylesGetSelectedStyle (SUStylesRef styles,SUStyleRef * style)
http://extensions.sketchup.com/developer_center/sketchup_c_api/sketchup/styles_8h.html#a2b9de1ccca04fbbcfaefe48e5a041f16

Appreciate for any help :slight_smile:

There is no C API equivalent to the “live” Ruby API’s Sketchup::Styles#purge_unused method.

File a request in the API issue tracker if you need this C API function.

But,… you would need to iterate all the model’s scene page’s and the model’s style setting itself to be sure that all their style settings were not pointing at the style you would be purging.

It might also be nice to have a boolean function to ask a SUStyleRef object whether it is being used. (Or it could be a boolean of the SUStylesRef collection object?)

1 Like

Thanks Dan.

Actually, I just want to switch my old watermark to the new one in the part of watermark with API. Don’t know is there a direct function or a workaround method could do this…

The Ruby API has only two style properties exposed (name and description.) So we’ve never been able to do anything with styles.

The new C API has quite a bit more exposed. See …
http://extensions.sketchup.com/developer_center/sketchup_c_api/sketchup/style_8h.html
… and the property getter and setter, as well as the property types enumeration.

I do not see the watermark exposed. If not, again, open an issue.


Just FYI, … .style files are zip archives containing XML files of properties and subfolders of resources (such as watermark images.) You might be able to clone your style to a new file and replace the watermark image using a zip library. Then add the new style to the model file and set it as the active style.
But until a purge function is added to the C API the old style will remain unused within the model file.

1 Like

Also, … you can of course create the new watermark style manually using SketchUp, then use the C API to add it to existing model files.

Got it. I’ll try. Thanks a lot!

1 Like

Along with the release of SU2019.2 the SDK is also updated to 7.1 and you can now use SUStylesRemoveStyle

http://extensions.sketchup.com/developer_center/sketchup_c_api/sketchup/styles_8h.html#abc1ab0c3e129ffb2207de8f43e93a6c5

1 Like

Bingo! It’s very useful… Thanks man!