sketchucation logo sketchucation
    • Login
    ℹ️ Licensed Extensions | FredoBatch, ElevationProfile, FredoSketch, LayOps, MatSim and Pic2Shape will require license from Sept 1st More Info

    Batch replace all textures in model with in one script?

    Scheduled Pinned Locked Moved Extensions & Applications Discussions
    extensions
    6 Posts 2 Posters 4.7k 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.
    • P Offline
      p_hennessey
      last edited by

      I'm hoping one of you fine folks is able or willing to advise me on a SketchUp script that I am convinced would be extremely helpful in lots of people's workflows.

      Let's say I have applied a series of unique artworks to a model. Let's say I have 20 unique JPG artworks with 20 unique filenames placed in my model. That would amount to a list of files (artwork1.jpg, artwork2.jpg, artwork3.jpg...etc).

      Now... let's say that I have updated JPGs -- the same exact list, but the artwork has been modified in some way, and I need to update my model with each of them.

      Currently, the only way to do this is to painstakingly replace each and every texture instance one by one in the material editor.

      SURELY THERE IS A BETTER WAY??

      Link Preview Image
      Batch create materials from directory of files

      Hello, World! This is my first attempt at Ruby for SketchUp. I have extensive experience creating similar tools in Rhino and 3dsMax and decent experience with SketchUp. Just zero knowledge of Ruby. I would like to loop…

      favicon

      SketchUp Community (forums.sketchup.com)

      Looks like this person was on to something. Is there anyone here who could help me rewrite this Ruby script (I'm new to Ruby, so bear with me) in such a way that we could batch replace every texture in the model with its corresponding JPG? In other words, a single script that would look in a specific folder, and replace any texture in my material library with the JPG in the folder whose name matches that texture?

      I refuse to believe this is impossible. Can anyone help?

      1 Reply Last reply Reply Quote 0
      • TIGT Offline
        TIG Moderator
        last edited by

        Let's assume the model.materials are 'inspected' and only those with associated textures are put into a 'list' - let's call that - mats
        and now we process that...
        Next. in turn look at each material and get its texture, and its path
        textu = mat.texture filen = textu.filename
        Check the path given in filen against a list of possible jpg names...
        Assemble that list from the contents of some subfolder you've set up and defined...
        There are Ruby tools to compare just the file-names [File.basename etc] and also to allow for non-matching cases etc...
        Assuming that you now have a match, then you have the new file path - filenew
        So use
        mat.texture = filenew
        That material now is assigned the replacement textu[tr] ??

        TIG

        1 Reply Last reply Reply Quote 0
        • P Offline
          p_hennessey
          last edited by

          @tig said:

          Let's assume the model.materials are 'inspected' and only those with associated textures are put into a 'list' - let's call that - mats
          and now we process that...
          Next. in turn look at each material and get its texture, and its path
          textu = mat.texture filen = textu.filename
          Check the path given in filen against a list of possible jpg names...
          Assemble that list from the contents of some subfolder you've set up and defined...
          There are Ruby tools to compare just the file-names [File.basename etc] and also to allow for non-matching cases etc...
          Assuming that you now have a match, then you have the new file path - filenew
          So use
          mat.texture = filenew
          That material now is assigned the replacement textu[tr] ??

          I thought the textures were embedded in the SKP file itself. When textures are placed, they don't appear to live at any particular filepath. That's the part that confuses me about how SketchUp works.

          1 Reply Last reply Reply Quote 0
          • TIGT Offline
            TIG Moderator
            last edited by

            When you make a new material and then give it a texture, the method mat.texture.filename return that texture's file-path, or in the case of an 'orphaned texture' - just its 'image-name' - e.g. from the SKM library where no path is applicable...

            You are muddling materials and textures.

            Just process a few materials and list if they have textures and then the texture's filename...

            TIG

            1 Reply Last reply Reply Quote 0
            • P Offline
              p_hennessey
              last edited by

              @tig said:

              When you make a new material and then give it a texture, the method mat.texture.filename return that texture's file-path, or in the case of an 'orphaned texture' - just its 'image-name' - e.g. from the SKM library where no path is applicable...

              You are muddling materials and textures.

              Just process a few materials and list if they have textures and then the texture's filename...

              Sorry...I don't mean texture as in bump map. I mean literally a JPG image, brought into a model and applied to a surface. What would that be called?

              1 Reply Last reply Reply Quote 0
              • TIGT Offline
                TIG Moderator
                last edited by

                An image used as part of a material is called a 'texture'.
                There's no bump-maps inside SketchUp.
                So any image like a JPG or PNG is called a 'texture' when associated with a SketchUp material...

                TIG

                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