Hello,
First of all, thanks again for all the awesome help on this forum. Lots of knowledgeable and helpful people, that’s a tough combo to find.
So I wrote a script that creates .skm files based on name and hex color values. It works well with no issues.
I modified it to be used with a directory of image files.
It works as expected. The .skm files are created, named properly, and when placed in a folder in Application Support/Sketchup 2020/Sketchup/Materials/Test Folder, they load into Sketchup Materials browser successfully and are named properly.
That’s where the success story ends.
Once a material is selected and applied to any geometry, the thumbnail shows up in the “Colors In Model” list, as is to be expected. However, the name of the material changes to <auto>.
I thought it was an error with the script, so I explicitly set the .name and .display_name of each material, as well as adding the .unique_name override. I tried running the script on each image file separately. Neither solved the issue of name in “Colors in Model”.
I thought it might be an issue with the file names being similar to existing materials (ex. Asphalt), so I gave them outlandish names that don’t exist in any existing Material Library.
Then I loaded the same .skm files onto a Windows machine running Sketchup 2019, and lo and behold, they import fine, apply fine, and the “In Model” list displays their appropriate names.
So, the issue can only be reproduced on Mac running Mojave 10.14.6 with Sketchup 20.2.171
I run the script in the Sketchup Ruby Console.
Here is the script:
#Hook into active model
model = Sketchup.active_model
materials = model.materials
path = '/Users/[sertfas]/Desktop/Ruby'
Dir.foreach(path) do |image|
#Strip file extension from name
base_name = File.basename(image, File.extname(image))
#Create full file path
image_path = File.join(path, image)
#Texture Properties
image_height = 24
image_width = 24
properties = [image_path, image_width, image_height]
#Add material by name
material = materials.add(base_name)
#Add texture file to material
material.texture = properties
#Set File Save Name
skm_name = base_name + '.skm'
#Set the file save location
save_location = File.join(ENV['HOME'], 'TestMaterials', skm_name)
#Save .skm file to folder
material.save_as(save_location)
end
Are you able to reproduce the error? Is there something obvious I’m missing?
Thanks in advance for any help you can offer