domlysz / BlenderGIS

Blender addons to make the bridge between Blender and geographic data
GNU General Public License v3.0
7.66k stars 1.35k forks source link

Can't use map_start() in a script #498

Open joebarteam11 opened 3 years ago

joebarteam11 commented 3 years ago

Blender and OS versions

2.92.0 - Ubuntu 20.04.1

Describe the bug

Can't script with python so we can export a map without pressing 'E' key. The aim of the script would be to add elevation data to the previously extracted map and create an STL file from them. This last part works but I can't use the bpy.ops.view3d.map_start() func. in script since this raises a poll error.

It would be awesome to have a function taking a bbox and a city name as parameters so we can automatically load a wanted geographic zone.

How to Reproduce

import bpy
bpy.ops.view3d.map_start(query='Rouen', zoom=14)

Error message

Traceback (most recent call last):
  File "/home/$USER/Documents/script_test.blend/scr.py", line 16, in <module>
    #Geograghic zone to load
  File "/usr/share/blender/2.92/scripts/modules/bpy/ops.py", line 132, in __call__
    ret = _op_call(self.idname_py(), None, kw)
RuntimeError: Error: Python: Traceback (most recent call last):
  File "/home/$USER/.config/blender/2.92/scripts/addons/BlenderGIS-master/operators/view3d_mapviewer.py", line 541, in execute
    bpy.ops.view3d.map_viewer('INVOKE_DEFAULT', srckey=self.src, laykey=self.lay, grdkey=self.grd, recenter=self.recenter)
  File "/usr/share/blender/2.92/scripts/modules/bpy/ops.py", line 130, in __call__
    ret = _op_call(self.idname_py(), C_dict, kw, C_exec, C_undo)
RuntimeError: Operator bpy.ops.view3d.map_viewer.poll() failed, context is incorrect

location: /usr/share/blender/2.92/scripts/modules/bpy/ops.py:132

Error: Python script failed, check the message in the system console
IwVr commented 3 years ago

Have a go at changing the context. See example below

bpy.context.area.type = "VIEW_3D" # Temporarily switch to Viewport Area bpy.ops.view3d.map_start(query='Rouen', zoom=14)

Let me know how it goes!