-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Co-authored-by: Kerry McAdams <[email protected]>
- Loading branch information
1 parent
90e48c3
commit 2ad0442
Showing
17 changed files
with
215 additions
and
10 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
Tips | ||
==== | ||
|
||
This section showcases some of the useful functions that can be used | ||
in PyMechanical embedding workflow. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
""" .. _ref_tips_01: | ||
3D visualization | ||
---------------- | ||
Visualize 3D imported geometry | ||
""" | ||
|
||
# %% | ||
# Import necessary libraries | ||
# ~~~~~~~~~~~~~~~~~~~~~~~~~~ | ||
|
||
|
||
import ansys.mechanical.core as mech | ||
from ansys.mechanical.core.examples import delete_downloads, download_file | ||
|
||
# %% | ||
# Embed mechanical and set global variables | ||
|
||
app = mech.App(version=242) | ||
app.update_globals(globals()) | ||
print(app) | ||
|
||
|
||
# %% | ||
# Download and import geometry | ||
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~ | ||
# Download geometry | ||
|
||
geometry_path = download_file("Valve.pmdb", "pymechanical", "embedding") | ||
|
||
# %% | ||
# Import geometry | ||
|
||
geometry_import = Model.GeometryImportGroup.AddGeometryImport() | ||
geometry_import.Import(geometry_path) | ||
|
||
# %% | ||
# Visualize in 3D | ||
# ~~~~~~~~~~~~~~~ | ||
|
||
app.plot() | ||
|
||
# %% | ||
# .. note:: | ||
# This visualization is currently available only for geometry and on version 24R2 or later | ||
|
||
# %% | ||
# Cleanup | ||
# ~~~~~~~ | ||
|
||
delete_downloads() | ||
app.new() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,100 @@ | ||
""" .. _ref_tips_02: | ||
Export image | ||
------------ | ||
Export image and display | ||
""" | ||
|
||
# %% | ||
# Import necessary libraries | ||
# ~~~~~~~~~~~~~~~~~~~~~~~~~~ | ||
|
||
import os | ||
|
||
import ansys.mechanical.core as mech | ||
from ansys.mechanical.core.examples import delete_downloads, download_file | ||
|
||
# %% | ||
# Embed Mechanical and set global variables | ||
|
||
app = mech.App(version=242) | ||
app.update_globals(globals()) | ||
print(app) | ||
|
||
|
||
# %% | ||
# Download and import geometry | ||
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~ | ||
# Download geometry | ||
|
||
geometry_path = download_file("Valve.pmdb", "pymechanical", "embedding") | ||
|
||
# %% | ||
# Import geometry | ||
|
||
geometry_import = Model.GeometryImportGroup.AddGeometryImport() | ||
geometry_import.Import(geometry_path) | ||
|
||
# %% | ||
# Configure graphics for image export | ||
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ | ||
|
||
# Orientation | ||
Graphics.Camera.SetSpecificViewOrientation(ViewOrientationType.Iso) | ||
|
||
# Export format | ||
image_export_format = GraphicsImageExportFormat.PNG | ||
|
||
# Resolution and background | ||
settings_720p = Ansys.Mechanical.Graphics.GraphicsImageExportSettings() | ||
settings_720p.Resolution = GraphicsResolutionType.EnhancedResolution | ||
settings_720p.Background = GraphicsBackgroundType.White | ||
settings_720p.Width = 1280 | ||
settings_720p.Height = 720 | ||
settings_720p.CurrentGraphicsDisplay = False | ||
|
||
# Rotate the geometry if needed | ||
ExtAPI.Graphics.Camera.Rotate(180, CameraAxisType.ScreenY) | ||
|
||
|
||
# %% | ||
# Custom function for displaying the image | ||
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ | ||
|
||
from matplotlib import image as mpimg | ||
from matplotlib import pyplot as plt | ||
|
||
# Temporary directory to save the image | ||
cwd = os.path.join(os.getcwd(), "out") | ||
|
||
|
||
def display_image(image_name): | ||
plt.figure(figsize=(16, 9)) | ||
plt.imshow(mpimg.imread(os.path.join(cwd, image_name))) | ||
plt.xticks([]) | ||
plt.yticks([]) | ||
plt.axis("off") | ||
plt.show() | ||
|
||
|
||
# %% | ||
# Export and display the image | ||
# ~~~~~~~~~~~~~~~~~~~~~~~~ | ||
|
||
# Fits the geometry in the viewing area | ||
Graphics.Camera.SetFit() | ||
|
||
Graphics.ExportImage( | ||
os.path.join(cwd, "geometry.png"), image_export_format, settings_720p | ||
) | ||
|
||
# Display the image using matplotlib | ||
display_image("geometry.png") | ||
|
||
# %% | ||
# Cleanup | ||
# ~~~~~~~ | ||
|
||
delete_downloads() | ||
app.new() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
""" .. _ref_tips_03: | ||
Project tree | ||
-------------------- | ||
Display the heirarchial Mechanical project structure. | ||
""" | ||
|
||
# %% | ||
# Import necessary libraries | ||
# ~~~~~~~~~~~~~~~~~~~~~~~~~~ | ||
|
||
|
||
import ansys.mechanical.core as mech | ||
from ansys.mechanical.core.examples import delete_downloads, download_file | ||
|
||
# %% | ||
# Embed Mechanical and set global variables | ||
|
||
app = mech.App(version=242) | ||
app.update_globals(globals()) | ||
print(app) | ||
|
||
|
||
# %% | ||
# Download the mechdb file | ||
# ~~~~~~~~~~~~~~~~~~~~~~~~ | ||
|
||
mechdb_path = download_file("graphics_test.mechdb", "pymechanical", "test_files") | ||
|
||
# %% | ||
# Load the mechdb file inside Mechanical | ||
|
||
app.open(mechdb_path) | ||
|
||
# %% | ||
# Display the project tree | ||
# ~~~~~~~~~~~~~~~~~~~~~~~~ | ||
|
||
app.print_tree() | ||
|
||
# %% | ||
# Display the tree only under the first analysis | ||
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ | ||
|
||
app.print_tree(Model.Analyses[0]) | ||
|
||
|
||
# %% | ||
# Cleanup | ||
# ~~~~~~~ | ||
|
||
delete_downloads() | ||
app.new() |
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.