Esempio n. 1
0
    def update_face_attributes(self, keys, names=None):
        if not names:
            names = self.default_face_attributes.keys()
        names = sorted(names)

        values = [self.facedata[keys[0]][name] for name in names]

        if len(keys) > 1:
            for i, name in enumerate(names):
                for key in keys[1:]:
                    if values[i] != self.facedata[key][name]:
                        values[i] = '-'
                        break

        values = map(str, values)
        values = compas_rhino.update_named_values(names, values)

        if values:
            for name, value in zip(names, values):
                if value != '-':
                    for key in keys:
                        try:
                            self.facedata[key][name] = ast.literal_eval(value)
                        except (ValueError, TypeError):
                            self.facedata[key][name] = value
            return True

        return False
Esempio n. 2
0
def mesh_update_attributes(mesh):
    """Update the attributes of a mesh.

    Parameters
    ----------
    mesh : :class:`compas.datastructures.Mesh`
        A mesh object.

    Returns
    -------
    bool
        ``True`` if the update was successful.
        ``False`` otherwise.

    See Also
    --------
    * :func:`mesh_update_vertex_attributes`
    * :func:`mesh_update_edge_attributes`
    * :func:`mesh_update_face_attributes`

    """
    names = sorted(mesh.attributes.keys())
    values = [str(mesh.attributes[name]) for name in names]
    values = compas_rhino.update_named_values(names, values)
    if values:
        for name, value in zip(names, values):
            try:
                mesh.attributes[name] = ast.literal_eval(value)
            except (ValueError, TypeError):
                mesh.attributes[name] = value
        return True
    return False
Esempio n. 3
0
    def update_vertex_attributes(cablenet, keys, names=None):
        if not names:
            names = cablenet.default_vertex_attributes.keys()
        names = sorted(names)
        values = [cablenet.vertex[keys[0]][name] for name in names]
        if len(keys) > 1:
            for i, name in enumerate(names):
                for key in keys[1:]:
                    if values[i] != cablenet.vertex[key][name]:
                        values[i] = '-'
                        break

        values = map(str, values)
        values = compas_rhino.update_named_values(names, values)

        if values:
            for name, value in zip(names, values):
                if value != '-':
                    for key in keys:
                        try:
                            value = literal_eval(value)
                        except (SyntaxError, ValueError, TypeError):
                            pass
                        cablenet.vertex_attribute(key, name, value)

            return True
        return False
Esempio n. 4
0
    def update_edge_attributes(self, keys, names=None):
        if not names:
            names = self.default_edge_attributes.keys()
        names = sorted(names)

        key = keys[0]
        values = self.get_edge_attributes(key, names)

        if len(keys) > 1:
            for i, name in enumerate(names):
                for key in keys[1:]:
                    if values[i] != self.get_edge_attribute(key, name):
                        values[i] = '-'
                        break

        values = map(str, values)
        values = compas_rhino.update_named_values(names, values)

        if values:
            for name, value in zip(names, values):
                if value != '-':
                    for key in keys:
                        try:
                            value = ast.literal_eval(value)
                        except (SyntaxError, ValueError, TypeError):
                            pass
                        self.set_edge_attribute(key, name, value)

            return True
        return False
Esempio n. 5
0
def update_mesh_vertex_attributes(mesh, keys, names=None):
    """Update the attributes of the vertices of a mesh.

    Parameters:
        mesh (compas.datastructures.mesh.Mesh): The mesh object.
        keys (tuple, list): The keys of the vertices to update.
        names (tuple, list): Optional. The names of the atrtibutes to update.
            Defaults to ``None``. If ``None``, all attributes are included in the
            update.

    Returns:
        bool: ``True`` if the update was successful, and ``False`` otherwise.

    Example:

        .. code-block:: python

            import compas
            import compas_rhino as rhino

            from compas.datastructures.mesh import Mesh

            mesh = Mesh.from_obj(compas.get_data('faces.obj'))

            keys = mesh.vertices()

            if compas_rhino.update_mesh_vertex_attributes(mesh, keys):
                print('mesh vertex attributes updated')
            else:
                print('mesh vertex attributes not updated')


    See Also:
        * :func:`update_mesh_attributes`
        * :func:`update_mesh_edge_attributes`
        * :func:`update_mesh_face_attributes`

    """
    if not names:
        names = mesh.default_vertex_attributes.keys()
    names = sorted(names)
    values = [mesh.vertex[keys[0]][name] for name in names]
    if len(keys) > 1:
        for i, name in enumerate(names):
            for key in keys[1:]:
                if values[i] != mesh.vertex[key][name]:
                    values[i] = '-'
                    break
    values = map(str, values)
    values = compas_rhino.update_named_values(names, values)
    if values:
        for name, value in zip(names, values):
            if value != '-':
                for key in keys:
                    try:
                        mesh.vertex[key][name] = ast.literal_eval(value)
                    except (TypeError, ValueError):
                        mesh.vertex[key][name] = value
        return True
    return False
