示例#1
0
 def assembly_from_json(self):
     path = compas_rhino.select_file(folder=compas_rbe.DATA,
                                     filter='JSON files (*.json)|*.json||')
     if not path:
         return
     self.assembly = assembly = Assembly.from_json(path)
     self.assembly.draw(self.settings['layer'])
def RunCommand(is_interactive):
    try:
        if 'compas_assembly' not in sc.sticky:
            raise Exception('Initialise the Assembly plugin first!')

        path = compas_rhino.select_file(folder=SESSIONS,
                                        filter='JSON files (*.json)|*.json||')
        if not path:
            return

        with open(path, 'r') as fo:
            session = json.load(fo)

        if 'blocks' not in session:
            raise Exception('Session data is incomplete.')
        if 'assembly' not in session:
            raise Exception('Session data is incomplete.')
        if 'settings' not in session:
            raise Exception('Session data is incomplete.')

        sc.sticky['compas_assembly']['settings'].update(session['settings'])
        settings = sc.sticky['compas_assembly']['settings']

        assembly = Assembly.from_data(session['assembly'])
        assembly.blocks = {
            key: Block.from_data(data)
            for key, data in session['blocks'].items()
        }
        assembly.draw(settings)

        sc.sticky['compas_assembly']['assembly'] = assembly

    except Exception as error:
        print(error)
        print(traceback.format_exc())
示例#3
0
def convert(source, destination):

    assembly = Assembly()

    with open(source, 'r') as fo:
        data = json.load(fo)
        for item in data:
            for fkey, cycle in item['face'].items():
                start = list(cycle.keys())[0]
                key = cycle[start]
                item['face'][fkey] = [start]
                while True:
                    if key == start:
                        break
                    item['face'][fkey].append(key)
                    key = cycle[key]
            block = Block.from_data(item)
            assembly.add_block(block)

    for key, attr in assembly.vertices(True):
        if assembly.blocks[key].attributes['name'] == 'Block_0':
            attr['is_support'] = True

    assembly.to_json(destination)
示例#4
0
# # for rhinomac

# assembly_interfaces.paths  = [compas_rbe.SRC]
# compute_interface_forces.paths  = [compas_rbe.SRC]

# mypython = "/Users/vanmelet/anaconda3/bin/python"

# assembly_interfaces.python = mypython
# compute_interface_forces.python = mypython


# ==============================================================================
# initialise assembly from stored block data
# ==============================================================================

assembly = Assembly()

# read block geometry data from sample json file

filepath = compas_rbe.get('simple_stack2.json')

with open(filepath, 'r') as fp:
    data = json.load(fp)

    for item in data:

        # simple_stack2.json still uses a dict of half-edges to represent a face
        # instead of simple lists
        for fkey, cycle in item['face'].items():
            start = list(cycle.keys())[0]
            key = cycle[start]
示例#5
0
from compas.utilities import XFunc

from compas_rbe.datastructures import Assembly

from compas_rbe.rhino import AssemblyArtist
from compas_rbe.rhino import AssemblyHelper


assembly_interfaces = XFunc('compas_rbe.interfaces.assembly_interfaces_xfunc', tmpdir=compas_rbe.TEMP)
compute_interface_forces = XFunc('compas_rbe.equilibrium.compute_interface_forces_xfunc', tmpdir=compas_rbe.TEMP)


# initialize assembly and blocks from json file

assembly = Assembly.from_json(compas_rbe.get('simple_stack_4.json'))

# identify block interfaces and update block_model

data = {
    'assembly': assembly.to_data(),
    'blocks'  : {str(key): assembly.blocks[key].to_data() for key in assembly.blocks},
}

result = assembly_interfaces(data, nmax=10, tmax=0.05, amin=0.01, lmin=0.01)

assembly.data = result['assembly']

for key in assembly.blocks:
    assembly.blocks[key].data = result['blocks'][str(key)]
assembly_interfaces = XFunc('compas_rbe.interfaces.assembly_interfaces_xfunc', tmpdir=compas_rbe.TEMP)
compute_interface_forces = XFunc('compas_rbe.equilibrium.compute_interface_forces_xfunc', tmpdir=compas_rbe.TEMP)

# ==============================================================================
# make an artist
# ==============================================================================

artist = AssemblyArtist(None, layer='RBE')
artist.clear_layer()

# ==============================================================================
# initialise assembly from Rhino geometry
# ==============================================================================

guids = compas_rhino.select_meshes()
assembly = Assembly.from_meshes(guids)

artist.assembly = assembly

# ==============================================================================
# draw blocks
# ==============================================================================

artist.draw_blocks()
artist.draw_vertices(color={key: '#ff0000' for key in assembly.vertices_where({'is_support': True})})

artist.redraw()

# ==============================================================================
# identify block interfaces
# ==============================================================================
示例#7
0
    'compas_rbe.equilibrium.compute_interfaceforces_xfunc')
compute_interface_forces.tmpdir = compas_rbe.TEMP

# ==============================================================================
# make an artist
# ==============================================================================

artist = AssemblyArtist(None, layer='RBE')
artist.clear_layer()

# ==============================================================================
# initialise assembly from Rhino geometry
# ==============================================================================

guids = compas_rhino.select_surfaces()
assembly = Assembly.from_polysurfaces(guids)

artist.assembly = assembly

# ==============================================================================
# draw blocks
# ==============================================================================

artist.draw_blocks()
artist.draw_vertices(color={
    key: '#ff0000'
    for key in assembly.vertices_where({'is_support': True})
})

artist.redraw()