From b4077b8cfd06c6308a850d8eabc37f0b75084f42 Mon Sep 17 00:00:00 2001 From: rs-bh-n Date: Tue, 27 Feb 2024 07:52:40 +0530 Subject: [PATCH 1/3] typo fix - mechanical --- .../pymechanical_cheat_sheet/pymechanical_cheat_sheet.tex | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cheat_sheets/pymechanical_cheat_sheet/pymechanical_cheat_sheet.tex b/cheat_sheets/pymechanical_cheat_sheet/pymechanical_cheat_sheet.tex index f04bb84..73eb591 100644 --- a/cheat_sheets/pymechanical_cheat_sheet/pymechanical_cheat_sheet.tex +++ b/cheat_sheets/pymechanical_cheat_sheet/pymechanical_cheat_sheet.tex @@ -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} From 9a4c43b06b086d0dd6cbb231a062bd119bfc0323 Mon Sep 17 00:00:00 2001 From: rs-bh-n Date: Tue, 27 Feb 2024 12:12:08 +0530 Subject: [PATCH 2/3] added add_mechanical_python_libraries and Enum arg --- .../pymechanical_script.py | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/cheat_sheets/pymechanical_cheat_sheet/pymechanical_script.py b/cheat_sheets/pymechanical_cheat_sheet/pymechanical_script.py index 46f78da..fecb108 100644 --- a/cheat_sheets/pymechanical_cheat_sheet/pymechanical_script.py +++ b/cheat_sheets/pymechanical_cheat_sheet/pymechanical_script.py @@ -69,7 +69,6 @@ # BREAK BLOCK from ansys.mechanical.core import App - app = App(version=241) print(app) # BREAK BLOCK @@ -77,7 +76,11 @@ # 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) +# Import python modules shipped with Mechanical +from ansys.mechanical.core.embedding import add_mechanical_python_libraries +add_mechanical_python_libraries(241) # BREAK BLOCK ExtAPI # Application.ExtAPI DataModel # Application.DataModel @@ -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") \ No newline at end of file From c39cd8f81aa31c75ad0d869f3acb6759c65af229 Mon Sep 17 00:00:00 2001 From: rs-bh-n Date: Tue, 27 Feb 2024 12:19:12 +0530 Subject: [PATCH 3/3] capital letter - Python --- cheat_sheets/pymechanical_cheat_sheet/pymechanical_script.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cheat_sheets/pymechanical_cheat_sheet/pymechanical_script.py b/cheat_sheets/pymechanical_cheat_sheet/pymechanical_script.py index fecb108..da3b988 100644 --- a/cheat_sheets/pymechanical_cheat_sheet/pymechanical_script.py +++ b/cheat_sheets/pymechanical_cheat_sheet/pymechanical_script.py @@ -78,7 +78,7 @@ # Merge them into your Python global variables # Optional argument for Enums without namespaces globals().update(global_variables(app),True) -# Import python modules shipped with Mechanical +# Import Python modules shipped with Mechanical from ansys.mechanical.core.embedding import add_mechanical_python_libraries add_mechanical_python_libraries(241) # BREAK BLOCK