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

Member, Employee, GitHub-issue-creator Posts: 331
50 Answers 100 Comments Second Anniversary 25 Likes
✭✭✭✭
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

  • Member, Employee, GitHub-issue-creator Posts: 331
    50 Answers 100 Comments Second Anniversary 25 Likes
    ✭✭✭✭
    edited November 2023
    1. import wbjn
    2. import os
    3. userdirectory = wbjn.ExecuteCommand(ExtAPI,'returnValue(GetUserFilesDirectory())')
    4. results =ExtAPI.DataModel.GetObjectsByType(DataModelObjectCategory.Result)
    5. #loop over the results
    6. for result in results:
    7. result.Activate()
    8. mvm = ExtAPI.Graphics.ModelViewManager
    9. avzFilename = os.path.join(userdirectory,'{}.avz'.format(result.Name))
    10. mvm.Capture3DImage(avzFilename)
  • Member, Employee Posts: 369
    25 Answers 100 Comments Second Anniversary 25 Likes
    ✭✭✭✭

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

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

Welcome!

It looks like you're new here. Sign in or register to get started.