sketchucation logo sketchucation
    • Login
    🤑 SketchPlus 1.3 | 44 Tools for $15 until June 20th Buy Now

    Modifying Texture objects?

    Scheduled Pinned Locked Moved Developers' Forum
    4 Posts 2 Posters 412 Views 2 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.
    • thomthomT Offline
      thomthom
      last edited by

      I had a model which was dead slow when I had V-Ray for SketchUp installed. Any editing operation I did would cause Sketchup to become unresponsive, yet consume no CPU or extra RAM.

      I managed to track it down to two textures in the model which refered to an old network path when the model was originally created. Began with \ARC3024... It appears that VfSU will often try to access this location causing a SU freeze until it times out.

      When I removed these textures the model was responsive as anything.
      But I wanted to keep the textures which where mapped to the model, so I figured I'd create a script that removed the network path from the file name.

      
      Sketchup.active_model.materials.each { |m|
      	if m.texture != nil
      		t = m.texture
      		if t.filename[0,2] == '\\\\'
      			puts 'Found network path. Trying to unlink...'
      			puts m.name + ' - ' + m.texture.filename
      			
      			filename = t.filename.split('\\').last
      			
      			result = (m.texture = filename)
      			puts 'Result; ' + result
      		end
      	end
      }
      
      

      This worked fine, ...nearly.
      Problem occurs when materials are set to a custom tile size. For example, 2000x1500mm. When I run the script, the modified textures will afterwards have tile size of 254x254mm. And that ruins the mapping.

      The thing is, if I do this manually, from the SketchUp Material editor, selects a new image with same proportions, the tile size remains the same.

      But from Ruby I can't seem to edit the Texture object at all. The only way I can replace the file name is by doing material.texture = 'filename' instead of material.texture.filename = 'filename' which I initially tried to do.

      So; is it really not possible to edit Texture objects?
      Is it not possible to set the tile size for a material?

      Thomas Thomassen — SketchUp Monkey & Coding addict
      List of my plugins and link to the CookieWare fund

      1 Reply Last reply Reply Quote 0
      • R Offline
        RickW
        last edited by

        Both are possible. For the size issue, store the width and height prior to changing the file location, then after the change, set
        texture.size = [width,height]

        For the location info, that one gets a little more tricky. You may need to write the material to a location, then pull it back in from that location.

        RickW
        [www.smustard.com](http://www.smustard.com)

        1 Reply Last reply Reply Quote 0
        • thomthomT Offline
          thomthom
          last edited by

          Ah. I didn't use that at first as the manual only demonstrated one value and saying that the value would be applied to the width and height to ensure the texture was proportional. But what if the original texture tiling wasn't proportional?

          Btu when I tried what you typed, an array, it worked perfectly!

          I wish that the wiki-style documentation would allow for wiki editing so these kind of things could be updated.

          Setting the location was no problem. The script works perfectly now that I know how to set the tiling sizes. Thanks Rick!

          Thomas Thomassen — SketchUp Monkey & Coding addict
          List of my plugins and link to the CookieWare fund

          1 Reply Last reply Reply Quote 0
          • thomthomT Offline
            thomthom
            last edited by

            Turns out, I think I need to write the texture to disk. The only reason it seemed to work to just take the original filename with the path and assign just the filename was because SU's last file dialog location pointed to where the original texture was.

            TextureWriter object is the only one that allows me to save out a texture? It doesn't take a Material object as an argument, so would I have to create a temporary object, like a group, assign it the material, export using TextureWriter, then delete dummy object? ...seems messy to me... any better solutions?

            Thomas Thomassen — SketchUp Monkey & Coding addict
            List of my plugins and link to the CookieWare fund

            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