Esempio n. 6
0
def RunCommand(is_interactive):

    if 'AGS' not in sc.sticky:
        compas_rhino.display_message('AGS has not been initialised yet.')
        return

    scene = sc.sticky['AGS']['scene']

    objects = scene.find_by_name('Form')
    if not objects:
        compas_rhino.display_message("There is no FormDiagram in the scene.")
        return
    form = objects[0]

    edges = list(form.diagram.edges_where({'is_ind': True}))

    if not len(edges):
        compas_rhino.display_message("""
None of the edges of the diagram are marked as "independent".
Forces can only be assigned to "independent" edges.
Please select the independent edges first.""")
        return

    form.settings['show.edgelabels'] = True
    form.settings['show.forcelabels'] = False
    scene.update()

    edge_index = form.diagram.edge_index()

    names = [edge_index[edge] for edge in edges]

    values = [str(form.diagram.edge_attribute(edge, 'f')) for edge in edges]
    values = compas_rhino.update_named_values(names,
                                              values,
                                              message='Independent edges.',
                                              title='Update force values.')

    if values:
        for edge, value in zip(edges, values):
            try:
                F = float(value)
            except (ValueError, TypeError):
                pass
            else:
                L = form.diagram.edge_length(*edge)
                Q = F / L
                form.diagram.edge_attribute(edge, 'f', F)
                form.diagram.edge_attribute(edge, 'q', Q)

        scene.update()
        scene.save()

    form.settings['show.edgelabels'] = False
    form.settings['show.forcelabels'] = True
    scene.update()
Esempio n. 7
0
 def update_attributes(self):
     names = sorted(self.attributes.keys())
     values = [str(self.attributes[name]) for name in names]
     values = compas_rhino.update_named_values(names, values)
     if values:
         for name, value in zip(names, values):
             try:
                 self.attributes[name] = ast.literal_eval(value)
             except (ValueError, TypeError):
                 self.attributes[name] = value
         return True
     return False
Esempio n. 8
0
def update_mesh_attributes(mesh):
    """Update the attributes of a mesh.

    Parameters:
        mesh (compas.datastructures.mesh.Mesh): The mesh object.

    Returns:
        bool: ``True`` if the update was successful, and ``False`` otherwise.

    Example:

        .. code-block:: python

            import compas
            import compas_rhino as rhino
            from compas.datastructures.mesh import Mesh

            mesh = Mesh.from_obj(compas.get_data('faces.obj'))

            if compas_rhino.update_mesh_attributes(mesh):
                print('mesh attributes updated')
            else:
                print('mesh attributres not updated')


    See Also:
        * :func:`update_mesh_vertex_attributes`
        * :func:`update_mesh_edge_attributes`
        * :func:`update_mesh_face_attributes`

    """
    names = sorted(mesh.attributes.keys())
    values = [str(mesh.attributes[name]) for name in names]
    values = compas_rhino.update_named_values(names, values)
    if values:
        for name, value in zip(names, values):
            try:
                mesh.attributes[name] = ast.literal_eval(value)
            except (TypeError, ValueError):
                mesh.attributes[name] = value
        return True
    return False
Esempio n. 9
0
def update_network_attributes(network):
    """Update the attributes of a network.

    Parameters:
        network (compas.datastructures.network.Network): The network object.

    Returns:
        bool: ``True`` if the update was successful, and ``False`` otherwise.

    Example:

        .. code-block:: python

            import compas
            import compas_rhino as compas_rhino
            from compas.datastructures.network import Network

            network = Network.from_obj(compas.get_data('lines.obj'))

            if compas_compas_rhino.update_network_attributes(network):
                print('network attributes updated')
            else:
                print('network attributres not updated')


    See Also:
        * :func:`update_network_vertex_attributes`
        * :func:`update_network_edge_attributes`
        * :func:`update_network_face_attributes`

    """
    names  = sorted(network.attributes.keys())
    values = [str(network.attributes[name]) for name in names]
    values = compas_rhino.update_named_values(names, values)
    if values:
        for name, value in zip(names, values):
            try:
                network.attributes[name] = ast.literal_eval(value)
            except (ValueError, TypeError):
                network.attributes[name] = value
        return True
    return False
Esempio n. 10
0
def update_network_edge_attributes(network, keys, names=None):
    """Update the attributes of the edges of a network.

    Parameters:
        network (compas.datastructures.network.Network): The network object.
        keys (tuple, list): The keys of the edges to update. Note that the keys
            should be pairs of vertex keys.
        names (tuple, list): Optional. The names of the atrtibutes to update.
            Defaults to ``None``. If ``None``, all attributes are included in the
            update.

    Returns:
        bool: ``True`` if the update was successful, and ``False`` otherwise.

    Example:

        .. code-block:: python

            import compas
            import compas_rhino as compas_rhino

            from compas.datastructures.network import Network

            network = Network.from_obj(compas.get_data('lines.obj'))

            keys = network.edges()

            if compas_compas_rhino.update_network_edge_attributes(network, keys):
                print('network edge attributes updated')
            else:
                print('network edge attributes not updated')


    See Also:
        * :func:`update_network_attributes`
        * :func:`update_network_vertex_attributes`
        * :func:`update_network_face_attributes`

    """
    if not names:
        names = network.default_edge_attributes.keys()
    names = sorted(names)
    u, v = keys[0]
    values = [network.edge[u][v][name] for name in names]
    if len(keys) > 1:
        for i, name in enumerate(names):
            for u, v in keys[1:]:
                if values[i] != network.edge[u][v][name]:
                    values[i] = '-'
                    break
    values = map(str, values)
    values = compas_rhino.update_named_values(names, values)
    if values:
        for name, value in zip(names, values):
            if value != '-':
                for u, v in keys:
                    try:
                        network.edge[u][v][name] = ast.literal_eval(value)
                    except (ValueError, TypeError):
                        network.edge[u][v][name] = value
        return True
    return False