0
$\begingroup$

I'm trying to save a texture using save_as, because I want to use the optional Copy parameter. I'm using this code:

# locals: size (int), path (string)
tex = bpy.data.images.new("MyTexture", size, size)
bpy.ops.image.save_as({"edit_image": tex}, copy=True, filepath=path)

As a result, I'm getting this:

RuntimeError: Operator bpy.ops.image.save_as.poll() failed, context is incorrect

However, I can't find any documentation about which context is needed for save_as. So my questions are:

  • What is the required context for save_as?
  • Where do I generally find what context is required for an operator?
$\endgroup$
  • $\begingroup$ How about tex.save_render(path) $\endgroup$ – batFINGER May 8 '19 at 12:35
  • $\begingroup$ It has slightly different behaviour in that it doesn't save a copy, but sets the image path, too. I do baking and I'm getting memory leaks when creating more images, so I'd like to re-use the same image to bake different channels. I know, it's a workaround around a workaround, but I'd generally like to know how to use these operators. $\endgroup$ – georch May 9 '19 at 21:58
  • $\begingroup$ (And after saving the image with tex.save_render, I can't change certain parameters of the texture any more, e.g. size) $\endgroup$ – georch May 9 '19 at 21:59
  • $\begingroup$ Why not? tex.scale(width, height) $\endgroup$ – batFINGER May 10 '19 at 11:05
0
$\begingroup$

Have you tried looking in the Blender documentation? It covers the following

bpy.ops.image.save_as(save_as_render=False, copy=False, filepath="", check_existing=True, filter_blender=False, filter_backup=False, filter_image=True, filter_movie=True, filter_python=False, filter_font=False, filter_sound=False, filter_text=False, filter_btx=False, filter_collada=False, filter_alembic=False, filter_folder=True, filter_blenlib=False, filemode=9, relative_path=True, show_multiview=False, use_multiview=False, display_type='DEFAULT', sort_method='FILE_SORT_ALPHA')
|improve this answer|||||
$\endgroup$
  • $\begingroup$ docs.blender.org/api/master/… This is what I considered. It says nothing about the context or why I am getting that error. $\endgroup$ – georch May 9 '19 at 21:54
  • $\begingroup$ i am too getting similar error, i use bpy.data.image["myimage"], gets error too. While save() would work, weird. $\endgroup$ – adrian li Mar 26 at 19:38

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.