Skip to content
This repository has been archived by the owner on Dec 6, 2021. It is now read-only.

Commit

Permalink
Bug fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
tsvilans committed Mar 17, 2020
1 parent 085159d commit 4301e46
Show file tree
Hide file tree
Showing 6 changed files with 29 additions and 20 deletions.
6 changes: 3 additions & 3 deletions bpy_speckle/convert/to_speckle/mesh.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
from time import strftime, gmtime


ignored_keys=["speckle", "_speckle_type", "_speckle_name", "_RNA_UI", "transform"]

def export_mesh(blender_object, scale=1.0):
return MeshObject_to_SpeckleMesh(blender_object, scale)
#return None
Expand All @@ -22,7 +24,6 @@ def MeshObject_to_SpeckleMesh(obj, scale=1.0):

#faces = [x.vertices for x in obj.data.polygons]

#sm = SpeckleResource.createSpeckleMesh()
sm = {'vertices':[], 'faces':[]}

for v in verts:
Expand All @@ -41,8 +42,7 @@ def MeshObject_to_SpeckleMesh(obj, scale=1.0):
# Add properties and custom data
sm['properties'] = {}
for key in obj.keys():
#print (key)
if key == "speckle" or key == "_RNA_UI":
if key in ignored_keys:
continue
if hasattr(obj[key], 'to_dict'):
sm['properties'][key] = obj[key].to_dict()
Expand Down
18 changes: 8 additions & 10 deletions bpy_speckle/functions.py
Original file line number Diff line number Diff line change
Expand Up @@ -97,16 +97,14 @@ def _add_account(client, cache, email, pwd, host, host_name="Speckle Hestia"):
else:
return False

if DEBUG:
_report("client.login")

try:
client.login(email=self.email, password=self.pwd)
client.login(email=email, password=pwd)
except AssertionError as e:
_report("Login failed.")
return False

authtoken = client.get("me").get("apitoken")
#authtoken = client.get("me").get("apitoken")
authtoken = client.me.get("apitoken")

'''
user = {
Expand Down Expand Up @@ -169,12 +167,12 @@ def _get_accounts(scene):
account.email=p['email']
account.authToken = p['apitoken']

def _create_stream(client, account, units="Millimeters"):
def _create_stream(client, account, stream_name, units="Millimeters"):

client.server = account.server
client.s.headers.update({'Authorization': account.authToken})

stream = {'name':self.stream_name, 'baseProperties':{'units':units}}
stream = {'name':stream_name, 'baseProperties':{'units':units}}

client.streams.create(stream)

Expand All @@ -183,7 +181,7 @@ def _delete_stream(client, account, stream):
client.s.headers.update({'Authorization': account.authToken})

if stream:
res = context.scene.speckle_client.StreamDeleteAsync(stream.streamId)
res = client.streams.delete(stream.streamId)
_report(res['message'])

'''
Expand All @@ -194,14 +192,14 @@ def _clear_cache_objects(cache):
if not cache.try_connect():
return False

cache.delete_all("Account")
cache.delete_all("CachedObject")
return True

def _clear_cache_accounts(cache):
if not cache.try_connect():
return False

cache.delete_all("CachedObject")
cache.delete_all("Account")
return True

def _clear_cache_stream(cache):
Expand Down
2 changes: 2 additions & 0 deletions bpy_speckle/operators/accounts.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ def execute(self, context):
_report("Loading accounts...")

_get_accounts(context.scene)
bpy.context.view_layer.update()

# for account in speckle.accounts:
# _get_streams(client, account)
Expand All @@ -81,6 +82,7 @@ def execute(self, context):
if len(speckle.accounts) > 0 and speckle.active_account >= 0 and speckle.active_account < len(speckle.accounts):
account = speckle.accounts[speckle.active_account]
_get_streams(client, account)
bpy.context.view_layer.update()

return {'FINISHED'}

Expand Down
3 changes: 3 additions & 0 deletions bpy_speckle/operators/cache.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

import bpy
from bpy.props import BoolProperty
from bpy_speckle.functions import _clear_cache_objects, _clear_cache_accounts, _clear_cache_stream

class ClearObjectCache(bpy.types.Operator):
bl_idname = "speckle.cache_clear_objects"
Expand Down Expand Up @@ -72,8 +73,10 @@ def execute(self, context):
self.are_you_sure = False

if _clear_cache_accounts(context.scene.speckle.cache):
print("Cleared accounts")
bpy.ops.speckle.accounts_load()
return {'FINISHED'}
bpy.context.view_layer.update()

return {'CANCELLED'}

Expand Down
10 changes: 8 additions & 2 deletions bpy_speckle/operators/object.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,15 +39,21 @@ def execute(self, context):
if active.speckle.send_or_receive == "send" and active.speckle.stream_id:
res = client.StreamGetAsync(active.speckle.stream_id)['resource']
#res = client.streams.get(active.speckle.stream_id)
_report(res)

if res is None:
_report ("Getting stream failed.")
return {'CANCELLED'}

scale = context.scene.unit_settings.scale_length / get_scale_length(res['baseProperties']['units'])
stream_units = 1.0
bp = res.get("baseProperties")
if bp:
stream_units = bp.get("units", "Meters")

scale = context.scene.unit_settings.scale_length / get_scale_length(stream_units)

sm = to_speckle_object(active, scale)


_report("Updating object {}".format(sm['_id']))
client.objects.update(active.speckle.object_id, sm)

Expand Down
10 changes: 5 additions & 5 deletions bpy_speckle/operators/streams.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
from bpy.props import StringProperty, BoolProperty, FloatProperty, CollectionProperty, EnumProperty

# from speckle import SpeckleApiClient
from bpy_speckle.functions import _check_speckle_client_account_stream, _get_stream_objects, _delete_stream, get_scale_length, _report
from bpy_speckle.functions import _check_speckle_client_account_stream, _get_stream_objects, _create_stream, _delete_stream, get_scale_length, _report
from bpy_speckle.convert import to_speckle_object, get_speckle_subobjects
from bpy_speckle.convert.to_speckle import export_ngons_as_polylines

Expand Down Expand Up @@ -217,10 +217,10 @@ def execute(self, context):

speckle = context.scene.speckle

if len(speckle.accounts) > 0 and speckle.active_account > 0 and speckle.active_account < len(speckle.accounts):
if len(speckle.accounts) > 0 and speckle.active_account >= 0 and speckle.active_account < len(speckle.accounts):
account = speckle.accounts[speckle.active_account]

if len(account.streams) > 0 and account.active_stream > 0 and account.active_stream < len(account.streams):
if len(account.streams) > 0 and account.active_stream >= 0 and account.active_stream < len(account.streams):
stream =account.streams[account.active_stream]

webbrowser.open('%s/streams/%s/objects?omit=displayValue,base64' % (account.server, stream.streamId), new=2)
Expand Down Expand Up @@ -255,12 +255,12 @@ def execute(self, context):
client = context.scene.speckle.client
speckle = context.scene.speckle

if len(speckle.accounts) > 0 and speckle.active_account > 0 and speckle.active_account < len(speckle.accounts):
if len(speckle.accounts) > 0 and speckle.active_account >= 0 and speckle.active_account < len(speckle.accounts):
account = speckle.accounts[speckle.active_account]

_create_stream(client, account, self.stream_name, context.scene.unit_settings.length_unit.title())

bpy.ops.scene.speckle_load_account_streams()
bpy.ops.speckle.load_account_streams()

account.active_stream = account.streams.find(self.stream_name)

Expand Down

0 comments on commit 4301e46

Please sign in to comment.