My goal is to import a .shp file into blender within my python script. I found the add-on BlenderGIS that offers this functionality. I can add the add-on to blender make it work "manually", but I want to call the import function from a python script.

I am new to Blender and I cannot find what the right way is to import a add-on/BlenderGIS into a python script.

Among other things, I tried the following:

import bpy
import sys
import os

dir = os.path.dirname(bpy.data.filepath)
if not dir in sys.path:
    sys.path.append(dir )

import io_shapefile

file = "path/to/file.shp"


This gives the error:

Traceback (most recent call last):
  File "<blender_console>", line 1, in <module>
TypeError: 'BPyOpsSubMod' object is not callable

Can someone point me in the right direction on how to import a .shp from a python script?

Thanks in advance


Have a look at the operator name when you mouse over it, in this case bpy.ops.importgis.shapefile()

Now in the python console type in command and using autocomplete ctrl-space

>> bpy.ops.importgis.shapefile(
bpy.ops.importgis.shapefile(filepath="", filter_glob="*.shp", useFieldElev=False, fieldElevName="", useFieldExtrude=False, fieldExtrudeName="", extrusionAxis='Z', angCoords=False, separateObjects=False, useFieldName=False, fieldObjName="")

You get the operator call and the parameters. Testing with a local filepath

>>> bpy.ops.importgis.shapefile(filepath="/mnt/.../GDAL/contour.shp")
Read shapefile...
Feature type : PolyLine
DBF fields : ['id', 'elev']
Imported mesh had some problem, check the result!


"bpy.ops.importgis(file)" is not a function. The right way to import a .shp file with BlenderGIS is:

bpy.ops.importgis.shapefile("EXEC_DEFAULT", filepath=file)

where the first parametere can be one of these options:


So, the following code will import a .shp file:

import bpy
file = "/path/to/file.shp"
bpy.ops.importgis.shapefile("EXEC_DEFAULT", filepath=file)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.