Is there a way to export the csv file from MAC calculator using Mechanical scripting?

Rohith Patchigolla
Rohith Patchigolla Member, Moderator, Employee Posts: 242
50 Answers 100 Comments Second Anniversary 25 Likes
✭✭✭✭

Is there a way to export the csv file from MAC calculator using Mechanical scripting?

Tagged:

Best Answer

  • Rohith Patchigolla
    Rohith Patchigolla Member, Moderator, Employee Posts: 242
    50 Answers 100 Comments Second Anniversary 25 Likes
    ✭✭✭✭
    Answer ✓

    Please find below code to export the first MAC Calculater Object as a csv file using Mechanical scripting.

    import os
    
    nvh_addon = ExtAPI.ExtensionManager.GetExtensionByName("NVHToolkit")
    
    #Define the path and file name for the export
    dirpath = r"D:\del\mac_export"
    filename = "test.csv"
    file_path_to_csv = os.path.join(dirpath,filename)
    
    nvh_addon.Attributes["exportdir"] = file_path_to_csv
    
    mac_objects=ExtAPI.DataModel.GetUserObjects(nvh_addon)
    nvh_module=nvh_addon.GetModule()
    mac_data = nvh_module.MacData()
    mac_data=nvh_module.ExportMAC(mac_objects[0])
    

Answers

  • M
    M Member, Employee Posts: 254
    50 Answers 100 Comments 100 Likes Second Anniversary
    ✭✭✭✭
    edited March 13

    To further the excellent suggestion by Rohith, you could write this out to the user directory with the name of the design point in the csv file. This would allow you to post process the mode MAC with any external tool and allow to track modes.

    The MAC Calculator has to be built in the first DP and set to the .rst for that analyses. (The MAC calculator is from an extension and while scripted, not easily amenable to being accessed by script). So solve the first DP, set the MAC Calculator to a .rst and set the path, and then solve the rest of your DPs with the code below in an After Post Target Callback Python Code object.

    `
    def after_post(this, solution):# Do not edit this line
    """
    Called after post processing.
    Keyword Arguments :
    this -- the datamodel object instance of the python code object you are currently editing in the tree
    solution -- Solution
    """

    # To access properties created using the Property Provider, please use the following command.
    # this.GetCustomPropertyByPath("your_property_group_name/your_property_name")
    
    # To access scoping properties use the following to access geometry scoping and named selection respectively:
    # this.GetCustomPropertyByPath("your_property_group_name/your_property_name/Geometry Selection")
    # this.GetCustomPropertyByPath("your_property_group_name/your_property_name/Named Selection")
    
    import wbjn
    import os
    
    dp=wbjn.ExecuteCommand(ExtAPI,"returnValue(Parameters.GetCurrentDesignPoint().DisplayText)")
    UserFilesDirectory = wbjn.ExecuteCommand(ExtAPI, "returnValue(GetUserFilesDirectory())")
    
    
    nvh_addon = ExtAPI.ExtensionManager.GetExtensionByName("NVHToolkit")
    #Define the path and file name for the export
    dirpath = UserFilesDirectory
    filename = 'MAC_%s.csv'%dp.replace(' ','_')
    file_path_to_csv = os.path.join(dirpath,filename)
    nvh_addon.Attributes["exportdir"] = file_path_to_csv
    mac_objects=ExtAPI.DataModel.GetUserObjects(nvh_addon)
    nvh_module=nvh_addon.GetModule()
    mac_data = nvh_module.MacData()
    mac_data=nvh_module.ExportMAC(mac_objects[0])
    
    pass
    

    `