[PLUGIN] Add Texture from MaterialColor
-
This plugin checks for any material without a texture, then assigns one(4x4 px bmp) based on the color of the material.
This is useful when importing in Lumion. It makes editing material properties easier(no need to generate the texture bitmap).This is my first ruby published, so I welcome any comments
-
Thanks for posting!
As for file paths, I don't know whether backslash paths will work for OS X users. Ruby usually abstracts filepaths and uses internally the standard unix paths.
Instead of doing:
matPath=File.dirname( Sketchup.active_model.path ) + '\mat\\' thumbnail_fn = matPath + e.name + '.bmp'
you could do:
mat_path = File.join(File.dirname(Sketchup.active_model.path), 'mat') thumbnail_fn = File.join(mat_path, e.name + '.bmp')
This way, Ruby will care about using the correct delimiter.
In addition to that, active_model.path is empty if the model has not been saved yet. In that case we either have to let the user choose a location, or we fallback to a default directory:
Sketchup.active_model.path || ENV["HOME"] || ENV["HOMEPATH"]
-
well, testing under windows vista
mat_path = File.join(File.dirname(Sketchup.active_model.path), 'mat')
returns
c:\folder\subfolder/mat
so ruby can't create the folderSketchup.active_model.path || ENV["HOME" || ENV["HOMEPATH"]]
does nothing for me(afaik).
I prevent the user from running the script unless the model is saved.
cmd.set_validation_procI'd have to make a separate .rb for mac, and i can't test it.
-
Sorry, I oversaw that:
File.expand_path expands all truncated path (or links) and translates Windows into unix delimiters. For unsaved models, active_model.path is an empty string (not nil), so we add an explicit conditional:
model_path = File.expand_path(Sketchup.active_model.path) model_path = ENV["HOME"] || ENV["HOMEPATH"] || return if model_path.empty?
@unknownuser said:
I'd have to make a separate .rb for mac, and i can't test it.
I don't think so. As long as we can avoid introducing platform-specific calls, we should keep one single version (which is also much easier to maintain). Most scripts (that use the SketchUp API or standard Ruby) are cross-platform anyways. Here are a lot of helpful people that help testing.
-
I think I can make that work, I'll upload the corrected version as soon as I have it. Thanks for the advise.
-
The hybrid
c:\folder\subfolder/mat
should still work when checking/making the folder - it just looks odd...
Aerilius'sFile.expand_path(...)
will simply make all \ into /.
The only time you need to keep a \ as a delimiter in a path is if you are on a PC and you are going to use it in a system/DOS call like a .bat or .cmd file...
PCs can otherwise cope with either \ OR / MACs always want /, so.expand_path
or.tr("\\","/")
will both fix any path to suit most things, and at least display neater if it's printed out...
To make the path PC AND DOS suited you can reverse the path delimiter logic as.tr("/","\\")
-
Done, I used File.expand_path(...) and modified to allow running the plugin without saving.
Anyways, it's a good idea to save before. -
Simply add after line 97:
e.texture.size = [1.m, 1.m]
Ramiro, the rescue block gives out an error assuming an error with non-ASCI characters. But there could be sooooo much else that causes errors (that's why it is sometimes good to output the original error message). If you add this in line 110, the folder deletes successfully:
Dir.entries(matPath).each{|f| file = File.join(matPath, f) next unless File.file?(file) File.delete(file) } Dir.rmdir(matPath)
-
Hi Aerilius, thanks for the tip.
I modified the block to include the original error message. I also added your corrections, but the problem (in my PC) is that in a folder with non-ASCII chars, I can't even create the temporary mats subfolder. -
Ok is an older thread however this is what i need however i would have a given name of material for the texture and don´t touch material this have textures.
the plugin give the noname Material Name and Texture Name
i would have this: Material Name and Texture Name (both the same)
this Material have a Texture
the Plugin change the name of the material, this i doesn´t want
Advertisement