TAGGED: mechanical
-
-
August 27, 2024 at 3:09 pm
-
August 27, 2024 at 3:46 pmmjmiddleAnsys Employee
The "Automation > Scripting" console is a place you can run some script immediately. You can use it to test a line at a time when developing your own script, or just paste your entire script and run it immediately. You can also turn on recording to easily build a basic script. And you have the Intellisense popup as you type python objects to see the properties and methods beneath it. Think of it as a test bed for developing a script, but you can also run your entire debugged script there.
The "python code" does not immediately run. It is triggered by its placement in the Outline, and the callback you set. You can also use the Property Provider to create custom fields in the Details. This allows you to create something that appears like a custom load or result or other custom Outline object depending on its placement in the Outline. Closely related is the "Python Result" which can display custom result contours on the model. See documentation (https://ansyshelp.ansys.com):
go to "Mechanical Application > Mechanical User's Guide > Python Code"
Also, "Mechanical Application > Scripting in Mechanical Guide > Scripting Examples > Examples Using the Python Code Object"
and "Mechanical Application > Mechanical Users' Guide > Results > Python Result"
See Forum post:
https://discuss.ansys.com/discussion/1177/how-to-use-pythoncode-object-in-mechanical-2021r2
https://developer.ansys.com/blog/script-tip-friday-python-code-object-mechanical
-
August 27, 2024 at 3:54 pmzzhang868Subscriber
Thank you for your detailed response! I have one more question: I'm currently using a "Scripting" approach to automatically set up "Analysis Settings" for over 100 time steps, but my machine tends to crash after setting up around 10 time steps. I'm wondering if switching to "Python Code" might help improve this. Do you have any suggestions on how to handle this? For context, I'm using a server with 20 nodes, each node having 24 cores.
-
August 27, 2024 at 4:17 pmErik KostsonAnsys Employee
Hi
Can you explain a bit more what you are doing - you setting up the analysis settings for multiple steps (say you have 100 steps)?
Python codee is not really made for that it is scripting that is the correct way here.All the best
Erik
-
August 27, 2024 at 4:26 pmzzhang868Subscriber
Apologies for the confusion. I use "Scripting" to write Python code that adjusts the "Analysis Settings" to set up 100 time steps. However, whenever it runs through a few steps (around 10, for example) to update the settings, the machine crashes. I'm using a CPU with 240 cores (10 nodes, each with 24 cores). I'm wondering if there's a way to run the scripting without issues. Should I modify any settings to ensure the scripting runs smoothly? Thank you so much!
-
-
August 27, 2024 at 4:33 pmErik KostsonAnsys Employee
Again please do you use NUmber of STeps = 100 in step controls (see below) or what are you setting up 100 times – please explain more.
Also what do you set up there say number of substeps, end time and so on.
This can be done directky via Scripting and does not use a Python Code object.
https://discuss.ansys.com/discussion/4384/how-to-change-and-set-up-multiple-steps-via-scripting#latest
See here how it is done:
Thank you
-
August 27, 2024 at 4:47 pmzzhang868SubscriberAs shown in the screenshot you shared, I use "Scripting" to change the "Number of Steps" to 100 and adjust the left settings under it accordingly. I have tested a simple case, for example, setting the "Number of Steps" to 5, and "Scripting" successfully adjusts all settings as needed. However, when the "Number of Steps" is set to 100, the machine crashes before it can finish updating all the details in "Analysis Settings."In my screenshot of the "Advanced Options," even after increasing the number of CPU cores from 72 to 240, the machine still crashes. I am wondering whether this issue is due to the limitations of "Scripting" when changing a large number of settings or if it is related to my CPU's capability. Even though I can allocate more cores, it hasn't resolved the issue based on my testing. I'm wondering if I have incorrectly configured the "Advanced Options" for computation, or if there's a way to better utilize my CPU cores to allow "Scripting" to run without issues. Thanks a lot!
-
August 27, 2024 at 4:56 pmErik KostsonAnsys Employee
This can be done directly via Scripting and does not use a Python Code object.
See here how it is done:
https://discuss.ansys.com/discussion/4384/how-to-change-and-set-up-multiple-steps-via-scripting
-
August 27, 2024 at 4:59 pmzzhang868Subscriber
Yes, that's exactly what I've done. However, when the "Number of Steps" is set to 100, my machine crashes. Please refer to my following responses for more details. Thanks a lot!
(Sorry for misunderstanding the concept of "Scripting" and "Python Codes")
-
-
-
August 27, 2024 at 4:56 pmzzhang868SubscriberFor example, I use "Scripting" to configure the following settings: setting the "Number of Steps" to 100. The script will then automatically adjust the "Current Step Number" from 100 down to 1. When the "Number of Steps" is set to 5, the scripting completes the setup without any issues. Therefore, I believe the Python code I've written in "Scripting" is functioning correctly.My main question is how I can run "Scripting" without encountering issues. Is the problem due to a limitation within the scripting itself, or is it related to computational limitations? I have tried increasing the number of CPU cores, but based on my testing, it hasn't resolved the problem. I'm wondering if I've set up the "Advanced Options" incorrectly. If so, how can I adjust them to make the most effective use of the CPU and ensure that the script runs smoothly?
-
August 27, 2024 at 4:58 pmErik KostsonAnsys Employee
This can be done directly via Scripting and does not use a Python Code object.
See here how it is done:
https://discuss.ansys.com/discussion/4384/how-to-change-and-set-up-multiple-steps-via-scripting
It has been tested and worked on 100 steps-
August 27, 2024 at 5:02 pmzzhang868Subscriber
In the example, it only shows 10 steps. I used this approach, but it failed when I tried to increase the number of steps. I’m wondering how this problem can be addressed. Do you have any suggestions? Thanks! Alternatively, could you please share the optimal machine settings that would enable it to run smoothly?
-
August 28, 2024 at 6:08 amErik KostsonAnsys Employee
It works on 2023 R2 and with 100 and 200 steps it works fine on a standard lapotop so not sure why it crashes at your end -
finally the settings you show (Advanced properties, core nr, etc) are for the solver (not for scripts) and do not have anything to do with the issue you mention as they deal with the solver (so once we solve a model).
As you have posted another post that is similar (https://innovationspace.ansys.com/forum/forums/topic/how-to-set-up-cpu-to-avoid-machine-crash-for-ansys-mechanical/), we will close this one as it is a duplicate and as I have posted a solution for a script that might be useful to others. Perhaps other forum members have some tips why it crashes because it should run fine.
-
-
-
- The topic ‘Difference between “Python Code” and “Scripting” in ANSYS Mechanical’ is closed to new replies.
- At least one body has been found to have only 1 element in at least 2 directions
- Error when opening saved Workbench project
- How to apply Compression-only Support?
- Geometric stiffness matrix for solid elements
- Frictional No separation contact
- Timestep range set for animation export
- Image to file in Mechanical is bugged and does not show text
- Script Error Code:800a000d
- Elastic limit load, Elastic-plastic limit load
- Element has excessive thickness change, distortion, is turning inside out
-
1416
-
599
-
591
-
565
-
366
© 2025 Copyright ANSYS, Inc. All rights reserved.