Batch Created Material Name Changes to <auto> in Colors in Model

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

Check if an API issue is logged in the tracker … if not you could open an issue.

https://github.com/SketchUp/api-issue-tracker/issues


Oh and you should put custom materials in the user AppData folders …

"~/Application Support/Sketchup 2020/Sketchup/Materials/"

Also might wanna check this thread:

Oh and you should put custom materials in the user AppData folders …

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.

Thanks, I know the code has them saved into a different location, but that is for internal permission and network issues. Before testing, all the files are placed in the Application Support/Sketchup 2020/Sketchup/Materials folder

Check if an API issue is logged in the tracker … if not you could open an issue.

Thanks for that resource, I hadn’t thought about checking there. My initial search didn’t turn up anything. I will do so more testing to see if it is API related or something to do with the build of Sketchup 2020 we are running.

Thank you for the help

Also might wanna check this thread:

Thank you, I actually had no problem doing just that. I had a CSV from a popular paint company that had hex values and color codes. Creating 1500+ skm from that CSV worked great and the files are still being used with no issues. Only when I went to make skm from jpg images did the problem present itself.