Hey!
I have a problem that's been bothering me for quite a while now. Its like this that I have created a few 3D models in Sketchup 8 (the freely downloadable version) and now I want to geo locate them as per their GPS Co-ordinates (so i'm not looking to go through the usual 'add location button'. Now that thing is, I have written a script for sketchup to open the .skp files that contain the 3D models that I've created and I've linked it to another script that adds the GPS location as well as exports it to the desired location. The problem is that all of this happens through a GUI that the script generates. I want all this to occur directly through a database (for example MS Excel) such that the "name of the model", the "GPS co-ordinates/lat-longs" are taken as an input from the Excel database. The code I've written is as follows: (It is fully functional, though, I'm relatively new to sketchup so dont mind if it's a wee bit shabby)
This is the code that opens the 3D model::
prompts = ["Status"]
defaults = [""]
list = ["House|Garden|Palace|Dog house"]
input = UI.inputbox prompts, defaults, list, "Choose a template"
if input[0].to_s.eql? "Garden"
result = Sketchup.open_file "E;\\GoogleEarth\\FINALFINAL\\NewFolder\\garden.skp"
elsif input[0].to_s.eql? "House"
result = Sketchup.open_file "E;\\GoogleEarth\\FINALFINAL\\NewFolder\\house.skp"
elsif input[0].to_s.eql? "Palace"
result = Sketchup.open_file "E;\\GoogleEarth\\FINALFINAL\\NewFolder\\palace.skp"
elsif input[0].to_s.eql? "Dog house"
result = Sketchup.open_file "E;\\GoogleEarth\\FINALFINAL\\NewFolder\\dog_house.skp"
end
load 'C;\Documents and Settings\91014276\Desktop\untitled(3).rb'
and this is 'untitled(3).rb' that actually geo locates the 3D model and exports it to the desired location::
prompts = ["Latitude", "Longitude", "Location", "Destination Drive"]
defaults = ["", "", "xyz", "E;\\Examples"]
list = ["", "", ""]
input = UI.inputbox prompts, defaults, list, "About the WEC"
model = Sketchup.active_model
# This is the bit that actually sets the geo-location.
shadowinfo = model.shadow_info
shadowinfo["City"] = "Unknown"
shadowinfo["Country"] = "Unknown"
shadowinfo["Latitude"] = input[0].to_f
shadowinfo["Longitude"] = input[1].to_f
georef = model.georeferenced?
key = "GeoReference"
model.set_attribute key, "GeoReferenceNorthAngle", 358.646700673226
model.set_attribute key, "UsesGeoReferencing", true
model.set_attribute key, "Longitude" , input[1].to_f
model.set_attribute key, "Latitude" , input[0].to_f
model.set_attribute key, "ModelTranslationX" , -12901579.2256146
model.set_attribute key, "ModelTranslationY" , -214086056.635273
model.set_attribute key, "ModelHereState", ""
model.set_attribute key, "ModelHereZoom", 19
model.set_attribute key, "ModelTranslationZ" , 0.0
model.set_attribute key, "LocationSource" , "Google Earth"
model.set_attribute key, "ZValueCentered" , 0.0
model.set_attribute key, "TimeStamp", 1296598526
model.set_attribute key, "ModelHereState", ""
model.set_attribute key, "ModelHereZoom", 19
# Export model to kmz file for Google Earth
model.export "#{input[3]}\\ #{input[2]}.kmz", true
result = UI.messagebox "Is that all or would you like to try another?", MB_YESNO
if result == 6 # Yes
load 'C;\Documents and Settings\91014276\Desktop\untitled(5).rb'
elsif result == 7 # No
UI.messagebox ("Alrighty then!")
end
In the above code 'input[0].to_f' and 'input[1].to_f' are the Latitude and Longitude co-ordinates where the model has to be placed.
Im in need of some desperate help here so please...err..help!