Compare commits

...

5 Commits

Author SHA1 Message Date
JR-Morgan fbda0110cd fix(connector): 2.9.0 update 2022-10-11 18:43:36 +01:00
Jedd Morgan ba9ad9ac07 Merge pull request #118 from specklesystems/gergo/workflowMetrics
add workflow tracking to receive operations
2022-10-11 17:56:40 +01:00
Jedd Morgan d13db2b44a Merge pull request #117 from specklesystems/jrm/receive-script-update
Jrm/receive script update
2022-10-11 17:54:33 +01:00
JR-Morgan 2c127c85f3 feat: Updated recieve scripts to use context rather than scene 2022-10-07 16:03:10 +01:00
Gergő Jedlicska cc099c0ff1 add workflow tracking to receive operations 2022-10-07 16:08:27 +02:00
4 changed files with 413 additions and 720 deletions
+2 -1
View File
@@ -10,4 +10,5 @@ __pycache__/
# dev
.venv
Installers/
modules/
modules/
.tool-versions
+27 -18
View File
@@ -3,7 +3,7 @@ Stream operators
"""
from itertools import chain
from math import radians
from typing import Callable, Dict, Iterable, TypeAlias
from typing import Callable, Dict, Iterable
import bpy
from specklepy.api.models import Commit
import webbrowser
@@ -15,7 +15,6 @@ from bpy.types import Context, Object
from bpy_speckle.convert.to_native import can_convert_to_native, convert_to_native
from bpy_speckle.convert.to_speckle import (
convert_to_speckle,
ngons_to_speckle_polylines,
)
from bpy_speckle.functions import (
_check_speckle_client_user_stream,
@@ -26,12 +25,13 @@ from bpy_speckle.convert import get_speckle_subobjects
from bpy_speckle.clients import speckle_clients
from bpy_speckle.operators.users import add_user_stream
from specklepy.api import operations
from specklepy.api import operations, host_applications
from specklepy.api.wrapper import StreamWrapper
from specklepy.api.resources.stream import Stream
from specklepy.transports.server import ServerTransport
from specklepy.objects.geometry import *
from specklepy.logging.exceptions import SpeckleException
from specklepy.logging import metrics
def get_objects_collections(base: Base) -> Dict[str, list]:
@@ -96,7 +96,7 @@ def get_objects_collections_recursive(base: Base, parent_col: bpy.types.Collecti
return objects
ObjectCallback = Callable[[bpy.types.Scene, Object, Base], Object] | None
ObjectCallback = Callable[[bpy.types.Context, Object, Base], Object] | None
ReceiveCompleteCallback = Callable[[bpy.types.Context, Dict[str, Object]], None] | None
def get_receive_funcs(context: Context, created_objects: Dict[str, Object]) -> tuple[ObjectCallback, ReceiveCompleteCallback]:
@@ -104,14 +104,15 @@ def get_receive_funcs(context: Context, created_objects: Dict[str, Object]) -> t
Fetches the injected callback functions from user specified "Receive Script"
"""
objectCallback = None
receiveCompleteCallback = None
objectCallback: ObjectCallback = None
receiveCompleteCallback: ReceiveCompleteCallback = None
if context.scene.speckle.receive_script in bpy.data.texts:
mod = bpy.data.texts[context.scene.speckle.receive_script].as_module()
if hasattr(mod, "execute_for_each"):
objectCallback = mod.execute_for_each
elif hasattr(mod, "execute"):
objectCallback = lambda s, o, _ : mod.execute(s, o)
objectCallback = lambda c, o, _ : mod.execute(c.scene, o)
if hasattr(mod, "execute_for_all"):
receiveCompleteCallback = mod.execute_for_all
@@ -119,9 +120,8 @@ def get_receive_funcs(context: Context, created_objects: Dict[str, Object]) -> t
progress = 0
def for_each_object(scene: bpy.types.Scene, obj: Object, base: Base) -> Object:
def for_each_object(context: bpy.types.Context, obj: Object, base: Base) -> Object:
nonlocal progress
nonlocal context
nonlocal created_objects
nonlocal objectCallback
@@ -130,13 +130,13 @@ def get_receive_funcs(context: Context, created_objects: Dict[str, Object]) -> t
created_objects[obj.name] = obj
if objectCallback:
return objectCallback(scene, obj, base)
return objectCallback(context, obj, base)
else:
return obj
return (for_each_object, receiveCompleteCallback)
def bases_to_native(context: bpy.types.Context, collections: Dict[str, list], scale: float, stream_id: str, func: ObjectCallback | None = None):
def bases_to_native(context: bpy.types.Context, collections: Dict[str, list], scale: float, stream_id: str, func: ObjectCallback = None):
for col_name, objects in collections.items():
col = bpy.data.collections[col_name]
existing = get_existing_collection_objs(col)
@@ -175,7 +175,7 @@ def base_to_native(context: bpy.types.Context,
stream_id: str,
col: bpy.types.Collection,
existing: Dict[str, Object],
func: ObjectCallback | None = None
func: ObjectCallback = None
):
new_objects = convert_to_native(base)
if not isinstance(new_objects, list):
@@ -199,7 +199,7 @@ def base_to_native(context: bpy.types.Context,
Run injected function
"""
if func:
new_object = func(context.scene, new_object, base)
new_object = func(context, new_object, base) #this base object isn't the right one for hosted elements!
if (
new_object is None
@@ -358,10 +358,19 @@ class ReceiveStreamObjects(bpy.types.Operator):
_report("No commits found. Probably an empty stream.")
return {"CANCELLED"}
commit = branch.commits.items[int(bbranch.commit)]
commit: Commit = branch.commits.items[int(bbranch.commit)]
transport = ServerTransport(stream.id, client)
stream_data = operations.receive(commit.referencedObject, transport)
metrics.track(
metrics.RECEIVE,
getattr(transport, "account", None),
custom_props={
"sourceHostApp": host_applications.get_host_app_from_string(commit.sourceApplication).slug,
"sourceHostAppVersion": commit.sourceApplication
},
)
stream_data = operations._untracked_receive(commit.referencedObject, transport)
client.commit.received(
bstream.id,
commit.id,
@@ -383,8 +392,8 @@ class ReceiveStreamObjects(bpy.types.Operator):
name = "{} [ {} @ {} ]".format(stream.name, branch.name, commit.id)
col = create_collection(name)
col.speckle.stream_id = stream.id
col.speckle.name = stream.name
col.speckle.units = stream_data.units
col.speckle.units = stream_data.units or "m"
if col.name not in bpy.context.scene.collection.children:
bpy.context.scene.collection.children.link(col)
@@ -397,7 +406,7 @@ class ReceiveStreamObjects(bpy.types.Operator):
Set conversion scale from stream units
"""
scale = (
get_scale_length(stream_data.units)
get_scale_length(col.speckle.units)
/ context.scene.unit_settings.scale_length
)
Generated
+379 -699
View File
File diff suppressed because it is too large Load Diff
+5 -2
View File
@@ -2,12 +2,12 @@
name = "speckle-blender"
version = "2.0.0"
description = "the Speckle 2.0 connector for Blender!"
authors = ["izzy lyseggen <izzy.lyseggen@gmail.com>"]
authors = ["izzy lyseggen <izzy.lyseggen@gmail.com>", "Gergő Jedlicska <gergo@jedlicska.com>"]
license = "Apache-2.0"
[tool.poetry.dependencies]
python = ">=3.8, <4.0.0"
specklepy = "^2.6.6"
specklepy = "^2.9.0"
[tool.poetry.dev-dependencies]
devtools = "^0.6.1"
@@ -16,6 +16,9 @@ fake-bpy-module-latest = "^20220401"
black = "^21.12b0"
pylint = "^2.12.2"
[tool.poetry.group.local_specklepy.dependencies]
specklepy = {path = "../specklepy", develop = true}
[build-system]
requires = ["poetry-core>=1.0.0"]
build-backend = "poetry.core.masonry.api"