OSArch Community

BIMTester call it from Python

  1. B

    To call BIMTester language examples from Pyhton I use the code attached.

    Ist it possible to retrieve the args dictionary from the cli.py module by Python? I would just need to set the ifc and feature afterwards.

    
    from os.path import join
    
    ifcos_main_path = join("the_path_to_ifcos_repo") 
    
    ifcbimtester_path = join(ifcos_main_path, "src", "ifcbimtester")
    
    examples_path = join(ifcbimtester_path, "examples", "01_ifcschema_translated")
    
    #feature_file_name = "de_grundlagen"
    
    #feature_file_name = "en_base"
    
    #feature_file_name = "fr_fondamentaux"
    
    feature_file_name = "it_fondamento"
    
    #feature_file_name = "nl_grondslag"
    
    
    args = {
    
        "action": "",
    
        "advanced_arguments": "",
    
        "console": True,
    
        "feature": join(examples_path, "features", feature_file_name + ".feature"),
    
        "ifc": join(examples_path, "IFC2X3_col.ifc"),
    
        "path": "",
    
        "report": "",
    
        "steps": "",
    
        "schema_file": "",
    
        "schema_name": "",
    
        "lang": "",
    
    }
    
    
    import sys
    
    sys.path.append(ifcbimtester_path)
    
    import bimtester.run
    
    import bimtester.reports
    
    report_json = bimtester.run.TestRunner(args["ifc"], args["schema_file"]).run(args)
    
    # bimtester.reports.ReportGenerator().generate(report_json, join(ifcos_main_path, "report.html"))
    
    

    might be related:

    https://stackoverflow.com/questions/31090479/python-argparse-pass-values-without-command-line

  2. B
  3. B

    update the code ...

    open a git shell

    
    cd /c/Users/BHA/Desktop
    
    git clone https://github.com/IfcOpenShell/IfcOpenShell/
    
    

    in a Python shell, works in FreeCAD Python console too, but some modules need to be installed before.

    
    import os
    
    from os.path import join
    
    ifcos_main_path = join("C:", os.sep, "Users", "BHA", "Desktop", "IfcOpenShell") 
    
    ifcbimtester_path = join(ifcos_main_path, "src", "ifcbimtester")
    
    examples_path = join(ifcbimtester_path, "examples", "01_ifcschema_translated")
    
    feature_file_name = "de_grundlagen"
    
    #feature_file_name = "en_base"
    
    #feature_file_name = "fr_fondamentaux"
    
    #feature_file_name = "it_fondamento"
    
    #feature_file_name = "nl_grondslag"
    
    
    args = {
    
        "action": "",
    
        "advanced_arguments": "",
    
        "console": False,
    
        "feature": join(examples_path, "features", feature_file_name + ".feature"),
    
        "ifc": join(examples_path, "IFC2X3_col.ifc"),
    
        "path": "",
    
        "report": "",
    
        "steps": "",
    
        "schema_file": "",
    
        "schema_name": "",
    
        "lang": "",
    
    }
    
    
    import sys
    
    sys.path.append(ifcbimtester_path)
    
    import bimtester.run
    
    import bimtester.reports
    
    report_json = bimtester.run.TestRunner(args["ifc"], args["schema_file"]).run(args)
    
    report_json
    
    report_html = join(os.path.dirname(os.path.realpath(report_json)), "report.html")
    
    bimtester.reports.ReportGenerator().generate(report_json, report_html)
    
    import webbrowser
    
    webbrowser.open(report_html)
    
    

    opens the standard webbrowser with the html report

Login or Register to reply.