コード例 #1
0
    def from_name(name):
        """Create a ``RhinoGeometry`` instance of the correct type based on a given object name.

        Parameters
        ----------
        name : str
            The name of the Rhino object.

        Returns
        -------
        RhinoPoint
            If the type of the Rhino object is ``rs.filter.point``.
        RhinoCurve
            If the type of the Rhino object is ``rs.filter.curve``.
        RhinoMesh
            If the type of the Rhino object is ``rs.filter.mesh``.
        RhinoSurface
            If the type of the Rhino object is ``rs.filter.surface``.

        Examples
        --------
        >>>

        """
        guids = compas_rhino.get_objects(name=name)
        if len(guids) > 1:
            raise NotImplementedError

        return RhinoGeometry.from_guid(guids[0])
コード例 #2
0
def display_mesh_face_normals(mesh,
                              display=True,
                              layer=None,
                              scale=1.0,
                              color=(0, 0, 255)):

    guids = compas_rhino.get_objects(
        name='{0}.face.normal.*'.format(mesh.attributes['name']))
    compas_rhino.delete_objects(guids)

    if not display:
        return

    lines = []

    for fkey in mesh.faces():
        normal = mesh.face_normal(fkey)
        start = mesh.face_center(fkey)
        end = [start[axis] + normal[axis] for axis in range(3)]
        name = '{0}.face.normal.{1}'.format(mesh.attributes['name'], fkey)

        lines.append({
            'start': start,
            'end': end,
            'name': name,
            'color': color,
            'arrow': 'end',
        })

    compas_rhino.xdraw_lines(lines, layer=layer, clear=False, redraw=True)
コード例 #3
0
 def color_interfaces(self, mode=0):
     """"""
     if mode == 0:
         return
     if mode == 1:
         color_compression = self.settings['color.force:compression']
         color_tension = self.settings['color.force:tension']
         resultants = []
         for key in self.assembly.edges():
             forces = self.assembly.edge_attribute(key, 'interface_forces')
             if not forces:
                 resultants.append(0)
                 continue
             R = 0
             for force in forces:
                 c = force['c_np']
                 t = force['c_nn']
                 f = c - t
                 R += f
             resultants.append(R)
         Rmax = max(resultants)
         Rmin = min(resultants)
         print(Rmax)
         print(Rmin)
         for index, key in enumerate(self.assembly.edges()):
             u, v = key
             name = "{}.interface.{}-{}".format(self.assembly.name, u, v)
             guids = compas_rhino.get_objects(name=name)
             if not guids:
                 continue
             guid = guids[0]
             R = resultants[index]
             color = i_to_blue((R - Rmin) / (Rmax - Rmin))
             compas_rhino.rs.ObjectColor(guid, color)
コード例 #4
0
def find_constraint(name):
    rail = None
    if name:
        guids = compas_rhino.get_objects(name=name)
        if len(guids) == 1:
            otype = rs.ObjectType(guids[0])
            if otype == rs.filter.curve:
                rail = find_object(guids[0])
    return rail
コード例 #5
0
ファイル: meshartist.py プロジェクト: yishizu/compas
    def clear_facenormals(self, keys=None):
        """Clear the all previously drawn face normals.

        Parameters
        ----------
        keys : list, optional
            The keys of a specific set of faces of which the normals should be cleared.
            Default is to clear the normals of all faces.

        """
        if not keys:
            name = '{}.face.normal.*'.format(self.mesh.name)
            guids = compas_rhino.get_objects(name=name)
        else:
            guids = []
            for key in keys:
                name = '{}.face.normal.{}'.format(self.mesh.name, key)
                guids += compas_rhino.get_objects(name=name)
        compas_rhino.delete_objects(guids)
