sketchucation logo sketchucation
    • Login
    Oops, your profile's looking a bit empty! To help us tailor your experience, please fill in key details like your SketchUp version, skill level, operating system, and more. Update and save your info on your profile page today!
    πŸ›£οΈ Road Profile Builder | Generate roads, curbs and pavements easily Download

    Assigning Textures

    Scheduled Pinned Locked Moved Developers' Forum
    6 Posts 3 Posters 560 Views 3 Watching
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • s_k_e_t_c_h_yS Offline
      s_k_e_t_c_h_y
      last edited by

      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 Reply Last reply Reply Quote 0
      • Dan RathbunD Offline
        Dan Rathbun
        last edited by

        (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 the do ... end block can. So try curlies.

        I'm not here much anymore.

        1 Reply Last reply Reply Quote 0
        • s_k_e_t_c_h_yS Offline
          s_k_e_t_c_h_y
          last edited by

          Thanks a lot for the feedback Dan πŸ˜ƒ

          1 Reply Last reply Reply Quote 0
          • s_k_e_t_c_h_yS Offline
            s_k_e_t_c_h_y
            last edited by

            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 failing

            			dialog.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=32643

            Now 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

            1 Reply Last reply Reply Quote 0
            • jolranJ Offline
              jolran
              last edited by

              maybe because Dan suggested you do a gsub BEFORE if File.exists?

              Note: You can also edit in place gsub!(etc..)

              1 Reply Last reply Reply Quote 0
              • s_k_e_t_c_h_yS Offline
                s_k_e_t_c_h_y
                last edited by

                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.

                1 Reply Last reply Reply Quote 0
                • 1 / 1
                • First post
                  Last post
                Buy SketchPlus
                Buy SUbD
                Buy WrapR
                Buy eBook
                Buy Modelur
                Buy Vertex Tools
                Buy SketchCuisine
                Buy FormFonts

                Advertisement