Hi All! I just got started with the C API yesterday and made some good progress. I was able to create the necessary wrappers so I could call some of the API functions from C#. (I know there are wrappers out there, but I like doing this sort of thing from scratch when learning a new API, as it helps make it stick in my memory.) By the end of the day, I was able to create a simple SKP file with a couple of triangles in it, with the vertices welded where they should be (via SUEntitiesFill).
When I open the file in SketchUp Make, the geometry appears correct, but the style settings are not what I usually use. For example, a selected edge appears in yellow (not my usual blue).
I am guessing I need to set something else in my model, but I haven’t been able to find anything that directly addresses setting a style. Searching for info, I found some references to SURenderingOptionsRef, but nothing much on styles. Is there a way set the style my model uses, or edit it, using the C API? Perhaps with an options provider?
I note that people are sometimes encouraged to describe their skill levels, to help others assist with answers posters can use. I’m a pretty good programmer in general, with a lot of C and C# experience. Been using SketchUp for a year or two, but only began with the C API yesterday. Obtaining references (such has to models, entities, loops, typed values, and so on) and adding vertices and faces seems straightforward enough. I’m getting an early idea of SketchUp’s document structure (but would be very grateful for pointers to more online info about that). I have used the Options Manager and units Options Provider to set my model to use meters and decimals (which was also when I learned that SketchUp stores everything in inches, no matter what you set the ModelUnits to).
Hope that’s a good way to ask my question. Looking forward to getting to know folks here and, maybe, helping answer a few questions myself, when I can.
That’s true. If I import my model, the style already in use applies. I’m curious about the case where I open the model directly, rather than import it. I suppose I could finesse the problem by creating a model in SketchUp, setting the style as I prefer, saving that file, then operating on it with the C API (rather than creating one from scratch). But that doesn’t do much for my curiosity .
Do you think this might be something that involves the Scene, rather than the model? That’s still an unexplored part of the C API for me, but maybe SUSceneFromEntity, followed by SUStylesApplyStyleToScene might get the job done.
Of course I haven’t tried it yet, but I think the function you posted would provide a reference to a style, but would not apply it.
Working on this now, and will post more if I find out anything Thanks for the quick reply!
This means coders are limited to creating .style files and loading them into a model, and then setting the active style for the model’s styles collection (ie the global style,) or the specific style for a certain scene page to use.
If the property you need to set has not yet been exposed to the C SDK / API, then you’d need to mimic the codeflow that Ruby coders must employ (mentioned above.)
ADD: … And you should file a feature request(s) for those style properties that have not yet been exposed to the C API in the tracker repo.
Note that SUSceneFromEntity is just a downcast operation so that you can access entity level functions (that would be inherited by subclasses in an OOP environment like Ruby.)
To set the style to be used by a specific scene page (after having loaded or created a style) you’d use: SUStylesApplyStyleToScene
I’d think it’d be a function of the model, but I don’t see it yet. (May need to check the issue tracker to see if there is an open issue for this.)
Ah … okay it is hidden in a boolean function parameter of the Styles collection … SUStylesAddStyle (SUStylesRef styles, const char *path, bool activate)
EDIT: I think I’ve come to another conclusion. See post 12 below.
Also note that the “old” RenderingOptions interface also affects the currently active style of the model. (But does not work well, if at all, for the style objects of scene pages.)
Oh, man, you are a life-saver! I never would have found that. I spent a lot of time scanning the model-related functions too, on the same expectation you had. Quirky way to do it, with a flag. Wonder what you’re supposed to do if the style has already been added…
Hey, while I have your attention (and thanks so much!), can you recommend a good resource for me to use in understanding the SketchUp document object model?
That got the job done! I just saved the style I like to use to a file, then added/activated it when I created my model. The model now opens in that style.
Thanks again. (I will try to figure out how to mark this topic as solved.)
I am thinking that this is one of the situations where the words “active” and “selected” may cause confusion.
In several of the collections, the “active” member can differ from the “selected” member.
But (after testing manually in SU2018) it appears that the two words have the same meaning for the styles collection. Whatever is selected is what the active style is that is used to render the viewport.
When I have a model with 3 scenes, each with it’s own style setting, the “selected” style (in the Styles inspector panel) changes to match which ever style is used for the scene page I choose.
If I were to delete the 3 scene pages and just have a single model view, whichever of the 3 styles I “select” becomes the “active” style for the model.
So it appears that the C API’s function to change the model’s global style would be:
The “active” style is different from the “selected” style if there was been changes made to the rendering options.
I was working with styles the other day myself and I found that there was functionality lacking in terms of applying active style to the selected style. Or even fully set all properties of a style.
Log any missing functionality you find in the issue tracker:
Does this implies that there is a temporary style being created ?
Keep in mind we are talking about the creation of a file, and how it will appear when first loaded into SketchUp. We’d think that there is one of the two (selected or active) that is the saved state, and upon loading one (guessing selected) inherits the setting of the other (guessing active).
Ie, the Ruby API has a “selected” style setter, but no “active” style setter.
But it has separate getter methods for both.
Yes. There is a “working set” style as the user change the rendering options. This is applied to a given style when the user clicks on the thumbnail of the style.
There is no way to set the “active” style - in the same manner as you don’t set the active model or active view - they are always there. But it may or may not be synced with the selected style depending if changes has been made.