コード例 #6
0
ファイル: meshartist.py プロジェクト: yishizu/compas
    def clear_edgelabels(self, keys=None):
        """Clear all previously drawn edge labels.

        Parameters
        ----------
        keys : list, optional
            The keys of a specific set of edges of which the labels should be cleared.
            Default is to clear all edge labels.

        """
        if not keys:
            name = '{}.edge.label.*'.format(self.mesh.name)
            guids = compas_rhino.get_objects(name=name)
        else:
            guids = []
            for u, v in keys:
                name = '{}.edge.label.{}-{}'.format(self.mesh.name, u, v)
                guids += compas_rhino.get_objects(name=name)
        compas_rhino.delete_objects(guids)
コード例 #7
0
ファイル: meshartist.py プロジェクト: yishizu/compas
    def clear_vertexlabels(self, keys=None):
        """Clear all previously drawn vertex labels.

        Parameters
        ----------
        keys : list, optional
            The keys of a specific set of vertex labels that should be cleared.
            Default is to clear all vertex labels.

        """
        if not keys:
            name = '{}.vertex.label.*'.format(self.mesh.name)
            guids = compas_rhino.get_objects(name=name)
        else:
            guids = []
            for key in keys:
                name = '{}.vertex.label.{}'.format(self.mesh.name, key)
                guids += compas_rhino.get_objects(name=name)
        compas_rhino.delete_objects(guids)
コード例 #8
0
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
コード例 #9
0
    def clear_mesh(self):
        """Delete the mesh drawn by this artist.

        Returns
        -------
        None

        """
        guids = compas_rhino.get_objects(name="{}.mesh".format(self.mesh.name))
        compas_rhino.delete_objects(guids, purge=True)
コード例 #10
0
    def clear_nodes(self, keys=None):
        """Clear all previously drawn nodes.

        Parameters
        ----------
        keys : list, optional
            The keys of a specific set of nodes that should be cleared.
            Default is to clear all nodes.

        """
        if not keys:
            name = '{}.node.*'.format(self.network.name)
            guids = compas_rhino.get_objects(name=name)
        else:
            guids = []
            for key in keys:
                name = '{}.node.{}'.format(self.network.name, key)
                guids += compas_rhino.get_objects(name=name)
        compas_rhino.delete_objects(guids)
コード例 #11
0
ファイル: helpers.py プロジェクト: edwardyanxin/compas-RV2
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
コード例 #12
0
ファイル: networkartist.py プロジェクト: compas-dev/compas
    def clear(self):
        """Delete all objects drawn by this artist.

        Returns
        -------
        None

        """
        guids = compas_rhino.get_objects(name="{}.*".format(self.network.name))
        compas_rhino.delete_objects(guids, purge=True)
コード例 #13
0
ファイル: edgeartist.py プロジェクト: tclim/compas
 def clear_edges(self, keys=None):
     if not keys:
         name = '{}.edge.*'.format(self.datastructure.name)
         guids = compas_rhino.get_objects(name=name)
     else:
         guids = []
         for u, v in keys:
             name = self.datastructure.edge_name(u, v)
             guid = compas_rhino.get_object(name=name)
             guids.append(guid)
     compas_rhino.delete_objects(guids)
コード例 #14
0
    def clear_vertices(self):
        """Delete all vertices drawn by this artist.

        Returns
        -------
        None

        """
        guids = compas_rhino.get_objects(
            name="{}.vertex.*".format(self.mesh.name))
        compas_rhino.delete_objects(guids, purge=True)
コード例 #15
0
 def clear_vertices(self, keys=None):
     if not keys:
         name = '{}.vertex.*'.format(self.mesh.attributes['name'])
         guids = compas_rhino.get_objects(name=name)
     else:
         guids = []
         for key in keys:
             name = '{}.vertex.{}'.format(self.attributes['name'], key)
             guid = compas_rhino.get_object(name=name)
             guids.append(guid)
     compas_rhino.delete_objects(guids)
