api-issue-tracker icon indicating copy to clipboard operation
api-issue-tracker copied to clipboard

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

Open Tamacun opened this issue 4 years ago • 6 comments

  1. SketchUp/LayOut Version: Sketchup 20.2.171
  2. OS Platform: Mac running Mojave 10.14.6 (Also Mac running Catalina unknown build #) - NOTE: The error can not be reproduced on Windows 10 running Sketchup 2019.

A Ruby script is used to create many Sketchup Materials and save them as .skm files. The .skm files are created, named uniquely, and when placed in Application Support/Sketchup 2020/Sketchup/Materials/Test Folder, they load into Sketchup Materials browser successfully and are named properly on Hover.

The first material selected by clicking on it in the Material Browser will load into paint bucket. This is confirmed using materials.current.

Issue 1 Once the material is applied to a face (or group) the material will display in the "Colors in Model" with the appropriate thumbnail, however the on Hover name is shown as <auto>. This is confirmed using material.name in the Ruby Console of the active model.

Issue 2 Additionally, once the first material has been selected, no other materials created using the API can be applied. This is confirmed using the materials.current after selecting the 2nd material. If the user tries to select a 2nd material, once they click on a face (or group) the 1st material will be applied.

It is expected that since these materials have unique .display_name, .name, and texture images, they should be able to be used as any other manually created texture, and their name should remain the same once added to the active model.

#Hook into active model
model = Sketchup.active_model
materials = model.materials
path = '/Users/[tamacun]/Desktop/Ruby'

Dir.foreach(path) do |image|
		
		#Strip file extension from name
	base_name = File.basename(image, File.extname(image))
	p base_name
	
		#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)
	p material

		#Add texture file to material
	material.texture = properties

		#Add name to material
	material.name = materials.unique_name(base_name)
	
		#Set File Save Name
	skm_name = base_name + '.skm'
	
		#Set the file save location to a local disk for permission reasons. Add files to Application Support/Sketchup 2020/Sketchup/Materials manually
	save_location = File.join(ENV['HOME'], 'TestMaterials', skm_name)

		#Save .skm file to folder
	material.save_as(save_location)

	
end

I will readily admit that my Ruby proficiency is lacking however, I was directed here after seeking help on the Sketchup API forum.

Thank you in advance to all the contributors in the community and those working in an official capacity.

Tamacun avatar Feb 24 '21 17:02 Tamacun

Can you provide some example materials to go along with this?

thomthom avatar Feb 25 '21 08:02 thomthom

Can you provide some example materials to go along with this?

Sure. Mats.zip

Tamacun avatar Feb 25 '21 13:02 Tamacun

Logged as: SKEXT-2933

sketchupbot avatar Mar 01 '21 07:03 sketchupbot

Hi, is there any progress on this bug? This is very annoying for me as well. I don't have any scripts running at all.

To reproduce with me, I imported textures into sketchup using the link found here: https://3dwarehouse.sketchup.com/model/12caa5ffb27ae6aac2e6b25689767769/akb-Wood-Species-wood-materials-texture-bonus-pack?hl=en

  1. Open sketchup file at above link
  2. Go to "Colors In Model" list for textures
  3. Duplicate "Colors In Model" and rename it "Wood Textures"
  4. Open new sketchup file and apply one of the textures from "Wood Textures"
  5. Go to "Colors In Model" and hover mouse over that texture. It's name is now <auto>

The reason this bug is so annoying is that...once a texture is renamed to <auto> it shares the name as all the other textures named to <auto> and thus, I can no longer switch between textures in Sketchup because they all have the same name.

I am running Mac Mohave 10.14 and Sketchup Pro Version 21.0.392.

ntreat avatar Aug 14 '21 18:08 ntreat

Do you think the problem is caused by the #unique_name method? If so, see if you can code a workaround.

DanRathbun avatar Aug 15 '21 11:08 DanRathbun

Hi Tamacun,

As part of trying to reproduce old bugs, I have encountered this one and wanted to know if this is still an issue for you with latest SketchUp version. I am not able to reproduce it on SU2025.0. Please let me know.

Thanks

kalpana-ghodeswar avatar May 15 '25 13:05 kalpana-ghodeswar