Developing Importer for .SHP (or SHX) to SketchUp



The unpack() method is being called upon an object that should be a String, but it is nil.

The error is happening specifically, at line 175, in file “spirix_shapefile_importer.rb”,
within method: spirix_shapefile_import_get_database()


Can you provide a link to the data files? Short of that, there’s no way to really guess what’s happening.


Dan, thanks for locating the problem. Unfortunately I know nothing about coding, so I have no idea how to fix it.
Jim, here is a link to the files I am trying to import: (820.0 KB)
the column HN_MAX in the dbf file indicates the height of buildings.



I notice that you’re using SketchUp 8. The import works fine under 2015 & 2016 (the plugin was originally developed under version 8 and then modified to work with 2015 & 2016). I didn’t have a chance to try the plugin under 8 until yesterday, but I get the same error you get, so I don’t think it’s a Mac-specific error. When making it compatible with 2015, I seem to recall a difference in one of the Ruby calls due to the version change in Ruby. Whether it was the file read operation returning a string or not or the array.first statement working differently, I don’t recall. I do seem to recall that @DanRathbun helped me figure this out when going from the previous Ruby version. Maybe he can shed some light on it?

Here’s a sample view of the import of 451 buildings using 2015:

Attached is the model in SketchUp 8 format (the full import was too big to post here): ostend.skp (1.6 MB)


This loop begins at line 170:

        while(name[0] != "\r")
          p_count += 1
          t_off += 32
          name = @@data[t_off,10].unpack('A10').first
          len = @@data[t_off + 16,1].unpack('C').first

Apparently in line 175,…


… results in the index t_off being outside the string, which causes the [] method to return nil.
And of course nil does not have a unpack method.

Either add another condition to the while expression:

while (name[0] != "\r" && t_off+32 < @@data.size-1)

… AND / OR, add a rescue break modifier to line 175, so as to exit the loop if the data extraction fails:

(name = @@data[t_off,10].unpack('A10').first) rescue break


Now I remember! I had originally coded the test as

while(name[0] != 13)

which works under 8 … however it failed under the newer Ruby version, so I changed it to:

while(name[0] != “\r”)

Maybe I should have used:

while(name[0].to_s != “\r”)


while(name[0].to_i != 13)



Oh, yes the single index change.

while(name[0,1] != "\r")

… should work for both. (Returns 1 character in all Ruby versions.)


I modified the code to use your suggested change and it now works with 8, 2015, and 2016. Thanks, Dan :slight_smile:

@REMx - If you replace line 171 (in the latest version or line 170 in your version) with:

    while(name[0,1] != "\r")

it should work now … you will still need to replace lines 158, 284, and 296 with the hardcoded path and filenames.


Yes, it worked! The import process is now smooth sailing on my good old Sketchup 8

I should have told right from the start which version of the program I was using, sorry about that.
Now I’m glad all this helped improve the plugin so it now works on any common version of Sketchup.
What a great plugin to have :smiley:

Thanks Jim, thanks Dan,



Hi Jim, thanks for taking the time to do this. I know it’s your hobby but I still feel a thanks is in order!

I’ve been trying to follow this thread and understand what’s going on but I’m a bit lost. I’ve gotten as far as installing the plugin(Spirix Import Shapefile) but I’m very confused by this shapefile business. Basically I want to work with the Chelsea area in New York. These are the steps I’ve taken to create the shapefile:

  1. I’ve followed the instructions as posted here:

  2. I’ve renamed the files building_0715 and pasted them in C\temp (??)

  3. Then I’ve opened the shapefile in Sketchup to this window:

I’ve no idea what to do from here or whether I’m on the right track at all for that matter. I just clicked OK but nothing happened. I’m new to Sketchup and obviously to the process outlined above. Any help would be greatly appreciated.

Thank you,


You’re not alone :wink:

The issue you are having is that the shapefile you’ve created from the OSM data doesn’t contain any closed polygons as defined by the shapefile standards. The data is a series of polylines that may (or may not) be an enclosed building or a walkway between parks.

If you want the Chelsea section of New York City, you might want to look at this model in the 3D Warehouse:

If you want to import OSM data, I would suggest downloading and installing my OSM Importer:

Browse to and use the native OSM exporter to grab an area:

Adjust the highlighted region:

The filename defaults to “map.osm” and I changed it to “denmark.osm”. Note that even a relatively small region can result in very large files.

Next run the OSM Importer and select the file:

Wait a bit … you should eventually get a popup (depending on the size of the file):

I’m using inches so I scaled it up by 1,000 … depending on the geometry, you may need to increase this (or decrease it):

If all is well and the planets are aligned correctly, you should get something like this as your reward:


That’s great. The planets were indeed aligned.

Thanks also for the Sketchup model. The area I was looking at (around Chealsea park) isn’t included unfortunately. I will however need to be able to import OSM data on a regular basis so the method you outlined is exactly what I need. Thank you.

I now wonder if there’s a way to smart extrude the models as outlined in this DEM Earth tutorial at 05:45: ?

Thanks in advance,


I’ve tiled all of downtown New York City … This model has the key to everything:

Maybe this tile has what you’re looking for?


I don’t know how I managed to miss that reference model. It’s been a long day (coming to a close here in London).

Cheers. This is amazing.


Sorry to bother you again Jim but is there an way to add textures to these buildings?


No bother. Unfortunately, there is no easy way to texture the buildings. However, comparing Google Earth’s 3D views with the imported shapes will give you a good idea of what they should really look like. The buildings I created were generated from the NYC database that provides an outline of the building footprint and its overall height. It doesn’t provide any detail as to whether or not there are multiples heights within the footprint. Here’s an example using the Museum of Modern Art (MoMA):

Note the difference … if you happen to have good street level views, you can use them to texture the buildings. But you still have to do it by hand.


I see what you’re saying.

I’m trying to figure out the most cost effective way to model the existing world for phasing and construction animations without compromising too much on quality.

Right now, without any background in either the construction or animation field, I’m researching the most cost effective way for a construction company to go about creating these animations which they would like to include in their bidding process. While we’ve got a workflow down i.e. Sketchup to Lumion, we’re trying to figure out if it is more cost effective to carry out the existing world modelling in-house or to outsource.

Taking into account what you say in your last post, we could use a model similar to yours but I feel we would need to model from scratch the buildings that are in close proximity to the construction project.

Any feedback is very welcome.


Do you think it’s possible to generate these models from some database that provides an outline of the which includes multiple heights within the footprint? Or does a database like that even exist?


The OSM database allows for building definitions that specify different heights of the roof (and type of roof) for the parts of larger buildings. However, it is limited at best. As near as I can determine, most of the detail data is manually massaged by private firms that make the custom database available for a fee. Several cities have posted individual building datasets in a wide variety of formats. Shapefiles and OSM are but two of them. If you haven’t looked into ArcGIS, you might find some interesting things there.

If the specific city doesn’t matter, you can find all kinds of detailed datasets, here and there, for random municipalities around the world. Great fun :slight_smile:


Thank you, I’ll look into that. I know I might be going a bit off topic here so forgive me but I just got wind of Infraworks 360 Model Builder. Have you heard of it? If so, I’d be interested to hear your thoughts!