Skip to content

Instantly share code, notes, and snippets.

@oxyflour
Created February 3, 2024 08:02
Show Gist options
  • Save oxyflour/86aece72e14ba5693b40e0be5d65925e to your computer and use it in GitHub Desktop.
Save oxyflour/86aece72e14ba5693b40e0be5d65925e to your computer and use it in GitHub Desktop.
blender scripts
# %%
import bpy
# make mesh
vertices = [(0, 0, 0), (1, 0, 0), (0, 1, 0), (0, 0, 1)]
edges = []
faces = [(0, 1, 2), (1, 2, 3), (2, 3, 1), (3, 1, 0)]
new_mesh = bpy.data.meshes.new('new_mesh')
new_mesh.from_pydata(vertices, edges, faces)
new_mesh.update()
# make object from mesh
new_object = bpy.data.objects.new('new_object', new_mesh)
# make collection
new_collection = bpy.data.collections.new('new_collection')
bpy.context.scene.collection.children.link(new_collection)
# add object to scene collection
new_collection.objects.link(new_object)
# %%
import os
#bpy.data.objects.remove(bpy.data.objects['Cube'])
bpy.context.scene.render.filepath = os.path.join(__file__, '..', 'out.png')
bpy.ops.render.render('INVOKE_DEFAULT', animation=False, write_still=True, use_viewport=False, scene="scene")
# %%
img = bpy.data.images['Viewer Node']
print(len(img.pixels))
# %%
import bpy
context = bpy.context
for window in context.window_manager.windows:
screen = window.screen
for area in screen.areas:
if area.type == 'VIEW_3D':
with context.temp_override(window=window, area=area):
bpy.ops.screen.screen_full_area(use_hide_panels=True)
break
print('ok')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment