예제 #1
0
    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
from compas.datastructures import mesh_weld
from compas_assembly.datastructures import Assembly
from compas_assembly.datastructures import Block
from compas_rhino.utilities import get_meshes

# get support meshes and block meshes from Rhino
rhino_supports = get_meshes("Supports")
rhino_blocks = get_meshes("Blocks")

#  create and weld compas meshes
supports = []
for i in rhino_supports:
    support = Block.from_rhinomesh(i)
    support = mesh_weld(support)
    supports.append(support)

blocks = []
for i in rhino_blocks:
    block = Block.from_rhinomesh(i)
    block = mesh_weld(block)
    blocks.append(block)

# create an assembly
assembly = Assembly()

for i in supports:
    assembly.add_block(i, is_support=True)
for i in blocks:
    assembly.add_block(i, is_support=False)

# export the assembly in a .json file