2
$\begingroup$

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!

$\endgroup$
4
  • 1
    $\begingroup$ 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. $\endgroup$
    – Ratt
    May 14, 2022 at 0:30
  • $\begingroup$ @Ratt Good thinking! $\endgroup$ May 14, 2022 at 3:06
  • 1
    $\begingroup$ 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. $\endgroup$
    – Ratt
    May 14, 2022 at 3:23
  • $\begingroup$ 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! $\endgroup$ May 14, 2022 at 3:51

1 Answer 1

4
$\begingroup$

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.

$\endgroup$

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .