def xdraw_texts(texts): """ Draw a set of text objects. Parameters: texts (list): {'radius':, 'pos':, 'color':, 'name':, 'text':, 'layer':}. Returns: list: Created text objects. """ objects = [] bpy.ops.object.text_add(radius=1, view_align=True, location=[0, 0, 0]) object = bpy.context.object for text in texts: copy = object.copy() copy.name = text.get('name', 'text') copy.data.body = text.get('text', 'text') copy.location = Vector(text.get('pos', [0, 0, 0])) copy.scale *= text.get('radius', 1) copy.data = copy.data.copy() copy.data.materials.append(bpy.data.materials[text.get('color', 'white')]) set_objects_layer([copy], text.get('layer', 0)) objects.append(copy) delete_objects([object]) for object in objects: bpy.context.scene.objects.link(object) deselect_all_objects() return objects
def xdraw_cubes(cubes): """ Draw a set of cubes. Parameters: cubes (list): {'radius':, 'pos':, 'color':, 'name':, 'layer':}. Returns: list: Created cube objects. """ objects = [] bpy.ops.mesh.primitive_cube_add(radius=1, location=[0, 0, 0]) object = bpy.context.object for cube in cubes: copy = object.copy() copy.name = cube.get('name', 'cube') copy.location = Vector(cube.get('pos', [0, 0, 0])) copy.scale *= cube.get('radius', 1) copy.data = copy.data.copy() copy.data.materials.append(bpy.data.materials[cube.get('color', 'white')]) set_objects_layer([copy], cube.get('layer', 0)) objects.append(copy) delete_objects([object]) for object in objects: bpy.context.scene.objects.link(object) deselect_all_objects() return objects
def xdraw_spheres(spheres, div=20): """ Draw a set of spheres. Parameters: spheres (dic): {'radius':, 'pos':, 'color':, 'name':, 'layer':}. div (int): Divisions for spheres. Returns: list: Created sphere objects. """ objects = [] bpy.ops.mesh.primitive_uv_sphere_add(size=1, location=[0, 0, 0], ring_count=div, segments=div) object = bpy.context.object for sphere in spheres: copy = object.copy() copy.name = sphere.get('name', 'sphere') copy.location = Vector(sphere.get('pos', [0, 0, 0])) copy.scale *= sphere.get('radius', 1) copy.data = copy.data.copy() copy.data.materials.append(bpy.data.materials[sphere.get('color', 'white')]) set_objects_layer([copy], sphere.get('layer', 0)) objects.append(copy) delete_objects([object]) for object in objects: bpy.context.scene.objects.link(object) deselect_all_objects() return objects
def xdraw_pipes(pipes, div=8): """ Draw a set of pipes. Parameters: pipes (list): {'radius':, 'start':, 'end':, 'color':, 'name':, 'layer':}. div (int): Divisions around cross-section. Returns: list: Created pipe objects. """ objects = [] bpy.ops.mesh.primitive_cylinder_add(radius=1, depth=1, vertices=div, location=[0, 0, 0]) object = bpy.context.object for pipe in pipes: radius = pipe.get('radius', 1) start = pipe.get('start', [0, 0, 0]) end = pipe.get('end', [0, 0, 1]) L = distance_point_point(start, end) pos = centroid_points([start, end]) copy = object.copy() copy.name = pipe.get('name', 'pipe') copy.rotation_euler[1] = acos((end[2] - start[2]) / L) copy.rotation_euler[2] = atan2(end[1] - start[1], end[0] - start[0]) copy.location = Vector(pos) copy.data = copy.data.copy() copy.scale = ((radius, radius, L)) copy.show_wire = True copy.data.materials.append(bpy.data.materials[pipe.get('color', 'white')]) set_objects_layer([copy], pipe.get('layer', 0)) objects.append(copy) delete_objects([object]) for object in objects: bpy.context.scene.objects.link(object) deselect_all_objects() return objects
def clear_facelabels(self, keys=None): if not keys: keys = list(self.datastructure.faces()) objects = [] for key in keys: name = 'F{0}'.format(key) object = get_objects(name=name) if object: objects.append(object) delete_objects(objects=objects)
def clear_edgelabels(self, keys=None): if not keys: keys = list(self.datastructure.edges()) objects = [] for u, v in keys: name = 'E{0}-{1}'.format(u, v) object = get_objects(name=name) if object: objects.append(object) delete_objects(objects=objects)
def clear_layer(layer): """ Deletes objects in given layer. Parameters: layer (int): Layer number. Returns: None """ delete_objects(get_objects(layer=layer))
def clear_vertices(self, keys=None): if not keys: keys = list(self.datastructure.vertices()) objects = [] for key in keys: name = self.datastructure.vertex_name(key) object = get_objects(name=name) if object: objects.append(object) name = 'V{0}'.format(key) object = get_objects(name=name) if object: objects.append(object) delete_objects(objects=objects)
def clear_layers(layers): """ Deletes objects in given layers. Parameters: layers (list, str): Layers or 'all'. Returns: None """ if layers == 'all': delete_all_objects() elif isinstance(layers, list): for layer in layers: delete_objects(get_objects(layer=layer))
def clear_collection(name: Text): """Clear the objects from a collection. Parameters ---------- name : str The name of the collection. Returns ------- None """ objects = list(bpy.data.collections[name].objects) if objects: delete_objects(objects)
def xdraw_pointcloud(points): """ Draw a set of points using Blender mesh vertices. Parameters: points (dic): {'pos':, 'name':, 'layer':}. Returns: list: Created point objects (bmeshes). """ objects = [] object = draw_bmesh('pt', vertices=[[0, 0, 0]]) for point in points: copy = object.copy() copy.name = point.get('name', 'point') copy.location = Vector(point.get('pos', [0, 0, 0])) copy.data = copy.data.copy() set_objects_layer([copy], point.get('layer', 0)) objects.append(copy) delete_objects([object]) for object in objects: bpy.context.scene.objects.link(object) deselect_all_objects() return objects
def xdraw_points(points): """ Draw a set of points (empties). Parameters: points (list): {'radius':, 'pos':, 'name':, 'layer':}. Returns: list: Created empty objects. """ objects = [] bpy.ops.object.empty_add(type='SPHERE', radius=1, location=[0, 0, 0]) object = bpy.context.object for point in points: copy = object.copy() copy.name = point.get('name', 'point') copy.location = Vector(point.get('pos', [0, 0, 0])) copy.scale *= point.get('radius', 1) set_objects_layer([copy], point.get('layer', 0)) objects.append(copy) delete_objects([object]) for object in objects: bpy.context.scene.objects.link(object) deselect_all_objects() return objects
def clear_layer(layer): objects = get_objects(layer=layer) if objects: delete_objects(objects=objects)
def clear_collection(name: Text): """Clear the objects from a collection.""" objects = list(bpy.data.collections[name].objects) if objects: delete_objects(objects)
def clear_collection(name): objects = list(bpy.data.collections[name].objects) if objects: delete_objects(objects)