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

Landon Mitchell Kanner
Landon Mitchell Kanner Member, Employee Posts: 287
100 Comments 25 Answers 25 Likes Photogenic
✭✭✭✭
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: 287
    100 Comments 25 Answers 25 Likes Photogenic
    ✭✭✭✭
    edited November 2023
    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: 327
    25 Answers First Anniversary 100 Comments 25 Likes
    ✭✭✭✭

    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