Which scripting part or Pyansys modules can I use to obtain results in the .avz format?

Naveen Kumar Begari
Naveen Kumar Begari Member Posts: 29
10 Comments Name Dropper Photogenic
**
edited July 8 in Structures

As we have ansys viewer to read .avz files to get visualisation in 3D.
Is their anything in pyansys same as ansys viewer or do we have any other extensions...?

Best Answers

Answers

  • Abel Ramos
    Abel Ramos Member, Employee Posts: 42
    5 Answers 10 Comments 5 Likes First Anniversary
    ✭✭✭✭

    Hello, depending on your needs you can use pyDPF (or dpf in mechanical) to plot your results natively in a 3D visualization.

    For example:
    https://post.docs.pyansys.com/

    Best Regards,

  • Landon Mitchell Kanner
    Landon Mitchell Kanner Member, Employee Posts: 295
    25 Answers 100 Comments Second Anniversary 25 Likes
    ✭✭✭✭
    ## AVZ export
    import wbjn
    import os
    userdirectory = wbjn.ExecuteCommand(ExtAPI,'returnValue(GetUserFilesDirectory())')
    results =ExtAPI.DataModel.GetObjectsByType(DataModelObjectCategory.Result)
    #loop over the results
    for result in results:
        result.Activate()
        mvm = ExtAPI.Graphics.ModelViewManager
        #avzFilename = r'D:\Temp\{}.avz'.format(result.Name)
        avzFilename = os.path.join(userdirectory,'{}.avz'.format(result.Name))
        mvm.Capture3DImage(avzFilename)
    
  • Landon Mitchell Kanner
    Landon Mitchell Kanner Member, Employee Posts: 295
    25 Answers 100 Comments Second Anniversary 25 Likes
    ✭✭✭✭
    import wbjn
    import os
    def ExportAVZ(obj,export_directory):
       obj.Activate()
       # export_directory = wbjn.ExecuteCommand(ExtAPI,'returnValue(GetUserFilesDirectory())')
       filename = os.path.join(export_directory,'{}.avz'.format(obj.Name))
       ExtAPI.Graphics.Export3D(filename)
       return filename
    

    This was taken from this blog post, which you might find useful.

  • Naveen Kumar Begari
    Naveen Kumar Begari Member Posts: 29
    10 Comments Name Dropper Photogenic
    **

    Hi @Landon Mitchell Kanner , Thanks for response.

    But, How can we do with PyAnsys using .rst files, instead of doing with IPython (Mechanical scripting).?

    Naveen.

  • Mike.Thompson
    Mike.Thompson Member, Employee Posts: 342
    25 Answers 100 Comments 25 Likes First Anniversary
    ✭✭✭✭

    Attached is an in-work ACT extension that will work in Mechanical Stand Alone mode (not workbench). You can open Mechanical and load the app. There is a single button that will let you open a results file.

    Upon selection it will launch MAPDL in batch in background, create a .cdb file from the .rst file, import that .cdb file into mechanical, create an analysis, and read in that results file for post processing

    This is a work-in progress, in the sense it has limited testing, but the code is all open for review/modification to your own needs. It also does not imply this will be a native feature/function in the future, just a demonstration that such a workflow can be executed from the Mechanical API.

  • Landon Mitchell Kanner
    Landon Mitchell Kanner Member, Employee Posts: 295
    25 Answers 100 Comments Second Anniversary 25 Likes
    ✭✭✭✭
    edited July 15

    Here is code to leverage @Mike.Thompson 's solution to create an .avz from an .rst using pyMechanical:

    RstPath = r'D:\Temp\project_Mech_Files\StaticStructural\file.rst'
    library = r'C:\Users\lmkanner\Downloads\ResultsFileMechReader\ResultsFileMechReader'
    
    from ansys.mechanical.core import App
    import sys
    import os
    from ansys.mechanical.core import global_variables
    
    outfolder = os.path.split(RstPath)[0]
    app = App()
    globals().update(global_variables(app))
    
    sys.path.append(library)
    sys.path.append(r'C:\Program Files\ANSYS Inc\v{}\aisol\DesignSpace\DSPages\Python'.format(app.version))
    
    
    import RunAPDL
    RunAPDL.Initialize(ExtAPI, Ansys)
    SI, CdbPath = RunAPDL.GetCdbFileFromResultFile(RstPath)
    
    import RunMech
    RunMech.Initialize(ExtAPI, Ansys)
    RunMech.ImportResultsToCurrentSession(CdbPath, RstPath, library)
    
    def ExportAVZ(obj,export_directory):
       obj.Activate()
       # export_directory = wbjn.ExecuteCommand(ExtAPI,'returnValue(GetUserFilesDirectory())')
       filename = os.path.join(export_directory,'{}.avz'.format(obj.Name))
       ExtAPI.Graphics.Export3D(filename)
       return filename
    
    results =ExtAPI.DataModel.GetObjectsByType(Ansys.Mechanical.DataModel.Enums.DataModelObjectCategory.Result)
    for result in results:
       avz = ExportAVZ(result,outfolder)
    
  • Naveen Kumar Begari
    Naveen Kumar Begari Member Posts: 29
    10 Comments Name Dropper Photogenic
    **

    @Landon Mitchell Kanner @AKD-Scripting-Team & @Mike.Thompson
    Thank you for the support and guidance.