コード例 #16
0
ファイル: helpers.py プロジェクト: edwardyanxin/compas-RV2
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
コード例 #17
0
 def clear_edges(self, keys=None):
     if not keys:
         name = '{}.edge.*'.format(self.mesh.attributes['name'])
         guids = compas_rhino.get_objects(name=name)
     else:
         guids = []
         for u, v in keys:
             name = '{}.edge.{}-{}'.format(self.attributes['name'], u, v)
             guid = compas_rhino.get_object(name=name)
             guids.append(guid)
     compas_rhino.delete_objects(guids)
コード例 #18
0
 def clear_vertexlabels(self, keys=None):
     if not keys:
         name = '{}.vertex.label.*'.format(self.datastructure.name)
         guids = compas_rhino.get_objects(name=name)
     else:
         guids = []
         for key in keys:
             name = self.datastructure.vertex_label_name(key)
             guid = compas_rhino.get_object(name=name)
             guids.append(guid)
     compas_rhino.delete_objects(guids)
コード例 #19
0
    def clear_facelabels(self):
        """Delete all face labels drawn by this artist.

        Returns
        -------
        None

        """
        guids = compas_rhino.get_objects(
            name="{}.facelabel.*".format(self.mesh.name))
        compas_rhino.delete_objects(guids, purge=True)
コード例 #20
0
    def from_name(name):
        """Create a ``RhinoGeometry`` instance of the correct type based on a given object name.

        Parameters
        ----------
        name : str
            The name of the Rhino object.

        Returns
        -------
        RhinoPoint
            If the type of the Rhino object is ``rs.filter.point``.
        RhinoCurve
            If the type of the Rhino object is ``rs.filter.curve``.
        RhinoMesh
            If the type of the Rhino object is ``rs.filter.mesh``.
        RhinoSurface
            If the type of the Rhino object is ``rs.filter.surface``.

        Examples
        --------
        .. code-block:: python

            import compas
            import compas_rhino

            from compas.datastructures import Mesh
            from compas_rhino.geometry import RhinoGeometry

            mesh = Mesh.from_json(...)

            mesh.update_default_vertex_attributes(constraint=None)

            # interesting stuff happens here

            for key, attr in mesh.vertices(True):
                name = attr['constraint']

                if name:
                    constraint = RhinoGeometry.from_name(name)
                    xyz = constraint.closest_point(mesh.get_vertex_attributes(key, 'xyz'))
                    mesh.set_vertex_attributes(key, 'xyz', xyz)

            # more interesting stuff happens here

        """
        guids = compas_rhino.get_objects(name=name)
        if len(guids) > 1:
            raise NotImplementedError

        return RhinoGeometry.from_guid(guids[0])
コード例 #21
0
def network_draw_axial_forces(network, scale=0.1, layer=None, clear_layer=False):
    cylinders = []
    for u, v, attr in network.edges(True):
        if attr['f'] > 0.0:
            cylinders.append({
                'start' : network.vertex_coordinates(u),
                'end'   : network.vertex_coordinates(v),
                'radius': scale * 3.14159 * attr['f'] ** 2,
                'name'  : '{}.axial.{}-{}'.format(network.name, u, v),
                'color' : (255, 0, 0),
            })
    guids = compas_rhino.get_objects(name='{}.axial.*'.format(network.name))
    compas_rhino.delete_objects(guids)
    compas_rhino.xdraw_cylinders(cylinders, layer=layer, clear=clear_layer)
