Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
40 commits
Select commit Hold shift + click to select a range
3b4b8be
example
dipinknair Aug 6, 2025
37e5ec8
update order
dipinknair Aug 11, 2025
fda6a3f
update ignore
dipinknair Aug 11, 2025
1f2895f
added overwrite
rs-bh-n Aug 20, 2025
c0a8049
setup - agdb changed
rs-bh-n Aug 20, 2025
6bb5f9f
geom in progress
rs-bh-n Aug 20, 2025
909b500
geometry with new model
rs-bh-n Aug 21, 2025
09f6407
started connections page
rs-bh-n Aug 21, 2025
fcc1b94
connections done
rs-bh-n Aug 21, 2025
a034c2f
nsel ready
rs-bh-n Aug 21, 2025
0377c05
results done
rs-bh-n Aug 21, 2025
404cc5f
started tree objects
rs-bh-n Aug 21, 2025
d10343c
tree objects done
rs-bh-n Aug 21, 2025
0bcdbb6
chore: auto fixes from pre-commit hooks
pre-commit-ci[bot] Aug 21, 2025
f6d18ba
chore: adding changelog file 1287.added.md [dependabot-skip]
pyansys-ci-bot Aug 21, 2025
3774796
Merge branch 'main' into chore/update-examples
dipinknair Aug 26, 2025
b6ef09f
Merge branch 'main' into chore/update-examples
dipinknair Aug 28, 2025
65bd3e7
Merge branch 'main' into chore/update-examples
dipinknair Sep 5, 2025
ea47646
Merge branch 'main' into chore/update-examples
dipinknair Sep 9, 2025
0e02da8
loads added
rs-bh-n Sep 9, 2025
4bb6991
chore: auto fixes from pre-commit hooks
pre-commit-ci[bot] Sep 9, 2025
6039d76
loads ready
rs-bh-n Sep 10, 2025
2dfee81
Merge branch 'chore/update-examples' of https://github.com/ansys/pyme…
rs-bh-n Sep 10, 2025
71b7d0a
loads ready
rs-bh-n Sep 10, 2025
d52c496
chore: auto fixes from pre-commit hooks
pre-commit-ci[bot] Sep 10, 2025
2ff1e7e
comments added
rs-bh-n Sep 12, 2025
bb5d317
Merge branch 'chore/update-examples' of https://github.com/ansys/pyme…
rs-bh-n Sep 12, 2025
55058e8
chore: auto fixes from pre-commit hooks
pre-commit-ci[bot] Sep 12, 2025
90b73d4
all htmls generated
rs-bh-n Sep 12, 2025
fc83eac
Merge branch 'chore/update-examples' of https://github.com/ansys/pyme…
rs-bh-n Sep 12, 2025
dc5068a
fix style
dipinknair Sep 12, 2025
85234e4
fix crash
dipinknair Sep 12, 2025
1938977
Merge branch 'main' into chore/update-examples
dipinknair Sep 12, 2025
cb19e16
dispose added
rs-bh-n Sep 14, 2025
abb0e89
Merge branch 'chore/update-examples' of https://github.com/ansys/pyme…
rs-bh-n Sep 15, 2025
f0d0cd0
Merge branch 'main' into chore/update-examples
dipinknair Sep 17, 2025
20a8e6a
geom description
rs-bh-n Sep 18, 2025
33dee9b
Merge branch 'chore/update-examples' of https://github.com/ansys/pyme…
rs-bh-n Sep 18, 2025
26a0af6
added more snippets from prompt forge
rs-bh-n Sep 18, 2025
8aacf8a
chore: auto fixes from pre-commit hooks
pre-commit-ci[bot] Sep 18, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -200,6 +200,7 @@ doc/source/api/*

# Examples files downloaded when building docs
examples/01_basic/out/*
examples/00_setup/out/*

# pymechanical-specific
mylocal.ip
Expand Down
1 change: 1 addition & 0 deletions doc/changelog.d/1287.added.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Update examples with code snippets
1 change: 1 addition & 0 deletions doc/source/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -241,6 +241,7 @@
"sidebar_pages": ["changelog", "index"],
},
"ansys_sphinx_theme_autoapi": {"project": project, "templates": "_templates/autoapi"},
"show_nav_level": 0,
}

if BUILD_CHEATSHEET:
Expand Down
115 changes: 115 additions & 0 deletions examples/00_setup/01_setup.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,115 @@
# Copyright (C) 2022 - 2025 ANSYS, Inc. and/or its affiliates.
# SPDX-License-Identifier: MIT
#
#
# Permission is hereby granted, free of charge, to any person obtaining a copy
# of this software and associated documentation files (the "Software"), to deal
# in the Software without restriction, including without limitation the rights
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
# copies of the Software, and to permit persons to whom the Software is
# furnished to do so, subject to the following conditions:
#
# The above copyright notice and this permission notice shall be included in all
# copies or substantial portions of the Software.
#
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
# SOFTWARE.

""".. _ref_setup:

App
---

This section has helper scripts for Embedded App
"""

# %%
# Create an embedded instance and open an existing Mechanical File
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

from ansys.mechanical.core import App
from ansys.mechanical.core.examples import delete_downloads, download_file

mechdat_path = download_file("cantilever.mechdat", "pymechanical", "embedding")

# The following line creates an instance of the app, extracts the global API entry points,
# and merges them into your Python global variables.

app = App(db_file=mechdat_path, globals=globals())
print(app)


# Alternatively, you can use the update_globals method of the App class to
# update the global variables.The second argument, if set to False updates
# globals without enums like "SelectionTypeEnum" or "LoadDefineBy"
# app = App()
# app.update_globals(globals(), False)

# For a specific version , use ;
# app = App(version=241)

# %%
# Import a Geometry File
# ~~~~~~~~~~~~~~~~~~~~~~

# sphinx_gallery_start_ignore
app.new()
# sphinx_gallery_end_ignore

geom_file_path = download_file("example_06_bolt_pret_geom.agdb", "pymechanical", "00_basic")
geometry_import = Model.GeometryImportGroup.AddGeometryImport()
geometry_import_format = Ansys.Mechanical.DataModel.Enums.GeometryImportPreference.Format.Automatic
geometry_import_preferences = Ansys.ACT.Mechanical.Utilities.GeometryImportPreferences()
geometry_import_preferences.ProcessLines = True
geometry_import_preferences.NamedSelectionKey = ""
geometry_import_preferences.ProcessNamedSelections = True
geometry_import_preferences.ProcessMaterialProperties = True
geometry_import.Import(geom_file_path, geometry_import_format, geometry_import_preferences)

# %%
# Set Units
# ~~~~~~~~~~~~~~~~~~~~~~~

app.ExtAPI.Application.ActiveUnitSystem = MechanicalUnitSystem.StandardNMM
app.ExtAPI.Application.ActiveAngleUnit = AngleUnitType.Radian
app.ExtAPI.Application.ActiveAngularVelocityUnit = AngularVelocityUnitType.RadianPerSecond

# %%
# View messages in Mechanical using PyMechanical
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

app.messages.show()


# %%
# Plot and Print the Tree (To check model so far)
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

# Plot
app.plot()

# Print the tree
app.print_tree()


# %%
# Save the model
# ~~~~~~~~~~~~~~~
from pathlib import Path

output_path = Path.cwd() / "out"
test_mechdat_path = str(output_path / "test.mechdat")
app.save_as(test_mechdat_path, overwrite=True)


# sphinx_gallery_start_ignore
# Close the app
app.close()
# Delete the downloaded files
delete_downloads()
# sphinx_gallery_end_ignore
Loading
Loading