2

I've been reading through this page on how to change the context of a Python script so that the poll is correct. I recently ran the AssetGen addon that broke because it reported that bpy.ops.uv.smart_project.poll() failed because its context is incorrect: enter image description here

Apparently, the context for UV unwrapping is now only edit mode and not object mode as well (https://developer.blender.org/T83038). If I want to edit this addon to work properly, how can I set the context to edit mode before the smart_project operator is called?

Thanks!

Anson Savage
  • 3,392
  • 3
  • 31
  • 67
  • 1
    I would recommend adding more details about the addon in question. Given it's not a standard addon pre-shipped and enabled with blender it might be useful for people to know where you got the addon, which version of the addon you are using, which version of blender you are running to better assist you. – Ratt May 14 '22 at 00:30
  • @Ratt Good thinking! – Anson Savage May 14 '22 at 03:06
  • 1
    looks like you can just paste bpy.ops.object.mode_set(mode = 'EDIT') into line 363 which is currently blank and bpy.ops.object.mode_set(mode = 'OBJECT') into line 365 which is also currently blank. Just be sure to have the indentation match up around line 364. (in the GA.py file) cant help you with the addon file location on linux though sorry. – Ratt May 14 '22 at 03:23
  • Hey, yeah! I ended up using bpy.ops.object.editmode_toggle() and that seemed to do the job as well! So it's not throwing a runtime error anymore, but it seems that there's some other broken things with the addon sadly :) Thanks for the help! – Anson Savage May 14 '22 at 03:51

1 Answers1

4

The context can be changed to edit mode with:

bpy.ops.object.mode_set(mode = 'EDIT')

or with

bpy.ops.object.editmode_toggle()

if the context is Object mode already.

Anson Savage
  • 3,392
  • 3
  • 31
  • 67