In Mechanical scripting, how do I export results as an .avz file?

Options
Landon Mitchell Kanner
Landon Mitchell Kanner Member, Employee Posts: 208
First Answer First Comment 5 Likes First Anniversary
edited November 2023 in Structures

I want to loop over all result objects in Mechanical, create a 3D AVZ file (.avz) for each, and save them in the user directory.

Answers

  • Landon Mitchell Kanner
    Landon Mitchell Kanner Member, Employee Posts: 208
    First Answer First Comment 5 Likes First Anniversary
    edited November 2023
    Options
    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 = os.path.join(userdirectory,'{}.avz'.format(result.Name))
        mvm.Capture3DImage(avzFilename)
    
  • Mike.Thompson
    Mike.Thompson Member, Employee Posts: 279
    First Anniversary First Comment 5 Likes Ansys Employee
    Options

    In the case you have an object with characters not safe for a file path you can use this:

    import string
    
    def GetFileSafeName(Name):
        safechars = string.ascii_lowercase + string.ascii_uppercase + string.digits + '.- '
        filename = ''.join([c if c in safechars else "_" for c in Name])
        return filename