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!
    🫛 Lightbeans Update | Metallic and Roughness auto-applied in SketchUp 2025+ Download

    Script to automate Texturing a surface -> Render

    Scheduled Pinned Locked Moved Developers' Forum
    2 Posts 1 Posters 490 Views 1 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.
    • C Offline
      Carpeggio
      last edited by

      Hey guys,

      New to Ruby and Sketchup. But making do with what resources I find.


      # Ruby Script for Retexturing and Rendering Scene from source directory images.
      # Have top of board game/material selected (Just the top face) before running script.
      
      inputDir = Dir.open "C;/Users/XXXX/Downloads/Notes And Things/Photo_Illustrator_OddandEnds/SketchUp/Gameboard Modeling/TopCovers(Bulk)"
      
      i = 1
      
      inputDir.each do |file|
      	# Process through Sketchup.
      	# Get a handle to the selection set.
      	currentMaterial = Sketchup.active_model.materials.current
      	currentMaterial.texture = File.absolute_path file
      	UI.messagebox(file)
      	# Save Render to outputDir.
      	view = Sketchup.active_model.active_view
      	view.write_image "C;/Users/XXX/Downloads/Notes And Things/Photo_Illustrator_OddandEnds/SketchUp/Gameboard Modeling/Renders/BulkOutput/testImage#{i}.png"
      	i = i + 1
      end
      

      It runs, and produces output write_images. However, the material does not update. I cannot for the life of me figure out why.

      Hoping to see these images get placed onto the model;
      http://i.imgur.com/jXTMik5.png

      but in the output I only see the original texture;
      http://i.imgur.com/XNxZpWt.png

      The script requires that you have the material with the texture selected because of the line 'currentMaterial = Sketchup.active_model.materials.current' selects that.

      In 'currentMaterial.texture = File.absolute_path file' I was hoping to find some syntactical error that would lead to nothing being applied, but I'm not seeing anything.

      I'm taking screenshots right now with view.write_image just for proof of concept, but hopefully I'll upgrade that to one of two things;

      Create a scene per texture, then Batch Render with Vray after all the textures have been put into a respective scene. OR... Render between retextures. I'm not sure which can work.

      1 Reply Last reply Reply Quote 0
      • C Offline
        Carpeggio
        last edited by

        Here's what my input/output folders look like after the script: http://i.imgur.com/9yTBr90.png

        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