Assigning Textures
-
Hi,
I'm trying to assign textures (the standard ones), but I'm having a bit of trouble as it just shows up as black faces and was hoping for some direction...In the initialization stage of my class I create a new material as follows;
@face_material = Sketchup.active_model.materials.add "face_material"
I receive my path from my web dialog with this bit of code
dialog.add_action_callback("face_material") do |dlg, msg| filename = msg if File.exists?(filename) @face_material.texture = filename puts @face_material.texture end end
Here is the output of the 'puts' statement so I can tell I'm getting the path ok.
@unknownuser said:
C:\Program Files (x86)\SketchUp\SketchUp 2013\Materials\Translucent\Translucent_Glass_Tinted.skm
If I check the face material texture I get nil back so I'm guessing this means that the assignment failed. Is there something about needing say no spaces in the name or needing to double backslash \ the path?
I create the face and assign the front and back sides with the material
face = @geodesic.entities.add_face @primitive_points[p_num - order], @primitive_points[p_num - order - 1], @primitive_points[p_num] face.material = @face_material face.back_material = @face_material
This face turns out to be black instead of what I picked. I've read a few articles on the subject, but can't find my mistake.
Sincerely, Sketchy...
-
(1) Slashes
Ruby uses forward slashes. Backslashes are used as escape sequences.
Example "\t" is a TAB character, "\n" is a newline.Either escape (double backslash, or replace with forward slash.)
filepath = msg.gsub('\','/')
(2) Scope
A block delimited with
do
...end
may has a different scope then a block delimited with{
...}
. Generally the curly braced block can see outer variables in more cases than thedo
...end
block can. So try curlies. -
Thanks a lot for the feedback Dan
-
Hmmm,
I included your advice and it still does not work. I also tried hardcoding a path (without spaces in case that was it) and it wasn't. The .nil check below is failingdialog.add_action_callback("face_material") { |dlg, msg| filepath = msg if File.exists?(filepath) puts filepath filepath = msg.gsub('\\','/') puts filepath @face_material.texture = "C;/a.skm" if (@face_material.texture.nil?) puts "No worky..." end puts @face_material.texture end }
Any ideas as to why I can't assign a path...?
Reference posts....
http://sketchucation.com/forums/viewtopic.php?f=180&t=3100
http://www.thomthom.net/thoughts/2012/03/the-secrets-of-sketchups-materials/Update:
https://groups.google.com/forum/#!msg/sketchupruby/0St9qMVnro4/TtcTfhOsbHoJ
Apparently you can't add .skm's directly...
http://sketchucation.com/forums/viewtopic.php?f=180&t=32643Now to find SKMTools... http://sketchucation.com/forums/viewtopic.php?f=180&t=33079
Ok, SKMTools installed....now windows permissions issues in the plug-in directory that SKM needs for temporary writing..... fun night
Most frustrating... Sketchy
-
maybe because Dan suggested you do a gsub BEFORE if File.exists?
Note: You can also edit in place gsub!(etc..)
-
Thanks Jolran,
You're right that was a short coming in logic, but it was making it into the 'if' anyway. The issue is you can only use .texture to load images, not skm's. TIG wrote a module to extract a .skm and return the texture within so I'm currently integrating that library.
Advertisement