In Mechanical scripting, how do I export results as an .avz file?
Landon Mitchell Kanner
Member, Employee Posts: 287
✭✭✭✭
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.
Tagged:
0
Answers
-
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)
1 -
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
1