Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Pymechanical update1 #69

Draft
wants to merge 3 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
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
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ \section{\includegraphics[height=\fontcharht\font`\S]{slash.png} Send commands t
Execute a Python script file:
\pythoncode{scripts/generated_scripts/pymechanical_script_8.py}

Import a Mechancial file and print the count of bodies:
Import a Mechanical file and print the count of bodies:
\pythoncode{scripts/generated_scripts/pymechanical_script_9.py}

% \section{\includegraphics[height=\fontcharht\font`\S]{slash.png}Project-specific operations}
Expand Down
14 changes: 7 additions & 7 deletions cheat_sheets/pymechanical_cheat_sheet/pymechanical_script.py
Original file line number Diff line number Diff line change
Expand Up @@ -69,15 +69,18 @@

# BREAK BLOCK
from ansys.mechanical.core import App

app = App(version=241)
print(app)
# BREAK BLOCK

# Extract the global API entry points (available from built-in Mechanical scripting)
from ansys.mechanical.core import global_variables
# Merge them into your Python global variables
globals().update(global_variables(app))
# Optional argument for Enums without namespaces
globals().update(global_variables(app),True)

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
globals().update(global_variables(app),True)
# Available in ansys-mechanical-core >= v0.10.3
globals().update(global_variables(app),True)

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This has been modified with latest way of updating globals

# Import Python modules shipped with Mechanical

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
# Import Python modules shipped with Mechanical
# Import Python modules shipped with Mechanical
# Available in ansys-mechanical-core >= v0.10.3

from ansys.mechanical.core.embedding import add_mechanical_python_libraries
add_mechanical_python_libraries(241)
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Two comments -

  1. I don't see where these libraries are used.

  2. better to make the version number a variable so that the same number is guaranteed to be used by add_mechanical_python_libraries() and app = App()

# BREAK BLOCK
ExtAPI # Application.ExtAPI
DataModel # Application.DataModel
Expand All @@ -89,16 +92,13 @@
file = r"D:\\Workdir\\bracket.mechdb"
app.open(file)
allbodies = DataModel.Project.Model.GetChildren(
Ansys.Mechanical.DataModel.Enums.DataModelObjectCategory.Body,
True)
DataModelObjectCategory.Body,True)
print(allbodies.Count)
# BREAK BLOCK
import logging
from ansys.mechanical.core import App
from ansys.mechanical.core.embedding.logger import (
Configuration,
Logger)

Configuration,Logger)
Configuration.configure(level=logging.WARNING, to_stdout=True)
app = App(version=241)
Logger.error("message")
Loading