sketchucation logo sketchucation
    • Login
    1. Home
    2. Ken007
    ℹ️ Licensed Extensions | FredoBatch, ElevationProfile, FredoSketch, LayOps, MatSim and Pic2Shape will require license from Sept 1st More Info
    K
    Offline
    • Profile
    • Following 0
    • Followers 0
    • Topics 1
    • Posts 5
    • Groups 1

    Ken007

    @Ken007

    10
    Reputation
    1
    Profile views
    5
    Posts
    0
    Followers
    0
    Following
    Joined
    Last Online

    Ken007 Unfollow Follow
    registered-users

    Latest posts made by Ken007

    • RE: Sketchup8 Geo-location linking to a database via rubyscript

      @tig said:

      Rather than trying to learn how to read binary XLS files [very complex to do compared to parsing a text format] can I suggest you simply do a save_as on the XLS file as a CSV...
      You then have a readily readbale file containing lines saying:
      Model,Lat,Long,Status
      Using:

      csv = 'path_to_csv'
      > IO.readlines(csv).each{|line| ### read the file line by line
      >   line.chomp! ### removes \n
      >   next if line.empty? ### empty lines are not used
      >   next if line=~/^[#]/ ### starts with '#' so it is ignored - e.g. the header
      >   model,lat,long,status = line.split(',')
      >   ### now you have the model/lat/long/status as strings
      >   ### perhaps use model = model+'.skp' ??
      >   ### convert the lat/long to float using lat=lat.to_f etc...
      >   ### ..............
      >   ### do your processing on these values... 
      >   ### then the next line is ready...
      >   ### ..............
      > }#end of the block
      

      There are many good sources of Ruby look in the Developer's section - Dan has links off to many... leike this http://www.ruby-doc.org/docs/ProgrammingRuby/html/builtins.html

      Thanks TIG! your idea worked wonders!.. The code I've written is a little shabby at the moment but it works just fine. I'll sort it out and then post it here as soon as possible in case someone needs it. Thanks once again!

      posted in Google Earth
      K
      Ken007
    • RE: Import CSV to extract values

      @tig said:

      Ken... I've given you an example in the 'parallel thread' that you started.

      Yep, got that TIG. Thanks..and sorry for repeating the post.

      posted in Developers' Forum
      K
      Ken007
    • RE: Sketchup8 Geo-location linking to a database via rubyscript

      @tig said:

      Data in a readable/writable text-based file format [for example CSV or TSV files] is readily parsed in Ruby using IO..., File.open... etc...
      There are many examples of doing that, e.g. tools that import X,Y,Z values as cpoints from CSV... do a search for those - I have made some...
      Unfortunately Excel files [XLS] are only readable/writable on a PC and need to use a .so link... again there have been some threads on that - it is much more complicated than using a simple format but I have written bespoke XLS read/write tools, but none quite like you envisage...

      Hmm...first of all, thanks for a such a prompt response TIG.
      ok, now I have a few questions:

      1. This might seem like a stupid/juvenile question, but I am new to rubyscript and its applications is sketchup; how do I use the aforementioned IOs like File.open. I did a google search but couldn't end up finding anything that I could understand
      2. Can you give me an example of the XLS read/write tools that you speak of please?
      3. Microsoft Excel has the provision of developer tools if I'm not wrong. In fact I've used VBA in MS excel a couple of times for certain small tasks. Any idea if its possible to generate a CSV file from data in excel. I'm basically trying to create a link between the geo-location tool in sketchup and a database.

      For example, the Excel data reads:
      [pre:2o2zulb1]Model Lat Long Status
      House 15.24566 75.12643 CNF[/pre:2o2zulb1]

      Skechup must read the model name 'Hoose' and open the respective .skp file. Then it must read the 'Latitude and Longitude' and make the required changes in the geo location.
      Now as soon as Sketchup reads 'CNF' (i.e. confirmed) from the database, it must export the 3D model and place it in a default folder (the code I've mentioned in my original post does all that but I need it to be done dynamically from a database)

      posted in Google Earth
      K
      Ken007
    • RE: Import CSV to extract values

      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!

      posted in Developers' Forum
      K
      Ken007
    • Sketchup8 Geo-location linking to a database via rubyscript

      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!

      posted in Google Earth sketchup
      K
      Ken007