예제 #1
0
파일: manager.py 프로젝트: Antr0py/FreeCAD
def run_analysis(doc, base_name, filepath=""):

    from os.path import join, exists
    from os import makedirs
    from tempfile import gettempdir as gettmp

    # recompute
    doc.recompute()

    # print(doc.Objects)
    # print([obj.Name for obj in doc.Objects])

    # filepath
    if filepath is "":
        filepath = join(gettmp(), "FEM_examples")
    if not exists(filepath):
        makedirs(filepath)

    # find solver
    # ATM we only support one solver, search for a frame work solver and run it
    for m in doc.Analysis.Group:
        from femtools.femutils import is_derived_from
        if (
            is_derived_from(m, "Fem::FemSolverObjectPython")
            and m.Proxy.Type is not "Fem::FemSolverCalculixCcxTools"
        ):
            solver = m
            break

    # we need a file name for the besides dir to work
    save_fc_file = join(filepath, (base_name + ".FCStd"))
    FreeCAD.Console.PrintMessage(
        "Save FreeCAD file for {} analysis to {}\n.".format(base_name, save_fc_file)
    )
    doc.saveAs(save_fc_file)

    # get analysis workig dir
    from femtools.femutils import get_beside_dir
    working_dir = get_beside_dir(solver)

    # run analysis
    from femsolver.run import run_fem_solver
    run_fem_solver(solver, working_dir)

    # save doc once again with results
    doc.save()
예제 #2
0
파일: manager.py 프로젝트: tomate44/FreeCAD
def run_analysis(doc, base_name, filepath=''):

    from os.path import join, exists
    from os import makedirs
    from tempfile import gettempdir as gettmp

    # recompute
    doc.recompute()

    # print(doc.Objects)
    # print([obj.Name for obj in doc.Objects])

    # filepath
    if filepath is '':
        filepath = join(gettmp(), 'FEM_examples')
    if not exists(filepath):
        makedirs(filepath)

    # find solver
    # ATM we only support one solver, search for a frame work solver and run it
    for m in doc.Analysis.Group:
        from femtools.femutils import is_derived_from
        if is_derived_from(m, "Fem::FemSolverObjectPython") and m.Proxy.Type is not 'Fem::FemSolverCalculixCcxTools':
            solver = m
            break

    # we need a file name for the besides dir to work
    save_fc_file = join(filepath, (base_name + '.FCStd'))
    FreeCAD.Console.PrintMessage('Save FreeCAD file for {} analysis to {}\n.'.format(base_name, save_fc_file))
    doc.saveAs(save_fc_file)

    # get analysis workig dir
    from femsolver.run import _getBesideDir as getpath
    working_dir = getpath(solver)

    # run analysis
    from femsolver.run import run_fem_solver
    run_fem_solver(solver, working_dir)

    # save doc once again with results
    doc.save()