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

    Loading PNG Textures in Ruby plugin and SketchUp freezes

    Scheduled Pinned Locked Moved Developers' Forum
    9 Posts 5 Posters 319 Views 5 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
      cstockman
      last edited by

      I have a Ruby plugin that attempts to load textures from a directory. The code looks like this:

      #jpgs is an array of filenames (with path included). They are actually pngs mats = [] jpgs.each do |j| name = File.split(j)[1] mat = Sketchup.active_model.materials.add(name) mat.texture = j mat.texture.size = size mats << mat end

      This code consistently freezes after I load 5 (of 20, in the test case) textures. Specifically, it freezes at the resizing step. If I comment out this step, it will get through 8 textures before freezing.

      These texture files are pretty small (~ 8kb), and I have plenty of ram (12GB) on my iMac.

      Does anyone have an idea as to what might be happening?

      (Probably unrelated, but I also had a problem with a plugin that froze after I called Sketchup.active_model.active_view.camera.set more than ten times in a row. I got around this by breaking the camera_set transformations into loops of five and putting those into a larger loop. I have no idea why this worked. Sketchup freezing is a mystery to me, and I have a difficult time debugging it).

      Thanks for your time.

      1 Reply Last reply Reply Quote 0
      • Chris FullmerC Offline
        Chris Fullmer
        last edited by

        I moved this topic to the developers forum. Any question about plugin-writing does not belong in the newbie section! πŸ˜„

        Have you tried removing all other plugins just in case one of them is messing with your plugin? Or are you doing this while running some sort of observer in your model?

        Lately you've been tan, suspicious for the winter.
        All my Plugins I've written

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

          There shouldn't be any issues with a longer list...

          Presumably 'size' [in inches] is preset in earlier code that you haven't shown us ?
          Otherwise you'd be trying to set it to 'nil' ! It defaults to 10" anyway ?
          πŸ˜•

          I already have a tool quite like this, which works fine [without texture resize]...

          Incidentally, if you want each new material to be named after its texture, instead of using
          name = File.split(j)[1]
          try
          name = File.basename(j, ".*")
          πŸ˜•
          So, if the full path were 'c:/users/me/desktop/images/brick.png'
          your 'split' method returns 'brick.png'
          whereas mine gives 'brick', because the extension is auto-stripped πŸ˜‰

          TIG

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

            There shouldn't be any issues with a longer list...

            Presumably 'size' [in inches - say size=100] is preset in earlier code that you haven't shown us ?
            Otherwise you'd be trying to set it to 'nil' ! It defaults to 10" anyway ?
            πŸ˜•
            Do you mean to set the texture's size to match the image ?
            then you might think to use:
            mat.texture.size = [mat.texture.width, mat.texture.height]
            which is somewhat circular ?
            texture.image_width and texture.image_height are in pixels, you could use those *factor to make them into inch values instead ?

            I already have a tool quite like this, which works fine [without texture resize]...

            Incidentally, if you want each new material to be named after its texture, instead of using
            name = File.split(j)[1]
            try
            name = File.basename(j, ".*")
            πŸ˜•
            So, if the full path were 'c:/users/me/desktop/images/brick.png'
            your 'split' method returns 'brick.png'
            whereas mine gives 'brick', because the extension is auto-stripped πŸ˜‰

            TIG

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

              Thanks for the replies.

              Chris, thanks for moving the post to the Developer forum. This is my first post.

              TIG, size is set to 35 elsewhere; I was trying to just simplify the code. Thanks for the tip on basename. I'm somewhat new to Ruby.

              Some interesting developments:

              The script seems to work on a SketchUp installation on Snow Leopard. I reinstalled SketchUp on my Lion machine, and I was able to get the script to work once using a different directory of textures, but now it's crashing every time again (not freezing this time, just crashing). I'll continue to investigate and post findings.

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

                Could be the JPEG itself. I've had some models that acted strange because of they way the JPEG was created.

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

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

                  If the image files themselves might be suspect try it with half of them removed from the folder, then swap them around until you get fails, narrow it down to the rogues and then look at the culprit[s] in an image editor...

                  TIG

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

                    I still haven't isolated the problem. The script works fine on my Snow Leopard laptop but doesn't work on my Lion machine. I've tried different models, different sets of images, etc... It will work sometimes on Lion, but eventually it will crash if I try to more directories of textures (it seems to crash around 20 textures). Since it works fine on Snow Leopard, and this is just a personal script, I'm just going to stick with that for now. (I've also noticed that other, heavy 2D exporting scripts seem to do better on Snow Leopard). Thanks for all of your help.

                    1 Reply Last reply Reply Quote 0
                    • J Offline
                      JGA
                      last edited by

                      I've had problems when exporting PNG files from Corel Photo-Paint & importing them into SKUP. I found that I had to re-save the image files in IrfanView before they would play ball.

                      Regards,
                      JGA

                      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