generated from specklesystems/speckle_automate_python_example
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
3 changed files
with
38 additions
and
28 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
FROM python:3.11-slim | ||
FROM nytimes/blender:latest | ||
|
||
RUN pip install poetry | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,49 +1,48 @@ | ||
import bpy | ||
import os | ||
from bpy_speckle.properties.scene import SpeckleSceneSettings | ||
from bpy_speckle.convert.to_native import _deep_conversion | ||
|
||
from specklepy.api import operations | ||
from specklepy.transports.server import ServerTransport | ||
from automate_data import * | ||
|
||
|
||
|
||
|
||
def take_screenshot(): | ||
bpy.ops.render.render(write_still = True) | ||
print(f"We took a screenshot! saved at {bpy.context.scene.render.filepath}") | ||
|
||
def set_output_path(commitId, cameraName): | ||
#Get Output file directory | ||
def set_filename(fileName): | ||
"""Sets the output directory for rendered images""" | ||
filepath = bpy.data.filepath | ||
filename = os.path.basename(filepath) | ||
directory = os.path.dirname(filepath) | ||
if not filepath: | ||
raise Exception("Blend file must be saved!") | ||
|
||
bpy.context.scene.render.filepath = os.path.join(directory, "Screenshots", f"{commitId}.{cameraName}") | ||
bpy.context.scene.render.filepath = os.path.join(directory, "Screenshots", fileName) | ||
|
||
|
||
print(f"Starting Receive...") | ||
|
||
remote_transport = ServerTransport(STREAMID, token=TOKEN, url=SERVER_URL) | ||
commit_object = operations.receive(OBJECTID, remote_transport) | ||
|
||
speckle: SpeckleSceneSettings = bpy.context.scene.speckle | ||
converted_objects = {} | ||
_deep_conversion(commit_object, converted_objects, True) | ||
|
||
|
||
print("hello speckle screenshot tool!") | ||
bpy.ops.speckle.users_load() | ||
bpy.ops.speckle.receive_stream_objects() | ||
|
||
|
||
print(f"We received the objects!") | ||
all_cameras = [o for o in bpy.context.scene.objects if o.type == 'CAMERA'] | ||
total = len(all_cameras) | ||
|
||
print(f"Starting rendering cameras... 0/{total}") | ||
|
||
|
||
|
||
for ob in bpy.context.scene.objects: | ||
if ob.type != 'CAMERA': | ||
continue | ||
for (i, ob) in enumerate(all_cameras): | ||
#Set as active render cam | ||
bpy.context.scene.camera = ob | ||
commit = speckle.get_active_user().get_active_stream().get_active_branch().get_active_commit() | ||
set_output_path(commit.id, ob.name) | ||
take_screenshot() | ||
|
||
#Render camera to output directory | ||
set_filename(f"{ob.name}") | ||
bpy.ops.render.render(write_still = True) | ||
print(f"Render {i}/{total} complete! saved at {bpy.context.scene.render.filepath}") | ||
|
||
print(f"All Done!") | ||
|
||
|
||
|