def empty_to_speckle(blender_object, scale=1.0): # probably an instance collection (block) so let's try it try: geo = blender_object.instance_collection.objects.items() return block_instance_to_speckle(blender_object, scale) except AttributeError as err: _report( f"No instance collection found in empty. Skipping object {blender_object.name}" ) return None
def execute(self, context): active = context.active_object if active is not None: # If active object is mesh client = context.scene.speckle.client client.verbose = True account = context.scene.speckle.accounts[ context.scene.speckle.active_account] stream = account.streams[account.active_stream] client.server = account.server client.s.headers.update({ 'content-type': 'application/json', 'Authorization': account.authToken, }) _report("authToken: ", account.authToken) scale = context.scene.unit_settings.scale_length / get_scale_length( stream.units) sm = to_speckle_object(active, scale) #if '_id' in sm.keys(): # del sm['_id'] #if 'transform' in sm.keys(): # del sm['transform'] #if 'properties' in sm.keys(): # del sm['properties'] placeholders = client.objects.create([sm]) if placeholders == None: return {'CANCELLED'} sstream = client.streams.get(stream.streamId) sstream.objects.extend(placeholders) N = sstream.layers[-1].objectCount sstream.layers[-1].objectCount = N + 1 sstream.layers[-1].topology = "0-%s" % (N + 1) _report("Updating stream %s" % stream['streamId']) res = client.streams.update(stream['streamId'], sstream) _report(res) active.speckle.enabled = True active.speckle.object_id = sm['_id'] active.speckle.stream_id = stream['streamId'] active.speckle.send_or_receive = 'send' # Update view layer context.view_layer.update() _report("Done.") return {'FINISHED'}
def execute(self, context): speckle = context.scene.speckle client = speckle.client _report("Loading accounts...") _get_accounts(context.scene) bpy.context.view_layer.update() # for account in speckle.accounts: # _get_streams(client, account) if context.area: context.area.tag_redraw() return {'FINISHED'}
def execute(self, context): active = context.active_object if not active: return {'CANCELLED'} if self.custom_prop not in active.keys(): return {'CANCELLED'} value = active[self.custom_prop] _report("Looking for '{}' property.".format(self.custom_prop)) for obj in bpy.data.objects: if self.custom_prop in obj.keys(): obj.select_set(True) else: obj.select_set(False) return {'FINISHED'}
def execute(self, context): client = context.scene.speckle.client account = context.scene.speckle.accounts[ context.scene.speckle.active_account] stream = account.streams[account.active_stream] client.server = account.server client.s.headers.update({'Authorization': account.authToken}) active = context.active_object _report(active) if active is not None: if active.speckle.enabled: if active.speckle.send_or_receive == "send" and active.speckle.stream_id: sstream = client.streams.get(active.speckle.stream_id) #res = client.StreamGetAsync(active.speckle.stream_id)['resource'] #res = client.streams.get(active.speckle.stream_id) if sstream is None: _report("Getting stream failed.") return {'CANCELLED'} stream_units = "Meters" if sstream.baseProperties: stream_units = sstream.baseProperties.units 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) return {'FINISHED'} # res = client.ObjectCreateAsync([sm]) # new_id = res['resources'][0]['_id'] # for o in stream_data['objects']: # if o['_id'] == active.speckle.object_id: # o['_id'] = new_id # break # res = client.StreamUpdateAsync(active.speckle.stream_id, {'objects': stream_data['objects']}) # res = client.ObjectDeleteAsync(active.speckle.object_id) # active.speckle.object_id = new_id # if res == None: return {'CANCELLED'} return {'FINISHED'} return {'CANCELLED'}
def execute(self, context): selected = context.selected_objects if len(selected) > 0: # If active object is mesh client = context.scene.speckle.client client.verbose = True account = context.scene.speckle.accounts[context.scene.speckle.active_account] stream =account.streams[account.active_stream] client.server = account.server client.s.headers.update({ 'content-type': 'application/json', 'Authorization': account.authToken, }) scale = context.scene.unit_settings.scale_length / get_scale_length(stream.units.lower()) placeholders = [] ''' Get script from text editor for injection ''' func = None if context.scene.speckle.upload_script in bpy.data.texts: mod = bpy.data.texts[context.scene.speckle.upload_script].as_module() if hasattr(mod, "execute"): func = mod.execute for obj in selected: if obj.type != 'MESH': continue new_object = obj ''' Run injected function ''' if func: new_object = func(context.scene, obj) if new_object is None: # Make sure that the injected function returned an object continue _report("Converting {}".format(obj.name)) create_objects = [] ngons = obj.get("speckle_ngons_as_polylines", False) if ngons: create_objects = export_ngons_as_polylines(obj, scale) else: create_objects = [to_speckle_object(obj, scale)] for co in create_objects: placeholder = client.objects.create(co) if placeholder == None or len(placeholder) < 1: return {'CANCELLED'} placeholders.extend(placeholder) obj.speckle.enabled = True obj.speckle.object_id = placeholder[0].id obj.speckle.stream_id = stream.streamId obj.speckle.send_or_receive = 'send' sstream = client.streams.get(stream.streamId) if sstream is None: return {'CANCELLED'} stream_patch = Stream() stream_patch.objects = placeholders stream_patch.layers = sstream.layers stream_patch.baseProperties.units = stream.units stream_patch.commitMessage = "Modified from Blender (blender.org)." stream_patch.layers[-1].objectCount = len(placeholders) stream_patch.layers[-1].topology = "0-{}".format(len(placeholders)) _report("Updating stream %s" % stream['streamId']) res = client.streams.update(stream['streamId'], stream_patch) _report(res) # Update view layer context.view_layer.update() if context.area: context.area.tag_redraw() return {'FINISHED'}
def execute(self, context): active = context.active_object if active is not None and active.type == 'MESH': # If active object is mesh client = context.scene.speckle.client client.verbose = True account = context.scene.speckle.accounts[ context.scene.speckle.active_account] stream = account.streams[account.active_stream] client.server = account.server client.s.headers.update({ 'content-type': 'application/json', 'Authorization': account.authToken, }) scale = context.scene.unit_settings.scale_length / get_scale_length( stream.units) sp = export_ngons_as_polylines(active, scale) if sp is None: return {'CANCELLED'} placeholders = [] for polyline in sp: #res = client.objects.create(polyline)[0] res = client.objects.create([polyline]) #res = client.ObjectCreateAsync([polyline])['resources'][0] print(res) if res == None: _report(client.me) continue placeholders.extend(res) #polyline['_id'] = res['_id'] #placeholders.append({'type':'Placeholder', '_id':res['_id']}) if len(placeholders) < 1: return {'CANCELLED'} # Get list of existing objects in stream and append new object to list _report("Fetching stream...") sstream = client.streams.get(stream.streamId) #res = client.StreamGetAsync(stream.streamId) #if res is None: return {'CANCELLED'} #stream = res['resource'] #if '_id' in stream.keys(): # del stream['_id'] if self.clear_stream: _report("Clearing stream...") sstream.objects = placeholders N = 0 else: sstream.objects.extend(placeholders) N = sstream.layers[-1].objectCount if self.clear_stream: N = 0 sstream.layers[-1].objectCount = N + len(placeholders) sstream.layers[-1].topology = "0-%s" % (N + len(placeholders)) res = client.streams.update(sstream.streamId, sstream) #res = client.StreamUpdateAsync(stream['streamId'], {'objects':stream['objects'], 'layers':stream['layers']}) # Update view layer context.view_layer.update() _report("Done.") return {'FINISHED'}