Download skp files directly into Sketchup
-
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 ) -
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).
-
You use
Sketchup.active_model.definitions.load_from_url(the_full_url_path_to_the_SKP, load_handler)
etc... with a predefined separateLoadHandler
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 -
I tried the file you linked to to download from my Dropbox Public Folder, but I get this message
and yes it ends inGrid.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 -
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?
-
@driven said:
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 inGrid.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
-
@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
-
@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
-
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) -
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.
-
@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
-
@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.
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!
-
@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 -
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...
Advertisement