Q regarding what is/isnt exposed to the API

Are the individual setting for materials programmable through the API?
I was looking at the Elgato Streamdeck+ (Stream Deck + | Elgato) and It got me thinking how nice it would be to be able to adjust the selected material’s setting via the dials, specifically I’d like to be able to:

  • Change the mode between RGB and HLS (a press of one of the dials)
  • Change the value of R,G,B,A or H,L,S,A (rotate the dials)
  • Scale the Texture (press to toggle between A and Texture and rotate the dial)

All my work is rendered so being able to quickly and easily ‘play’ with colours and instantly see the results would be if nothing else a lot of fun.

This is of course all moot if the values are inaccessible via the API, so the question is, are they?

I’ve been using SU since 2004 and I’ve only just noticed that the Picker dropdown states HLS but the order of the individual sliders is HSL!

It is supposed to be HSL.

Yes Material and Texture settings are exposed to the API.

However, the GUI interface is a user interface not an API interface. It does not make sense to directly “flip a switch” in the GUI, or “spin a dial” from the API. This is not what the API is for

Instead the API setter methods directly set a color value to what is intended in one step. There is no need to step through a bunch of intermediate color values to get to the value needed.

The current GUI interface does this for the SketchUp view. But SketchUp’s API will not effect external renderings in say V-Ray. The V-Ray (or whatever renderer) interface would need to do this.

I use Enscaple which is a real-time renderer and I can dynamically change the SU material properties and see it instantly in the render window.
Other material properties such as roughness/bump etc are controlled through the Enscape materials dialog but once set for a particular material type I rarely change them.

So are you saying that I could affect the currently selected material’s colour/ texture size via the api? ( I only posted the screenshot for context)

Yes, but I think your not being clear in how you would want to “change” the currently selected material’s properties that would be better or different than through the Materials inspector panel ?

I’ll try and be clearer:
I would like to select a material either through the panel or more often via the eyedropper tool
Change the mode (click action on 1st dial) to either RGB or HLS

Assuming we are in RGB mode
I’d want to be able to change the red value via the 1st dial between 0 and 255
the blue value via the 2nd dial between 0 and 255
the green value via the 3rd dial between 0 and 255
the opacity (alpha) via the 4th dial between 0 and 100

Assuming we are in HLS mode
I’d want to be able to change the Hue value via the 1st dial between 0 and 360
the lightness value via the 2nd dial between 0 and 100
the saturation value via the 3rd dial between 0 and 100
the opacity (alpha) via the 4th dial between 0 and 100

Clicking the 4th dial would change to texture mode, rotating it would increase/decrease the width of the texture (height linked) by NNmm

Okay, still I do not see much difference why you cannot use the native Materials panel.

But YES … if you like, you can program up a HTML Dialog with mirrored controls that affect the same settings you have in the native Materials panel. The learning curve may be steep if you do not know HTML, JavaScript, CSS and Ruby.

There is a quirk with the Sample tool in that after picking a painted face, the Paint Bucket tool is activated. This might be undesired. A workaround might be to code a custom Ruby tool using the PickHelper class.

Personally, I wouldn’t require an interface at all, the SD+ would be it.
Here’s a photo of my setup

Sketchup on the Right Monitor and Enscape on the Left, I can fly around the entire house in realtime using the keyboard or the xbox controller.
Picture the SD+ where the xbox controller is and me playing with the wall paint colour in real time.

Hard for me to do, as I don’t know what an SD+ is. A Bing search is of no help.

Speaking of keyboard control, it would likely be possible to code a custom Ruby Tool that accepts certain keypresses to increment or decrement the various material properties.

R - increase Red component
SHIFT+R - decrease Red component

G - increase Green component
SHIFT+G - decrease Green component

W - increase Texture width
SHIFT+W - decrease Texture width

… etc.

I’m following this thread - I’ve been looking at making a new colour picker that isn’t SRGB based.
There are lots of better perceptual alternatives now - SketchUp for i.pad has OKLAB or OKHSL which is so much better for humans.

I’m not well versed in this stuff , but after @thomthom and @ChrisFullmer 's Ruby 401 class at Basecamp , I’ve been trying

# Get the active material
model = Sketchup.active_model
materials = model.materials

# Create a color object from RGB values
red_color = 199

blue_color =75

Green_Color =137

new_color = Sketchup::Color.new(red_color, blue_color, Green_Color)

# Assign the color object to the active material's color property
active_material.color = new_color

now all you need is a way to get your streamdeck to change those SRGB values and a way to send that ruby script to SketchUp

1 Like

StreamDeck+, I mentioned it in the 1st post, it has the physical dials I’ve been talking about

Two issues with your snippet.

materials is undefined as you’ve written it.

I think that just after SketchUp loads a model, there is no current material and nil will be returned.
This means either your code or the user must select a material from the “In Model” materials collection.

1 Like

LOL at my denseness. I had no idea what you meant by the “dials”. I thought you meant to create them virtually in an interface.

Let me try again, I’m still trying to get my head around this.

Edit whoops. I had deleted something in Vscode without realising it

Got it!

1 Like

This is the support doc for the StreamDeck+ dials https://help.elgato.com/hc/en-us/articles/10715833118989-Elgato-Stream-Deck-Dials-Introduction
The 3rd screenshot shows assigning keystrokes to CW and CCW actions of a dial, so if the rb increases/decreases a value by 1 (with min and max limits) the dial could trigger them.

So I think the question is how intercept a keystroke with a SketchUp ruby extension.
I bet that is where things get difficult

If the setup on the SD+ causes the PC to send a key press event to SketchUp, there would be no difference in handling it in a Ruby Tool than if a real key is pressed.

So this is the area to look in

Class: Sketchup::Tool — SketchUp Ruby API Documentation

If the rb was assigned an obscure SketchUp keyboard shortcut such as Ctrl-Alt-Shift-R then it should work.
I do see a problem though as we need ones for Red+, Red-, Blue+, Blue-, Green+, Green- and the same for HLS, the mode switch (RGB>HLS) and transparency… that’s a lot of shortcuts.
There is an SDK for the Elgato products but that’s seriously beyond me… I’m just a user