def horizontal_nodal_xfunc(formdata, forcedata, *args, **kwargs): from compas_tna.diagrams import FormDiagram from compas_tna.diagrams import ForceDiagram form = FormDiagram.from_data(formdata) force = ForceDiagram.from_data(forcedata) horizontal_nodal(form, force, *args, **kwargs) return form.to_data(), force.to_data()
def horizontal_nodal_proxy(formdata, forcedata, *args, **kwargs): form = FormDiagram.from_data(formdata) force = ForceDiagram.from_data(forcedata) horizontal_nodal(form, force, *args, **kwargs) return form.to_data(), force.to_data()
def RunCommand(is_interactive): if 'TNA' not in sc.sticky: raise Exception("Initialise the plugin first!") TNA = sc.sticky['TNA'] form = TNA['form'] force = TNA['force'] settings = TNA['settings'] options = ['save', 'save_as', 'open'] option = rs.GetString("Initialise FormDiagram from", options[0], options) if not option: return if option == 'save': # save the current file in the current directory # get the components of the current filepath if not settings['file.dir']: file_dir = compas_rhino.select_folder(default=HERE) else: file_dir = compas_rhino.select_folder(default=settings['file.dir']) if not os.path.isdir(file_dir): print('The selected directory is invalid: {}'.format(file_dir)) return settings['file.dir'] = file_dir if not settings['file.name']: file_name = compas_rhino.select_file(folder=settings['file.dir']) if not file_name: print('The filename is invalid: {}'.format(file_name)) return settings['file.name'] = file_name file_name = settings['file.name'] if not file_name.endswith('.json'): print('The filename is invalid: {}'.format(file_name)) return # compile the filepath filepath = os.path.join(file_dir, file_name) # compile the data dict data = {'settings': settings} if form: data['form'] = form.to_data() if force: data['force'] = force.to_data() # write the data dict to the specified file with open(filepath, 'w') as f: json.dump(data, f) elif option == 'save_as': # save the current file using a different name and location # get the components of the current filepath if not settings['file.dir']: file_dir = compas_rhino.select_folder(default=HERE) else: file_dir = compas_rhino.select_folder(default=settings['file.dir']) settings['file.dir'] = file_dir if not os.path.isdir(file_dir): print('The selected directory is invalid: {}'.format(file_dir)) return file_name = rs.GetString('File name') if not file_name: print('The filename is invalid: {}'.format(file_name)) return if not file_name.endswith('.json'): print('The filename is invalid: {}'.format(file_name)) return settings['file.dir'] = file_dir settings['file.name'] = file_name if not file_name.endswith('.json'): print('The filename is invalid: {}'.format(file_name)) return # compile the filepath filepath = os.path.join(file_dir, file_name) data = {'settings': settings} if form: data['form'] = form.to_data() if force: data['force'] = force.to_data() with open(filepath, 'w') as f: json.dump(data, f) elif option == 'open': # open a specified file # and update the current file properties in the settings # get the dirname of the current filepath if not settings['file.dir']: filepath = compas_rhino.select_file( folder=HERE, filter='JSON files (*.json)|*.json||') else: filepath = compas_rhino.select_file( folder=settings['file.dir'], filter='JSON files (*.json)|*.json||') if not filepath: return file_dir = os.path.dirname(filepath) file_name = os.path.basename(filepath) settings['file.dir'] = file_dir settings['file.name'] = file_name if not file_name.endswith('.json'): print('The filename is invalid: {}'.format(file_name)) return # compile the filepath filepath = os.path.join(file_dir, file_name) compas_rhino.clear_layer(settings['layer.form']) compas_rhino.clear_layer(settings['layer.force']) with open(filepath, 'r') as f: data = json.load(f) settings.update(data['settings']) if 'form' in data and data['form']: form = FormDiagram.from_data(data['form']) form.draw(layer=settings['layer.form'], clear_layer=True, settings=settings) else: form = None if form and 'force' in data and data['force']: force = ForceDiagram.from_data(data['force']) force.draw(layer=settings['layer.force'], clear_layer=True) else: force = None del TNA['form'] del TNA['force'] TNA['form'] = form TNA['force'] = force TNA['settings'] = settings else: # any other options are invalid raise NotImplementedError
def RunCommand(is_interactive): if 'TNA' not in sc.sticky: raise Exception("Initialise the plugin first!") TNA = sc.sticky['TNA'] form = TNA['form'] force = TNA['force'] settings = TNA['settings'] options = ['save', 'save as', 'open'] option = rs.GetString("Initialise FormDiagram from", options[0], options) if not option: return if option == 'save': if not settings['file.dir']: file_dir = compas_rhino.select_folder(default=compas_tna.DATA) else: file_dir = settings['file.dir'] if not os.path.isdir(file_dir): return if not settings['file.name']: file_name = rs.GetString('File name') if not file_name: return else: file_name = settings['file.name'] if not file_name.endswith('.json'): file_name += '.json' filepath = os.path.join(file_dir, file_name) if not filepath: return data = {'settings': settings} if form: data['form'] = form.to_data() if force: data['force'] = force.to_data() with open(filepath, 'w') as f: json.dump(data, f) elif option == 'save as': file_dir = compas_rhino.select_folder(default=compas_tna.DATA) if not file_dir: return if not os.path.isdir(file_dir): return file_name = rs.GetString('File name') if not file_name: return if not file_name.endswith('.json'): file_name += '.json' settings['file.dir'] = file_dir settings['file.name'] = file_name filepath = os.path.join(file_dir, file_name) if not filepath: return data = {'settings': settings} if form: data['form'] = form.to_data() if force: data['force'] = force.to_data() with open(filepath, 'w') as f: json.dump(data, f) elif option == 'open': filepath = compas_rhino.select_file(folder=settings['file.dir'], filter='json') if not filepath: return compas_rhino.clear_layer(settings['layer.form']) compas_rhino.clear_layer(settings['layer.force']) with open(filepath, 'r') as f: data = json.load(f) settings.update(data['settings']) if 'form' in data: if data['form']: form = FormDiagram.from_data(data['form']) form.draw(layer=settings['layer.form'], clear_layer=True, settings=settings) else: form = None else: form = None if form: if 'force' in data: if data['force']: force = ForceDiagram.from_data(data['force']) force.draw(layer=settings['layer.force'], clear_layer=True) else: force = None else: force = None del TNA['form'] del TNA['force'] TNA['form'] = form TNA['force'] = force TNA['settings'] = settings else: raise NotImplementedError