コード例 #22
0
ファイル: network.py プロジェクト: dtbinh/T1_python-exercises
def move_network(network):
    """Move the entire network.

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

    """
    color  = Rhino.ApplicationSettings.AppearanceSettings.FeedbackColor
    origin = {key: network.vertex_coordinates(key) for key in network.vertices()}
    vertex = {key: network.vertex_coordinates(key) for key in network.vertices()}
    edges  = network.edges()
    start  = compas_rhino.pick_point('Point to move from?')

    if not start:
        return

    def OnDynamicDraw(sender, e):
        current = list(e.CurrentPoint)
        vec = [current[i] - start[i] for i in range(3)]
        for key in vertex:
            vertex[key] = [origin[key][i] + vec[i] for i in range(3)]
        for u, v in iter(edges):
            sp = vertex[u]
            ep = vertex[v]
            sp = Point3d(*sp)
            ep = Point3d(*ep)
            e.Display.DrawDottedLine(sp, ep, color)

    guids = compas_rhino.get_objects(name='{0}.*'.format(network.attributes['name']))
    compas_rhino.delete_objects(guids, False)

    gp = Rhino.Input.Custom.GetPoint()
    gp.SetCommandPrompt('Point to move to?')
    gp.DynamicDraw += OnDynamicDraw
    gp.Get()

    if gp.CommandResult() == Rhino.Commands.Result.Success:
        end = list(gp.Point())
        vec = [end[i] - start[i] for i in range(3)]
        for key, attr in network.vertices(True):
            attr['x'] += vec[0]
            attr['y'] += vec[1]
            attr['z'] += vec[2]

    try:
        network.draw()
    except AttributeError:
        # this may result in the network being drawn in a different layer then before
        draw_network(network)
コード例 #23
0
def draw_mesh_as_faces(mesh,
                       layer=None,
                       clear_layer=False,
                       facecolor=None,
                       redraw=True):

    guids = compas_rhino.get_objects(
        name='{0}.*'.format(mesh.attributes['name']))
    compas_rhino.delete_objects(guids)

    if clear_layer:
        if not layer:
            compas_rhino.clear_current_layer()
        else:
            compas_rhino.clear_layer(layer)

    facecolor = facecolor or {}

    meshes = []

    for fkey in mesh.faces():
        vertices = mesh.face_coordinates(fkey)
        faces = [range(len(vertices))]
        color = facecolor.get(fkey, (255, 255, 255))
        guid = compas_rhino.xdraw_mesh(vertices,
                                       faces,
                                       None,
                                       '{0}.face.{1}'.format(
                                           mesh.attributes['name'], fkey),
                                       layer=layer,
                                       clear=False,
                                       redraw=False)
        compas_rhino.set_mesh_vertex_colors(
            guid, [color for i in range(len(vertices))])
        meshes.append(guid)

    if layer:
        previous = rs.CurrentLayer(layer)

    guid = rs.JoinMeshes(meshes, delete_input=True)

    if layer:
        rs.CurrentLayer(previous)

    rs.ObjectName(guid, '{0}'.format(mesh.attributes['name']))

    rs.EnableRedraw()
    rs.Redraw()
コード例 #24
0
def network_draw_loads(network, scale=1.0, layer=None, clear_layer=False):
    lines = []
    for key, attr in network.vertices(True):
        if not attr['is_fixed']:
            force = attr['px'], attr['py'], attr['pz']
            start = network.vertex_coordinates(key)
            end = [start[axis] + scale * force[axis] for axis in (0, 1, 2)]
            lines.append({
                'start': start,
                'end'  : end,
                'name' : '{}.load.{}'.format(network.name, key),
                'color': (0, 255, 255),
                'arrow': 'end',
            })
    guids = compas_rhino.get_objects(name='{}.load.*'.format(network.name))
    compas_rhino.delete_objects(guids)
    compas_rhino.xdraw_lines(lines, layer=layer, clear=clear_layer)
コード例 #25
0
    def clear_facenormals(self, keys=None):
        """Clear the normals of all faces previously drawn by the ``FaceArtist``.

        Parameters
        ----------
        keys : list, optional
            The keys of a specific set of faces of which the normals should be cleared.
            Default is to clear the normals of all faces.

        """
        if not keys:
            name = '{}.face.normal.*'.format(self.datastructure.name)
            guids = compas_rhino.get_objects(name=name)
        else:
            guids = []
            for key in keys:
                name = self.datastructure.face_name(key)
                guid = compas_rhino.get_object(name=name)
                guids.append(guid)
        compas_rhino.delete_objects(guids)
