Skip to content

Instantly share code, notes, and snippets.

@p2or
Last active May 21, 2023 18:19
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save p2or/ebc4d7c98d465de0c1256d2c5f085144 to your computer and use it in GitHub Desktop.
Save p2or/ebc4d7c98d465de0c1256d2c5f085144 to your computer and use it in GitHub Desktop.
Supress operator output #Blender
# for http://blender.stackexchange.com/questions/56087/check-if-an-operation-can-be-applied-without-runtime-errors
import bpy
import io
from contextlib import redirect_stdout
if bpy.ops.mesh.fill_grid.poll():
print("correct context")
else:
print ("incorrect context")
stdout = io.StringIO()
with redirect_stdout(stdout):
try:
bpy.ops.mesh.fill_grid()
except:
pass
stdout.seek(0)
output = stdout.read()
print("Report was %r" % output)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment