Something like this:
# imports here
# necessary for the rule to be loaded
import os
import sys
import bpy
import bgl
RULE_NAME = "Render Tumbnail"
def process(input):
"""
This function is called for each file that is checked. The input is the file path.
the function should return an empty json if the file is valid and a json object with the status and required information.
status can be one of the following: "error", "warning", "info"
example:
for a single error: {"status": "error" , "details": {"object_name": "error message"}}
for multiple errors: {"status": "error" , "details": {"object_name": "error message", "object_name2": "error message2"}}
for a single warning: {"status": "warning" , "details": {"object_name": "warning message"}}
for info: {"status": "info" , "details": {"object_name": "info message"}}
"""
result_json = {"status": "info"} # default status is info
details_json = {}
# Implement your rule here and fill the details_json with the appropriate information or errors or leave it empty if there are no errors or warnings
outputimgname = os.path.join(get_render_path(), input + ".png")
for area in bpy.context.screen.areas:
if area.type == 'VIEW_3D':
for region in area.regions:
if region.type == 'WINDOW':
override = {'area': area, 'region': region,
'edit_object': bpy.context.edit_object}
bpy.ops.view3d.view_all(override)
L_altBpyCtx = {
'area': area,
'blend_data': bpy.context.blend_data,
'region': None,
'scene': bpy.context.scene,
'space': area.spaces[0],
'screen': bpy.context.screen,
'window': bpy.context.window
}
# bpy.ops.screen.screenshot(outputimgname)
bpy.ops.screen.screenshot(
L_altBpyCtx, filepath=outputimgname, full=False)
if details_json != {}:
result_json["details"] = details_json
return result_json
else:
return {}
def get_region_view3d():
'''
context = bpy.context
assert context.space_data.type == 'VIEW_3D'
region = context.region
return region
'''
# for win in bpy.context.window_manager.windows:
for win in [bpy.context.window]:
for area3d in [area for area in win.screen.areas if area.type == 'VIEW_3D']:
for region in [region for region in area3d.regions if region.type == 'WINDOW']:
return region
def get_render_path() -> str:
application_path: str = os.path.dirname(sys.executable) if getattr(
sys, 'frozen', False) else os.path.dirname(os.path.abspath(__file__))
return os.path.join(application_path, "renders")
Something like this: