How to Obtain Length and Width Values from the Material Panel via SketchUp Ruby API?
-
How can I obtain the length and width values from the material panel using the SketchUp Ruby API?
I’ve checked the official SketchUp Ruby API documentation, but I couldn’t find a method that solves this issue. I also tried searching on Google and with AI tools, but still haven’t found an effective solution.
See the image below for reference:
If anyone has experience with this or knows how to retrieve these values through the API, I would really appreciate your help!
Thanks in advance!!
-
I am not a SU Ruby expert, but I think you can get and modify the dimensions for only those materials which has texture assigned to them and they has been added to the model. Then you can use
Sketchup.active_model.materials[x]
to get the material and then you can modify it's attributes.Others might have better ideas...
-
Here is a little snipet
Open the console, load the RB and type: matTexturedef matTexture() model = Sketchup.active_model materials = model.materials mat = Sketchup.active_model.materials.current mat_name = mat.display_name texture = mat.texture if texture t_height = texture.height t_width = texture.width UI.messagebox( "Material " + mat_name + "\n\nCurrent size:\n" + "Height: " + t_height.to_s + " inches\n" + "Width: " + t_width.to_s + " inches") else UI.messagebox("No texture applied to this material",MB_OK) end end
Please select a material first
Retrieved values are in INCHES
Hope this helps -
@Gábor Thanks for the suggestion! I actually tried this before posting, but it didn’t give me the length and width values I was looking for.
Still appreciate your help!
-
@Didier-Bur Awesome, thanks a lot! Your method worked like a charm — exactly what I needed.
Really appreciate your support!
Cheers!
-
Above is a little enhancement: select the material before typing matTexture in the console.
Regards
Advertisement