• Login
sketchucation logo sketchucation
  • Login
⚠️ Libfredo 15.4b | Minor release with bugfixes and improvements Update

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.
  • C Offline
    CadFather
    last edited by 21 Apr 2013, 12:54

    hope it's making any 'copy/paste' sense

    what i'm trying to do is:

    1 - get a 'front' view, save the file into a folder called 'front' then export an image in the same folder ('front')

    2 - get a 'top' view, save the file to a folder called 'top' then export an image in the same folder ('top').

    and so on for any other view...

    now the saving to a new folder for each view has been basically done by TIG, but i want to add export the relative image too and i can't seem to set the path to be the same as the new saved file.

    am i too far off with this skillful code?

    
    model = Sketchup.active_model
    model_filename = File.basename(model.path)  #  i think i'm find out the models path
    view = model.active_view
    view.write_image( File.join(model_filename),600,600,true )
    
    

    thanks...

    1 Reply Last reply Reply Quote 0
    • T Offline
      TIG Moderator
      last edited by 21 Apr 2013, 14:42

      model.path is the path to the model's SKP, OR '' if the models has never been saved.
      model_filename = File.basename(model.path) is the name of the SKP 'xxx.skp'
      model_dirname = File.dirname(model.path) is the name of the folder containing the SKP 'C:/...../myskpsfolder/'
      The code I've given you previously shows how to make a new folder in that newfolder=Dir.mkdr(File.join(model_dirname, 'mynewfolder'))
      You meed to specify the image-name too...
      myimage=File.join(newfolder, 'myimagename.png') view.write_image( myimage, 600, 600, true )
      πŸ˜•

      TIG

      1 Reply Last reply Reply Quote 0
      • C Offline
        CadFather
        last edited by 21 Apr 2013, 15:52

        thanks - i think i forgot to mention the image name has to be the same as the sketchup file just saved

        that's why i was trying: model_filename = File.basename(model.path)

        (i thought i was getting the name of the file in that particular folder)

        1 Reply Last reply Reply Quote 0
        • T Offline
          TIG Moderator
          last edited by 21 Apr 2013, 15:56

          To get the 'root' of the model name you can use
          title = model.title
          then to make the full image path...
          myimage=File.join(newfolder, title+'.png')

          TIG

          1 Reply Last reply Reply Quote 0
          • C Offline
            CadFather
            last edited by 21 Apr 2013, 16:01

            ok TIG, thanks, i think i understand it - i shall look into it (won't take more than a few months) πŸ‘ πŸ˜„

            1 Reply Last reply Reply Quote 0
            • C Offline
              CadFather
              last edited by 21 Apr 2013, 16:34

              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 21 Apr 2013, 16:39

                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
                • C Offline
                  CadFather
                  last edited by 21 Apr 2013, 17:06

                  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
                  • T Offline
                    TIG Moderator
                    last edited by 21 Apr 2013, 18:40

                    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
                    • C Offline
                      CadFather
                      last edited by 21 Apr 2013, 20:44

                      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 21 Apr 2013, 21:27

                        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
                        • C Offline
                          CadFather
                          last edited by 21 Apr 2013, 23:22

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

                          1 Reply Last reply Reply Quote 0
                          • T Offline
                            TIG Moderator
                            last edited by 22 Apr 2013, 08:52

                            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
                            • C Offline
                              CadFather
                              last edited by 22 Apr 2013, 12:12

                              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 1 Jul 2013, 17:00

                                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