stuffmatic / fSpy-Blender

Official fSpy importer for Blender
https://fspy.io
GNU General Public License v3.0
1.2k stars 122 forks source link

fspy failed to import probem for blender 2.8 import #18

Open StephaneTephane opened 5 years ago

StephaneTephane commented 5 years ago

How can i solve that ? Here is the message from blender 2.8-> operator bpy.ops.object.camera_add.poll() failed, context is incorrect any idea ? thx in advance

stuffmatic commented 5 years ago

Wild guess: you don't have a 3D view open when doing the import?

Do you get a more detailed error message?

StephaneTephane commented 5 years ago

Hello!Yes i have one open like on the screen shot!

Roethlisberger Stéphane BethlehemStrasse 175 3018 Berne  ++41 78 778 66 29

On Monday, September 9, 2019, 08:27:33 AM GMT+2, Stuffmatic <notifications@github.com> wrote:  

Wild guess: you don't have a 3D view open when doing the import?

Do you get a more detailed error message?

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub, or mute the thread.

stuffmatic commented 5 years ago

I would be great if you could proved some steps to reproduce the issue. And perhaps also a .blend file if it happens for a specific .blend file.

StephaneTephane commented 5 years ago

Hello!i'have tried to import on an other blender file and it's work !?!?i don't know what's happend on the firts file ( was virgin)!?

Roethlisberger Stéphane BethlehemStrasse 175 3018 Berne  ++41 78 778 66 29

On Tuesday, September 10, 2019, 12:34:22 PM GMT+2, Stuffmatic <notifications@github.com> wrote:  

I would be great if you could proved some steps to reproduce the issue. And perhaps also a .blend file if it happens for a specific .blend file.

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub, or mute the thread.

brendensoares commented 4 years ago

I ran into the same issue today while trying to import a 2nd camera view using another fspy file. Though if I create a new blender file I can import both of them fine. There is something wrong with my existing blender file.

I did change the units in my affected blender file. I wonder if that's related?

brendensoares commented 4 years ago

Changing the units back to default metric made no difference. I also removed the camera that the fspy import created and then tried reimporting both of my fspy files and both generated the above mentioned error.

brendensoares commented 4 years ago

I undid the fspy imported camera delete (by reloading my blender file) and then imported the initial fspy file again (the already existing imported camera) and it worked without error.

However, when I delete the fspy imported camera and immediately try to import its fspy file again, it now fails with the same error.

brendensoares commented 4 years ago

The only mention of add_camera in the code is https://github.com/stuffmatic/fSpy-Blender/blob/0a593e0b1933c0a65e10a6bacb5e16c985b90cee/fspy_blender/addon.py#L90 which means there is no existing camera object detected so it tries to create a new one.

Running bpy.ops.object.camera_add() in Blender's Python console generates the error:

>>> bpy.ops.object.camera_add()
Traceback (most recent call last):
  File "<blender_console>", line 1, in <module>
  File "/Applications/Blender.app/Contents/Resources/2.82/scripts/modules/bpy/ops.py", line 201, in __call__
    ret = op_call(self.idname_py(), None, kw)
RuntimeError: Operator bpy.ops.object.camera_add.poll() failed, context is incorrect

I did some further debugging:

>>> cont = bpy.context.area.type
>>> print(str(cont))
CONSOLE

>>> bpy.context.area.type = '?'
Traceback (most recent call last):
  File "<blender_console>", line 1, in <module>
TypeError: bpy_struct: item.attr = val: enum "?" not found in (, 'VIEW_3D', 'IMAGE_EDITOR', 'NODE_EDITOR', 'SEQUENCE_EDITOR', 'CLIP_EDITOR', 'DOPESHEET_EDITOR', 'GRAPH_EDITOR', 'NLA_EDITOR', 'TEXT_EDITOR', 'CONSOLE', 'INFO', 'OUTLINER', 'PROPERTIES', 'FILE_BROWSER', 'PREFERENCES')

So (as I'm learning this) it seems the blender UI area is what drives the context. It seems the fspy import plugin is attempting to add a camera to a context that doesn't support it.

SOLUTION

make sure you're not in Edit Mode. I was and when I changed back to Object Mode, I was able successfully import the fspy file as a camera.

Gaud1225 commented 3 years ago

thank you being in object mode was the issue

alexandis commented 1 year ago

Suddenly got the same issue. It happened after I adjusted points in the fspy project, resaved it and now trying to import it to my Blender scene (initially deleted "old" fspy camera). I tried to move the points slightly, but keep getting the same error again and again. Here is the scene + fspy project. Subway.zip

UPDATE: hmm - switched to Shading mode and the import now is successful...