BlenderGIS icon indicating copy to clipboard operation
BlenderGIS copied to clipboard

data import scripting

Open Spfeil2 opened this issue 2 years ago • 2 comments

Blender and OS versions

Blender 3.2.1 Windows 10

Describe the bug

Is it possible to perform data import (.shp with BlenderGIS) through the scripting interface?

How to Reproduce

I'm working on a project in which I automate the conversion of building footprints and floor plans (shapefiles) into 3D building models using Blender. Currently, I import the shapefiles manually, but I also want to automate this step. Thank you in advance!

Error message

Spfeil2 avatar Sep 25 '23 15:09 Spfeil2

I actually ran into a similar need of batch-importing rasters a few days ago. I found a solution from issue #754

Likewise, you can simply call the bpy.ops.importgis.shapefile operator from your script, just like this:

import bpy

shp_files = [#List of shp file paths]
for path in shp_files:
    bpy.ops.importgis.shapefile(filepath=path)

Note that you need to use keyword arguments (i.e. filepath= is mandatory). The filepath parameter is the minimal requirement to import a shapefile. You could use the below parameters as needed:

filepath="",            # Shapefile path.
shpCRS="",              # CRS of the shapefile.
elevSource="GEOM",      # Determine the source of elevation. Can be None, "GEOM", "OBJ", "FIELD"
objElevName="",         # If elevSource == "OBJ", the object name used for elevation.
fieldElevName="",       # If elevSource == "FIELD", the attribute field to determine elevation.
fieldExtrudeName="",    # The field name of the attribute used to extrude the faces. Leave blank if extrusion is not needed.
fieldObjName="",        # If separateObjects == True, the attribute field to name the generated objects.
extrusionAxis='Z',      # Extrusion direction. Can be "NORMAL", "Z"
separateObjects=False   # Import features as separate objects.

SerLinkzero avatar Oct 07 '23 05:10 SerLinkzero

perfect, this is what I was looking for. Thank you very much!!

Spfeil2 avatar Oct 16 '23 12:10 Spfeil2