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

    Download skp files directly into Sketchup

    Scheduled Pinned Locked Moved Developers' Forum
    14 Posts 7 Posters 3.2k Views 7 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.
    • K Offline
      Kevin Fung
      last edited by

      Hi Guys!

      I am not technical man. I am just trying to develop my own website for my own skp files and let me clients to download the skp files.

      I am looking for the code which allows the download skp files directly into sketchup software.

      It may be easy one. But, it helps me a lot for developing the new website applications to my clients.

      I found out the code from 3D warehouse for downloading files directly into sketchup software as follows :

      <a class="download" href="/3dwarehouse/download?mid=bf122b6e466158b1a9184fc3cc92a412&rtyp=s7&fn=Porte+de+garage+dynamique&ctyp=other&ts=1367319137000" onclick="_G3DWH_Utils.showHideElement('downloadChoices', false)">下載547 kb</a>

      Is this code ( onclick="_G3DWH_Utils.showHideElement('downloadChoices', false)" ) that I need for downloading files directly into sketchup software?
      Or is there any new code for doing the same purpose?

      Thanks a lot in advance.

      Kevin Fung
      ( Hong Kong )

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

        Hi,
        this is not the code that downloads model into SketchUp. This is the code that you see in a normal browser. No browser allows websites to access your local programs or modify your SketchUp model.
        Inside SketchUp, Trimble uses a different version of 3D Warehouse and modifies the browser to listen to certain commands ("action_call_back" with skp protocol handler).

        You don't have access to this because it works only in the 3D Warehouse window. You could develop a SketchUp plugin and replicate the same function, but SketchUp's API does not provide a method for downloading files, so you would even have to program a downloader.

        Much easier is it to tell you clients to drag & drop the link (url) of a model into SketchUp. SketchUp can load dragged files as well as load files from the web. You could use the html5 drag&drop API so that you don't need to show the url to the model (but an image whose drag&drop data is a url).

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

          You use
          Sketchup.active_model.definitions.load_from_url(the_full_url_path_to_the_SKP, load_handler)
          etc... with a predefined separate LoadHandler class called etc...
          Tip: the url_path MUST either end in '.SKP' or if it is initially as 'php', then resolve to a path that ends in '.SKP'...
          It is NOT as simple as loading a SKP from the same PC, BUT it has been done many times by others, so it is quite possible.
          Note also, that this method simply adds the SKP to the model's component-definitions, so if you want to place an instance of it in the model, or save it as a separate SKP into a folder on the user's PC, then you'll need some extra code to do this...
          http://sketchup.com/intl/en/developer/docs/ourdoc/definitionlist.php#load_from_url

          TIG

          1 Reply Last reply Reply Quote 0
          • D Offline
            driven
            last edited by

            @Tig

            I tried the file you linked to to download from my Dropbox Public Folder, but I get this messageit is a valid component from the sampler in SU.
            and yes it ends in Grid.skp

            to get it to run at all, I changed line #32,
            any ideas?

             class LoadHandler
            
               def onPercentChange(p)
                 Sketchup;;set_status_text("LOADING;    " + p.to_i.to_s + "%")
               end
            
               def cancelled?
                 # You could, for example, show a messagebox after X seconds asking if the
                 # user wants to cancel the download. If this method returns true, then
                 # the download cancels.
                 return false
               end
            
               def onSuccess
                 Sketchup;;set_status_text('')
               end
            
               def onFailure(error_message)
                 # A real implementation would probably not use a global variable,
                 # but this demonstrates storing any error we receive.
                 $last_error = error_message
                 Sketchup;;set_status_text('')
               end
            
             end
            
             # Replace this with a real URL...
             url = "https://dl.dropboxusercontent.com/u/25114184/Dynamic Components Training/Tile Grid.skp"
             load_handler = LoadHandler.new
             Sketchup.active_model.definitions.load_from_url url, load_handler
            
             if $last_error == nil
               last_def_id = Sketchup.active_model.definitions.count - 1
               loaded_definition = Sketchup.active_model.definitions[last_def_id]
             else
               UI.messagebox("Error; " + $last_error.to_s)
             end
            

            it's an active link if you want to test against it...
            john

            learn from the mistakes of others, you may not live long enough to make them all yourself...

            1 Reply Last reply Reply Quote 0
            • M Offline
              mwm5053
              last edited by

              So a quick question to TIG. Why couldn't you save a model as a component and use component browser to import like you would with say furniture or cabinets?

              2011 iMac
              SU 2015 Pro, 2017 Make
              V2 Twilight
              macOS Sierra 10.12.5

              1 Reply Last reply Reply Quote 0
              • S Offline
                slbaumgartner
                last edited by

                @driven said:

                @Tig

                I tried the file you linked to to download from my Dropbox Public Folder, but I get this message[attachment=0:2x8b9f01]<!-- ia0 -->2013-06-19 06.51.51 pm.png<!-- ia0 -->[/attachment:2x8b9f01]
                and yes it ends in Grid.skp

                to get it to run at all, I changed line #32,
                any ideas?

                 class LoadHandler
                > 
                >    def onPercentChange(p)
                >      Sketchup;;set_status_text("LOADING;    " + p.to_i.to_s + "%")
                >    end
                > 
                >    def cancelled?
                >      # You could, for example, show a messagebox after X seconds asking if the
                >      # user wants to cancel the download. If this method returns true, then
                >      # the download cancels.
                >      return false
                >    end
                > 
                >    def onSuccess
                >      Sketchup;;set_status_text('')
                >    end
                > 
                >    def onFailure(error_message)
                >      # A real implementation would probably not use a global variable,
                >      # but this demonstrates storing any error we receive.
                >      $last_error = error_message
                >      Sketchup;;set_status_text('')
                >    end
                > 
                >  end
                > 
                >  # Replace this with a real URL...
                >  url = "https://dl.dropboxusercontent.com/u/25114184/Dynamic Components Training/Tile Grid.skp"
                >  load_handler = LoadHandler.new
                >  Sketchup.active_model.definitions.load_from_url url, load_handler
                > 
                >  if $last_error == nil
                >    last_def_id = Sketchup.active_model.definitions.count - 1
                >    loaded_definition = Sketchup.active_model.definitions[last_def_id]
                >  else
                >    UI.messagebox("Error; " + $last_error.to_s)
                >  end
                

                it's an active link if you want to test against it...
                john

                @john, the above ran ok for me - added the Tile Grid to the components in my model and did not raise any errors. Puzzling...why not for you?

                Steve

                1 Reply Last reply Reply Quote 0
                • D Offline
                  driven
                  last edited by

                  @slbaumgartner said:

                  Puzzling...why not for you?

                  not sure, do you have a dropbox to check if there's a short circuit trying to use your own???

                  does that even make sense?

                  john

                  learn from the mistakes of others, you may not live long enough to make them all yourself...

                  1 Reply Last reply Reply Quote 0
                  • S Offline
                    slbaumgartner
                    last edited by

                    @driven said:

                    @slbaumgartner said:

                    Puzzling...why not for you?

                    not sure, do you have a dropbox to check if there's a short circuit trying to use your own???

                    does that even make sense?

                    john

                    I don't have any experience with dropbox, so it's all guessing on my part. But it doesn't make sense to me that you would be blocked from accessing your own dropbox. Has that happened to you in any other context? Your code worked for me in both SU 8 and SU 2013 Make.

                    Steve

                    1 Reply Last reply Reply Quote 0
                    • K Offline
                      Kevin Fung
                      last edited by

                      Thanks Aerilius and TIG for your prompt reply.

                      I would prefer to try the HTML5 drag and drop API.

                      If there is any successful, I would post the photo for your reference.

                      Thanks.

                      Kevin Fung
                      (Hong Kong)

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

                        I used HTML5 Drag and Drop API for my installer utility: http://sketchucation.com/forums/viewtopic.php?t=51330

                        But I found that it didn't work under OSX because the WebDialog hides when the parent SketchUp window loses focus.

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

                        1 Reply Last reply Reply Quote 0
                        • S Offline
                          slbaumgartner
                          last edited by

                          @thomthom said:

                          I used HTML5 Drag and Drop API for my installer utility: http://sketchucation.com/forums/viewtopic.php?t=51330

                          But I found that it didn't work under OSX because the WebDialog hides when the parent SketchUp window loses focus.

                          Yes, that is one of the frustrating aspects of OSX. When the app loses focus, its secondary windows all hide - they aren't merely invisible behind other windows, they actually cease to be displayed. If the app is set up for drag and drop, the main window and its secondary windows will pop back to the top when you drag onto the main window, at which point you can drag onto the secondary window. But, it does not appear that SU is set up for drag and drop, even as of 2013 - at least I can't get it to work.

                          Steve

                          1 Reply Last reply Reply Quote 0
                          • D Offline
                            driven
                            last edited by

                            @slbaumgartner said:

                            the main window and its secondary windows will pop back to the top when you drag onto the main window, at which point you can drag onto the secondary window. But, it does not appear that SU is set up for drag and drop, even as of 2013 - at least I can't get it to work.

                            this much works I use top left 'hot corner' to get back to SU, it's the actual loading that fails and even after disabling the virtual store messages I get

                             Creating Drop Zone Window...
                            >> Dialog Ready
                            [Callback;;Install_Ended]
                            > Params; ""
                            > Checking installed stack; 0
                            > Clearing installed stack...
                            > Cleared!
                            

                            learn from the mistakes of others, you may not live long enough to make them all yourself...

                            1 Reply Last reply Reply Quote 0
                            • D Offline
                              driven
                              last edited by

                              @slbaumgartner said:

                              @driven said:

                              @john, the above ran ok for me - added the Tile Grid to the components in my model and did not raise any errors. Puzzling...why not for you?

                              BTW. this is working for me now as well, I reset some of my outgoing request [Little Snitch] Filters, so I can download directly into SU from my 'dropbox' or iCloud, I might try Google drive next...
                              john

                              learn from the mistakes of others, you may not live long enough to make them all yourself...

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

                                Yea, I also found awkward ways to drop files to the WebDialog - but it's so awkward that I won't bother making a public release for it. It'll just be confusing - and defeat the purpose of trying to make an easy drag and drop feature...

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

                                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