Graphical Views

The API ModelViewManager allows you to set, create, delete, apply, rename, rotate, save, import, and export graphical views, providing an alternative to the View Manager window in Mechanical.


Note:  The API ModelViewManager does not export graphical views exactly as they appear in Mechanical. For example, the exported views exhibit inconsistencies in the zoom and model orientation. If you want to compare views to see changes in results, export them to PNG files using the command ExtAPI.Graphics.ExportScreenToImage instead. This command exports the current view as it appears in Mechanical to a PNG file:

ExtAPI.Graphics.ExportScreenToImage(filePath)

Where filePath is the fully qualified path for the PNG file to create.

Currently, only the PNG file format is supported. The file path must be surrounded by escape characters. An example follows:

ExtAPI.Graphics.ExportScreenToImage("C:\\Users\\Desktop\\image1.png")

The exported view retains the same orientation, zoom factor, and other graphics rendering properties as the view in Mechanical.


In situations where exported graphical views do not have to exactly match what is shown in Mechanical, you can use the API ModelViewManager:

Getting the ModelViewManager Data Object

To get the data object ModelViewManager, you enter the following in the command line of the ACT Console:

model = ExtAPI.DataModel.Project.Model
view_manager = ExtAPI.Graphics.ModelViewManager

If you wanted to get the number of graphical views that are currently defined, you would enter:

views_count = view_manager.NumberOfViews

Setting the View

Before creating a graphical view, you can set the type of view you want to capture. The following table provides commands for setting views.

Table 1:  Commands for Setting Graphical Views

ActionCommand

Set to ISO view

view_manager.SetISOView()

Set to Fit view

view_manager.SetFitView()

Set to Front view

view_manager.SetFrontView()

Set to Back view

view_manager.SetBackView()

Set to Right view

view_manager.SetRightView()

Set to Left view

view_manager.SetLeftView()

Set to Top view

view_manager.SetTopView()

Set to Bottom view

view_manager.SetBottomView()


Creating a View

You can create a graphical view from current graphics using either a default name or a specified name.

To create a view using a default name, you enter:

view_manager.CreateView
   

The name assigned to the new view is View followed by the next sequential number.

To create a view using a specified name, you enter the following, where viewName is the name to assign to the new view:

view_manager.CreateView(string viewName)

For example, assume that you want to set the top view and then create a view named Top View. You enter:

view_manager.SetTopView()
view_manager.CreateView("Top View")
   

Deleting a View

You can delete a view by specifying its name or index.

To delete a view by specifying its name, you enter the following, where viewLabel is the name of the view to delete:

DeleteView(string viewLabel)

For example, to delete a view named Left View, you enter:

view_manager.DeleteView("Left View")

To delete a view by specifying its index, you enter the following, where viewIndex is the index of the listed view to delete:

DeleteView(int viewIndex)

For example, to delete a view with index 0, you enter:

view_manager.DeleteView(0)

   

Applying a View

You can apply a graphical view by specifying its name or index.

To apply a view by specifying its name, you enter the following, where viewLabel is the name of the view to apply:

view_manager.ApplyModelView(string viewLabel)

For example, to apply a view named Fit View, you enter:

view_manager.ApplyModelView("Fit View")

To apply a view by specifying its index, you enter the following, where viewIndex is the index of the listed view to apply:

view_manager.ApplyModelView(int viewIndex)

For example, to apply a view with index 1, you enter:

view_manager.ApplyModelView(1)

Renaming a View

To rename a saved graphical view, you enter the following, where viewLabel is the current name of the view to rename and newLabel is the new name to assign to the view:

view_manager.RenameView(string viewLabel, string newLabel)

For example, assume that a view is currently named View 7 and you want to rename it to ISO View. You enter:

view_manager.RenameView("View 7","ISO View")

Rotating a View

To rotate the active view, you enter the following, where angle is the amount of rotation:

view_manager.RotateView(double angle)

For example, to rotate the active object 45 degrees clockwise, you enter:

view_manager.RotateView(45)
   

Note:  For the angle parameter, you enter a positive value to rotate the view clockwise or a negative value to rotate the view counter-clockwise.


Saving a View

You can save a graphic view of the entire model as an image file by specifying its name or index. For all methods, mode is a string representing the graphics format of the file to which to save the image. The values that can be entered for mode are "PNG", "JPG", "TIF", "BMP", and "EPS".


Note:  For commands that use the parameter folder, an empty string ("") for this parameter defaults to the project user files. This is a null operation if the specified folder does not exist.


To save a view specified by name as an image to the project user files, you enter the following, where viewLabel is the name of the view to save and mode is the graphics format for the image file:

view_manager.CaptureModelView(string viewLabel, string mode)

For example, to save a view named Bottom View to a TIF file to the project user files, you enter:

view_manager.CaptureModelView("Bottom View", "TIF")

To save a view specified by name as an image to a specified folder, you enter the following, where viewLabel is the name of the view to save, mode is the graphics format for the image file, and folder is the name of the folder in which to save the file:

view_manager.CaptureModelView(string viewLabel, string mode, string folder)

For example, to save a view named Right View to a JPG file to D:\My_Projects\Views, you enter:

view_manager.CaptureModelView("Right View", "JPG", "D:\My_Projects\Views")
   

To save a view specified by index as an image to a specified folder, you enter the following, where index is the index of the view to save, mode is the graphics format for the image file, and folder is the name of the folder in which to save the file:

view_manager.CaptureModelView(index, string mode, string folder)

For example, to save a view with index 0 to a PNG file to the project user files, you enter:

view_manager.CaptureModelView(0, "PNG")

Saving an Object

To save an object as an image to a file having the same name as the object, you enter the following, where obj is the object to save, mode is the graphics format for the image file, and folder is the name of the folder in which to save the file:

view_manager.CaptureObjectImage(Ansys.ACT.Automation.Mechanical.DataModelObject obj, string mode, string folder)

For example, to save an object named plate to a BMP file to the project user files, you enter:

view_manager.CaptureObjectImage(Ansys.ACT.Automation.Mechanical.DataModelObject "Plate", "BMP")

Note:  An empty string ("") for the parameter folder defaults to the project user files. This is a null operation if the specified folder does not exist.


Importing a Saved View List

To import a saved view list by specifying a filename, you enter the following, where viewfilepath is the name of the view (XML file) to import:

view_manager.ImportModelViews(string viewfilepath)

For example, to import a saved view list named allviews.xml that is located in D:\My_Projects\Views, you enter:

view_manager.ImportModelViews("D:\My_Projects\Views\allviews.xml")

Exporting a Saved View List

To export all saved graphical views to an XML file, you enter the following, where viewfilepath is the name of the XML file to create:

view_manager.ExportModelViews(string viewfilepath)

For example, to export a saved view list named myviews.xml to D:\My_Projects\Views, you enter:

view_manager.ExportModelViews("D:\My_Projects\Views\myviews.xml")

Exporting an Object

To export the active object to a 3D AVZ file, you enter the following, where avzffilepath is a fully qualified AVZ filepath:

 view_manager.Capture3DImage(string avzfilepath)

For example, to export the active object to a file named my_plane.avz to D:\My_Projects\Views, you enter:

view_manager.Capture3DImage("D:\My_Projects\Views\my_plane.avz")

Release 18.2 - © ANSYS, Inc. All rights reserved.