コード例 #26
0
    def clear_edges(self, keys=None):
        """Clear all edges previously drawn by the ``EdgeArtist``.

        Parameters
        ----------
        keys : list, optional
            The keys of a specific set of edges that should be cleared.
            Default is to clear all edges.

        """
        if not keys:
            name = '{}.edge.*'.format(self.datastructure.name)
            guids = compas_rhino.get_objects(name=name)
        else:
            guids = []
            for u, v in keys:
                name = self.datastructure.edge_name(u, v)
                guid = compas_rhino.get_object(name=name)
                guids.append(guid)
        compas_rhino.delete_objects(guids)
コード例 #27
0
    def clear_vertexlabels(self, keys=None):
        """Clear all vertex labels previously drawn by the ``VertexArtist``.

        Parameters
        ----------
        keys : list, optional
            The keys of a specific set of vertex labels that should be cleared.
            Default is to clear all vertex labels.

        """
        if not keys:
            name = '{}.vertex.label.*'.format(self.datastructure.name)
            guids = compas_rhino.get_objects(name=name)
        else:
            guids = []
            for key in keys:
                name = self.datastructure.vertex_label_name(key)
                guid = compas_rhino.get_object(name=name)
                guids.append(guid)
        compas_rhino.delete_objects(guids)
コード例 #28
0
ファイル: meshartist.py プロジェクト: mpopescu/compas
    def clear_normals(self, keys=None):
        """Clear all normals previously drawn by the ``MeshArtist``.

        Parameters
        ----------
        keys : list, optional
            The keys of a specific set of normals that should be cleared.
            Default is to clear all normals.

        """
        if not keys:
            name = '{}.normal.*'.format(self.mesh.name)
            guids = compas_rhino.get_objects(name=name)
        else:
            guids = []
            for key in keys:
                name = '{}.normal.{}'.format(self.mesh.name, key)
                guid = compas_rhino.get_object(name=name)
                guids.append(guid)
        compas_rhino.delete_objects(guids)
コード例 #29
0
ファイル: network.py プロジェクト: dtbinh/T1_python-exercises
def display_network_residual_forces(network,
                                    display=True,
                                    layer=None,
                                    clear_layer=False,
                                    scale=1.0,
                                    color=(0, 255, 255),
                                    attr_name='is_anchor'):

    tol = compas_rhino.get_tolerance()
    guids = compas_rhino.get_objects(name='{0}.force:residual.*'.format(network.attributes['name']))
    compas_rhino.delete_objects(guids)

    if not display:
        return

    lines = []

    for key, attr in network.vertices(True):

        if attr[attr_name]:
            continue

        force  = attr['rx'], attr['ry'], attr['rz']
        start  = network.vertex_coordinates(key)
        end    = [start[i] + scale * force[i] for i in range(3)]
        length = distance_point_point(start, end)
        arrow  = 'end'
        name   = '{0}.force:residual.{1}'.format(network.attributes['name'], key)

        if length < tol:
            continue

        lines.append({
            'start' : start,
            'end'   : end,
            'name'  : name,
            'color' : color,
            'arrow' : arrow,
        })

    compas_rhino.xdraw_lines(lines, layer=layer, clear=clear_layer)
コード例 #30
0
    def draw_reactions(self, scale=1.0, color=None):
        compas_rhino.delete_objects(
            compas_rhino.get_objects(
                name="{}.reaction.*".format(self.mesh.name)))

        color = color or (0, 255, 0)
        lines = []
        for key, attr in self.mesh.vertices(True):
            if not attr['is_anchor']:
                continue

            r = [attr['rx'], attr['ry'], attr['rz']]
            sp = [attr['x'], attr['y'], attr['z']]
            ep = add_vectors(sp, scale_vector(r, -scale))

            lines.append({
                'start': sp,
                'end': ep,
                'color': color,
                'name': "{}.reaction.{}".format(self.mesh.name, key),
                'arrow': 'end'
            })

        compas_rhino.xdraw_lines(lines, layer=self.layer, redraw=True)