Path: blob/devel/ElmerWorkflows/FreeCADBatchFEMTools/tests/cubemeshtest/cubemeshtest.py
3206 views
import argparse1import os2import subprocess34description = 'Writes parameters to file cubemeshtestparameters.txt and runs cubemeshtest_freecadscript.py with FreeCAD.'5description += ' Edge length of cube is 200 (diameter 200 with spheres). Distance between two cubes (spheres) is 20.'67ps_help = 'Is points used for finding boundaries and solids (section and common search otherwise)'8af_help = 'Appends execution times to file cubemeshtestexecutiontimes.txt if used'910parser = argparse.ArgumentParser(description=description)11parser.add_argument('-n', '--number_of_cubes', type=int, required=True)12parser.add_argument('-m', '--cube_mesh_size', type=float, default=50.0)13parser.add_argument('-fb', '--find_boundaries', action='store_true')14parser.add_argument('-fs', '--find_solids', action='store_true')15parser.add_argument('-ca', '--create_air', action='store_true', help='Is air created around cubes')16parser.add_argument('-am', '--air_mesh_size', type=float, help='If not given cube_mesh_size is used')17parser.add_argument('-ps', '--point_search', action='store_true', help=ps_help)18parser.add_argument('-s', '--spheres', action='store_true', help='Use spheres instead of cubes')19parser.add_argument('-af', '--append_file', action='store_true', help=af_help)20parser.add_argument('-fe', '--freecad-executable', type=str, default="FreeCAD", help='give the path to FreeCAD executable')2122args = parser.parse_args()2324directory = os.path.dirname(os.path.realpath(__file__))25freecadscript_name = os.path.join(directory, 'cubemeshtest_freecadscript.py')26if not os.path.isfile(freecadscript_name):27print("cubemeshtest_freecadscript.py does not exist, check that you are in correct directory")28else:29with open(os.path.join(directory, 'cubemeshtestparameters.txt'), 'w') as f:30f.write('{} {} {} {} {} {} {} {} {}'.format(args.number_of_cubes, args.cube_mesh_size, args.find_boundaries,31args.find_solids, args.create_air, args.air_mesh_size,32args.point_search, args.spheres, args.append_file))33try:34p = subprocess.Popen([args.freecad_executable, '-c', freecadscript_name])35p.communicate()36except Exception:37print("Running FreeCAD failed!!! Try to give the correct FreeCAD executable as an argument (--freecad-executable, -fe)")383940