def match_vertices(diagram, keys): temp = compas_rhino.get_objects(name="{}.vertex.*".format(diagram.name)) names = compas_rhino.get_object_names(temp) guids = [] for guid, name in zip(temp, names): parts = name.split('.') key = literal_eval(parts[2]) if key in keys: guids.append(guid) return guids
def match_faces(cablenet, keys): temp = compas_rhino.get_objects(name="{}.face.*".format(cablenet.name)) names = compas_rhino.get_object_names(temp) guids = [] for guid, name in zip(temp, names): parts = name.split('.') key = literal_eval(parts[2]) if key in keys: guids.append(guid) return guids
def match_edges(diagram, keys): temp = compas_rhino.get_objects(name="{}.edge.*".format(diagram.name)) names = compas_rhino.get_object_names(temp) guids = [] for guid, name in zip(temp, names): parts = name.split('.')[2].split('-') u = literal_eval(parts[0]) v = literal_eval(parts[1]) if (u, v) in keys or (v, u) in keys: guids.append(guid) return guids
def update_network_from_points(network, guids): points = compas_rhino.get_point_coordinates(guids) names = compas_rhino.get_object_names(guids) gkey_key = {geometric_key(network.vertex_coordinates(key)): key for key in network} for i, xyz in enumerate(points): name = names[i] try: attr = ast.literal_eval(name) except ValueError: pass else: gkey = geometric_key(xyz) if gkey in gkey_key: key = gkey_key[gkey] network.vertex[key].update(attr)
def add_blocks_from_rhinomeshes(self, guids): """Add multiple blocks from their representation as as Rhino meshes. Parameters ---------- guids : list of str A list of GUIDs identifying the meshes representing the blocks of the assembly. Returns ------- list The keys of the added blocks. Warning ------- This method only works in Rhino. Examples -------- .. code-block:: python assembly = Assembly() guids = compas_rhino.select_meshes() assembly.add_blocks_from_rhinomeshes(guids) """ from compas_assembly.datastructures import Block onames = compas_rhino.get_object_names(guids) keys = [] for i, (guid, oname) in enumerate(zip(guids, onames)): try: attr = ast.literal_eval(oname) except (TypeError, ValueError): attr = {} name = attr.get('name', 'B{0}'.format(i)) block = Block.from_rhinomesh(guid) block.attributes['name'] = name key = self.add_block(block, attr_dict=attr) keys.append(key) return keys
def update_network_from_lines(network, guids): lines = compas_rhino.get_line_coordinates(guids) names = compas_rhino.get_object_names(guids) gkey_key = {geometric_key(network.vertex_coordinates(key)): key for key in network} for i, (sp, ep) in enumerate(lines): name = names[i] try: attr = ast.literal_eval(name) except ValueError: pass else: a = geometric_key(sp) b = geometric_key(ep) if a in gkey_key and b in gkey_key: u = gkey_key[a] v = gkey_key[b] if v in network.edge[u]: network.edge[u][v].update(attr) else: network.edge[v][u].update(attr)
import compas_rhino from compas.utilities import geometric_key from fofin.shell import Shell from fofin.shellartist import ShellArtist # ============================================================================== # Input # ============================================================================== guids = compas_rhino.select_lines() lines = compas_rhino.get_line_coordinates(guids) guids = compas_rhino.select_points() points = compas_rhino.get_point_coordinates(guids) names = compas_rhino.get_object_names(guids) # ============================================================================== # Shell # ============================================================================== shell = Shell.from_lines(lines, delete_boundary_face=True) # ============================================================================== # Geometric key map # ============================================================================== gkey_key = shell.gkey_key() # ============================================================================== # Vertex attributes