Compare commits

...

2 Commits

Author SHA1 Message Date
Jedd Morgan b55df58313 Merge pull request #176 from specklesystems/jrm/blender/automate
Extracted some functions for automate
2023-10-13 13:02:28 +01:00
Jedd Morgan afa6722253 Extracted some functions for automate 2023-10-13 12:56:30 +01:00
4 changed files with 43 additions and 31 deletions
+1 -1
View File
@@ -518,7 +518,7 @@ def icurve_to_native(speckle_curve: Base, name: str, scale: float) -> bpy.types.
else bpy.data.curves.new(name, type="CURVE")
)
blender_curve.dimensions = "3D"
blender_curve.resolution_u = 12 #TODO: We could maybe decern the resolution from the ployline displayValue
blender_curve.resolution_u = 12 #TODO: We could maybe decern the resolution from the polyline displayValue
icurve_to_native_spline(speckle_curve, blender_curve, scale)
+1 -1
View File
@@ -255,7 +255,7 @@ ignored_keys = {
}
def get_blender_custom_properties(obj, max_depth: int = 63):
"""Recursivly grabs custom properties on blender objects. Max depth is determined by the max allowed by Newtonsoft.NET, don't exceed unless you know what you're doing"""
"""Recursively grabs custom properties on blender objects. Max depth is determined by the max allowed by Newtonsoft.NET, don't exceed unless you know what you're doing"""
if max_depth <= 0:
return obj
+4 -4
View File
@@ -74,7 +74,7 @@ def get_receive_funcs(speckle: SpeckleSceneSettings) -> tuple[ObjectCallback, Re
#]
INSTANCES_SETTINGS = [
("collection_instance", "Collection Instace", "Receive Instances as Collection Instances"),
("collection_instance", "Collection Instance", "Receive Instances as Collection Instances"),
("linked_duplicates", "Linked Duplicates", "Receive Instances as Linked Duplicates"),
]
@@ -91,7 +91,7 @@ class ReceiveStreamObjects(bpy.types.Operator):
clean_meshes: BoolProperty(name="Clean Meshes", default=False)
#receive_mode: EnumProperty(items=RECEIVE_MODES, name="Receive Type", default="replace", description="The behaviour of the recieve operation")
#receive_mode: EnumProperty(items=RECEIVE_MODES, name="Receive Type", default="replace", description="The behaviour of the receive operation")
receive_instances_as: EnumProperty(items=INSTANCES_SETTINGS, name="Receive Instances As", default="collection_instance", description="How to receive speckle Instances")
@@ -183,7 +183,7 @@ class ReceiveStreamObjects(bpy.types.Operator):
(object_converted_callback, on_complete_callback) = get_receive_funcs(speckle)
# older commits will have a non-collection root object
# for the sake of consistant behaviour, we will wrap any non-collection commit objects in a collection
# for the sake of consistent behaviour, we will wrap any non-collection commit objects in a collection
if not isinstance(commit_object, SCollection):
dummy_commit_object = SCollection()
dummy_commit_object.elements = [commit_object]
@@ -620,7 +620,7 @@ class DeleteStream(bpy.types.Operator):
def delete_stream(self, context: Context) -> None:
if not self.are_you_sure:
raise Exception("Cancled by user")
raise Exception("Cancelled by user")
self.are_you_sure = False
+37 -25
View File
@@ -6,10 +6,10 @@ import bpy
from bpy.types import Context
from bpy_speckle.functions import _report
from bpy_speckle.clients import speckle_clients
from bpy_speckle.properties.scene import SpeckleCommitObject, SpeckleSceneSettings, SpeckleUserObject, get_speckle
from bpy_speckle.properties.scene import SpeckleCommitObject, SpeckleSceneSettings, SpeckleStreamObject, SpeckleUserObject, get_speckle
from specklepy.core.api.client import SpeckleClient
from specklepy.core.api.models import Stream
from specklepy.core.api.credentials import get_local_accounts
from specklepy.core.api.credentials import get_local_accounts, Account
from specklepy.logging import metrics
class ResetUsers(bpy.types.Operator):
@@ -58,7 +58,7 @@ class LoadUsers(bpy.types.Operator):
_report("Loading users...")
speckle = cast(SpeckleSceneSettings, context.scene.speckle) #type: ignore
users = speckle.users
users_list = speckle.users
ResetUsers.reset_ui(context)
@@ -77,31 +77,19 @@ class LoadUsers(bpy.types.Operator):
raise Exception("Zero accounts were found, please add one through Speckle Manager or a local account")
for profile in profiles:
user = users.add()
user.server_name = profile.serverInfo.name or "Speckle Server"
user.server_url = profile.serverInfo.url
user.id = profile.userInfo.id
user.name = profile.userInfo.name
user.email = profile.userInfo.email
user.company = profile.userInfo.company or ""
try:
url = profile.serverInfo.url
assert(url)
client = SpeckleClient(
host=url,
use_ssl="https" in url,
)
client.authenticate_with_account(profile)
speckle_clients.append(client)
add_user_account(profile, speckle)
except Exception as ex:
_report(f"Failed to authenticate user {user.email} with server {user.server_url}: {ex}")
users.remove(len(users) - 1)
_report(f"Failed to authenticate user account {profile.userInfo.email} with server {profile.serverInfo.url}: {ex}")
users_list.remove(len(users_list) - 1)
continue
if profile.isDefault:
active_user_index = len(users) - 1
active_user_index = len(users_list) - 1
_report(f"Authenticated {len(users)}/{len(profiles)} accounts")
_report(f"Authenticated {len(users_list)}/{len(profiles)} accounts")
if active_user_index < len(users):
if active_user_index < len(users_list):
speckle.active_user = str(active_user_index)
bpy.context.view_layer.update()
@@ -109,14 +97,38 @@ class LoadUsers(bpy.types.Operator):
if context.area:
context.area.tag_redraw()
if not users:
if not users_list:
raise Exception("Zero valid user accounts were found, please ensure account is valid and the server is running")
return {"FINISHED"}
def add_user_account(account: Account, speckle: SpeckleSceneSettings) -> SpeckleUserObject:
"""Creates a new new SpeckleUserObject for the provided user Account and adds it to the SpeckleSceneSettings"""
users_list = speckle.users
URL = account.serverInfo.url
user = cast(SpeckleUserObject, users_list.add())
user.server_name = account.serverInfo.name or "Speckle Server"
user.server_url = URL
user.id = account.userInfo.id
user.name = account.userInfo.name
user.email = account.userInfo.email
user.company = account.userInfo.company or ""
assert(URL)
client = SpeckleClient(
host=URL,
use_ssl="https" in URL,
)
client.authenticate_with_account(account)
speckle_clients.append(client)
return user
def add_user_stream(user: SpeckleUserObject, stream: Stream):
s = user.streams.add()
"""Adds the provided Stream (with branch & commits) to the SpeckleUserObject"""
s = cast(SpeckleStreamObject, user.streams.add())
s.name = stream.name
s.id = stream.id
s.description = stream.description