Skip to content

Commit

Permalink
Merge pull request #176 from specklesystems/jrm/blender/automate
Browse files Browse the repository at this point in the history
Extracted some functions for automate
  • Loading branch information
JR-Morgan authored Oct 13, 2023
2 parents a3d4881 + afa6722 commit b55df58
Show file tree
Hide file tree
Showing 4 changed files with 43 additions and 31 deletions.
2 changes: 1 addition & 1 deletion bpy_speckle/convert/to_native.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down
2 changes: 1 addition & 1 deletion bpy_speckle/convert/util.py
Original file line number Diff line number Diff line change
Expand Up @@ -255,7 +255,7 @@ def add_uv_coords(speckle_mesh: Mesh, blender_mesh: BMesh):
}

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

Expand Down
8 changes: 4 additions & 4 deletions bpy_speckle/operators/streams.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"),
]

Expand All @@ -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")


Expand Down Expand Up @@ -183,7 +183,7 @@ def receive(self, context: Context) -> None:
(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]
Expand Down Expand Up @@ -620,7 +620,7 @@ def execute(self, context):

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

Expand Down
62 changes: 37 additions & 25 deletions bpy_speckle/operators/users.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,10 @@
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):
Expand Down Expand Up @@ -58,7 +58,7 @@ def execute(self, context):
_report("Loading users...")

speckle = cast(SpeckleSceneSettings, context.scene.speckle) #type: ignore
users = speckle.users
users_list = speckle.users

ResetUsers.reset_ui(context)

Expand All @@ -77,46 +77,58 @@ def execute(self, context):
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()

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
Expand Down

0 comments on commit b55df58

Please sign in to comment.