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

    Export images to saved file location with file name

    Scheduled Pinned Locked Moved Developers' Forum
    15 Posts 4 Posters 459 Views 4 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.
    • CadFatherC Offline
      CadFather
      last edited by

      this does produce an image but the name is empty - only '.png'

      title = model.title
      myimage=File.join(dir2, title+'.png')
      view.write_image( myimage, 600, 600, true )

      anyway at least i know i'm on a better track now.

      1 Reply Last reply Reply Quote 0
      • A Offline
        Aerilius
        last edited by

        Did that happen in a new (unsaved) file? Then the model has no file name and the title is empty. You would then need to provide a fallback name like:
        title = model.title title = "untitled" if title.empty?
        Eventually we would hve to check if such a file already exists and iterate until the file name is unique.

        1 Reply Last reply Reply Quote 0
        • CadFatherC Offline
          CadFather
          last edited by

          yes, it already has a name, this is what i'm running after making a directory and saving the file..

          
          dir=Dir.mkdr(File.join(model_dirname, 'TEST'))
          	
          model.save(File.join(dir, File.basename(skp)))
          			
          model_filename = File.basename(model.path)
          
          imager=File.join(dir, model_filename+'.png')
          
          view.write_image( imager, 600, 600, true )
          
          
          1 Reply Last reply Reply Quote 0
          • TIGT Offline
            TIG Moderator
            last edited by

            BUT model.title and model.path etc are empty [''] UNLESS it's been saved.
            Using the model.save() does NOT change the current model, it just saves a copy of it as it is...
            So suspect you haven't saved the base SKP.
            therefore the save you are doing is '.png', and the folder is probably not set wither
            Therefore you need to do something to establish a 'title' some other way...

            Tip, to see what is going on run with the Ruby console open and put a temporary ' p' in front of each reference you are setting to see what you get - e.g. p title=model.title should return "mymodelname" NOT "" - which shows it's not been saved...

            TIG

            1 Reply Last reply Reply Quote 0
            • CadFatherC Offline
              CadFather
              last edited by

              can't i just save it with the name of the copy then?

              1 Reply Last reply Reply Quote 0
              • A Offline
                Aerilius
                last edited by

                If you know that the file is saved to File.join(dir, File.basename(skp))),
                you can also write the image to File.join(dir, File.basename(skp, ".skp")+".png"))

                File.basename understands the second argument as an extension and strips it off; if the extension was unknown, we could obtain it with File.extname ("a_model.skp") or a regular expression.

                1 Reply Last reply Reply Quote 0
                • CadFatherC Offline
                  CadFather
                  last edited by

                  friends, let me say.. you are not from this planet...! (..but i'm very glad you landed!) 💚

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

                    I recommend a minor adjustment
                    File.join(dir, File.basename(skp, **".*"**)+".png"))

                    • it is safer, because a file ending with '.SKP' would fail == not matching ".skp"...

                    TIG

                    1 Reply Last reply Reply Quote 0
                    • CadFatherC Offline
                      CadFather
                      last edited by

                      ok, TIG, i'll see what i can do. 🤓

                      this is what i'm getting towards: (and of course TIG has already done the biggest part)

                      i'll call it a batcher:

                      starts and asks for some options:

                      views to make = top, front, side, hi angle
                      delete all materials from model entities - on/off
                      shadows - on/off
                      fov value
                      layer name (to put the file contents into it)

                      when it starts, it opens a folder to choose and processes all files in it.

                      process does:

                      delete all guides,
                      purge all unused entities,
                      create a layer (named from previous options) and move everything in it,
                      set a custom style
                      go to the first view (ie. top) and save the model to a subfolder (top),
                      save a transparent png image of the same view and place it in the same subfolder (top),

                      then moves to the next file... 🤢

                      1 Reply Last reply Reply Quote 0
                      • B Offline
                        bauhaustoourhouse
                        last edited by

                        I have run into an issue when I'm working on the same image on two different computers - when exporting the Sketchup image, the Width & Height are locked (when one is edited, the other automatically matches that computer's viewport ratio). I am trying to find a way to export an image with independently filled in Width and Height resolutions. This seems to be the closest Ruby I could find to fixing my issue. Is there any way to modify this to get what I'm looking for? I export so often that I would like to create a button on a new toolbar to keep at the top of the screen, instead of entering the Ruby Console every time. Is there any way to do this?

                        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