What’s New in SketchUp 2014? Better Ruby, for Example!

By now you most probably have heard that SketchUp 2014 has been released. There are quite a few great new-feature overviews and reviews out there and I’ll suggest you look at the ones linked at the end of this post to get up to speed. For now, I just wanted to show you why the Ruby update in SketchUp 2014 is pretty amazing. Look at this image: Flickr photos in SketchUp What is so interesting about the image above? Well – those are images that were loaded from Flickr directly into SketchUp using the now included “net/http” library. Since SU 2014 not only updated Ruby to 2.0 but also included all of the standard libraries, stuff like this is now possible. You can integrate Net functionality much more and create all kinds of interesting mash-ups. To replicate what I did above, copy the following code snippet and either paste it into the Ruby Console (it now accepts multiline Ruby!) or into my Ruby Code Editor. Here’s also an interactive version on Sketchfab:

Code Snippet:

# This script loads Flickr's RSS feed and exatrcts images from it into the SU model

mod = Sketchup.active_model # Open model
ent = mod.entities # All entities in model
sel = mod.selection # Current selection

require 'net/http'

tag = 'architecture'
rad = 1000
n = 20
fn = 'temp.jpg'

# Use a timer
t = Time.now

# Get all images in Flickr's RSS feed
uri = URI("http://api.flickr.com/services/feeds/photos_public.gne?tags=#{tag}")
cnt = Net::HTTP.get(uri)
p "RSS feed loaded - at #{Time.now - t}s"

# Process feed
collect = URI.extract(cnt, "http")
collect.reject! {|i| !i.include? "_b.jpg" }
# Convert to lower quality before downloading
collect.map {|s| s.gsub!('_b.jpg', '_q.jpg')}

# Insert the images into the model
(0..n-1).each { |i|
    uri = URI(collect[i])
    Net::HTTP.start(uri.host) { |http| 
       resp = http.get(uri.path)
          open(fn, 'wb') { |file|
             file.write(resp.body)
          }
    }
    p "Loaded #{uri} - at #{Time.now - t}s"    
    image = ent.add_image fn, [-150,-150,0] , 300
    pos = [Math::sin((i * 360 / n).degrees)*rad, Math::cos((i * 360 / n).degrees)*rad, 0]
    t1 = Geom::Transformation.translation pos
    t2 = Geom::Transformation.new( image.bounds.center, [1,0,0],  90.degrees)
    t3 = Geom::Transformation.new( image.bounds.center, [0,1,0],  -(i * 360 / n).degrees)
    image.transform! t1*t2*t3
}
p "Done! - at #{Time.now - t}s"

SketchUp 2014 Links:

  • tom hopper

    Alex,
    My question is:
    When say designing something three dimensionally in form and then making it a “component”, does it not glue to another say identical component if you place it flush, touching, tangential like one plane touching another plane?
    I an somewhat frustrated with this sticky feature of Sketchup and want to move one component in relation to another but not effect the other in this moving or editing one.Sketchup always seems to distort the touching part and I don’t want that but I want the faces to touch.
    Does making things labeled “components” solve and eliminate this gluing effect? I want to move one component without moving parts of another and yet have faces touching.
    Thank you, Architect a wee bit old at this……….

    -Tom Hopper at tphopper tphopper@gmail.com

    • Hi Tom,

      That is what happens when you don’t create groups or components. I would advise that as soon as you model something (e.g. a brick), that you turn it into a group or a component. Then move on to the next piece of geometry. That way nothing sticks to other geometry. Rule for components: If you need many copies of the same thing, create a component, otherwise a group is fine.

      Hope this helps.