-
-
December 19, 2022 at 12:41 pm
Ingmar van Dijk
SubscriberHi all,
Experienced engineer but notive programmer here. I code directly into the python console in ansys mechanical. I'd like to make some functions I can always import and call to clean up my code.
However, a standard function doesn't know what to do with ANSYS commands.
Can somebody help me write this example:
The external function is something like:
def lights():
ExtAPI.DataModel.Project.Model.Ambient=0.4And I call it like this:
#Import sys for system and imp for importlib. In Python3 it is importlib instead imp.
import sys
import imp#Set your path where your python files are, for example my test folder for random ansys stuff
path = r"R:\OF_EN\SUS\_DOC\Tools\FEA\700-FEM-ANSYS-Python\Mech-Functions"#Check if path exists. Without check it will always add the path and create a bunch of bullshit
if path not in sys.path:
sys.path.append(path)#Import your library you want
import TestFunction as tester
#import SetLightning as lights#IMPORTANT: reload your library. If you dont, you dont see changes in your code
imp.reload(tester)
#imp.reload(lights)tester.lights()
This of course doesn't work as the function is trying to perform a function that doesn't do anything at that external location.
Help on how to fix this is much apprechated!
Thanks in advance,
Ingmar
-
- You must be logged in to reply to this topic.

Earth Rescue – An Ansys Online Series
The climate crisis is here. But so is the human ingenuity to fight it. Earth Rescue reveals what visionary companies are doing today to engineer radical new ideas in the fight against climate change. Click here to watch the first episode.

Ansys Blog
Subscribe to the Ansys Blog to get great new content about the power of simulation delivered right to your email on a weekly basis. With content from Ansys experts, partners and customers you will learn about product development advances, thought leadership and trends and tips to better use Ansys tools. Sign up here.
- Saving & sharing of Working project files in .wbpz format
- An Unknown error occurred during solution. Check the Solver Output…..
- Understanding Force Convergence Solution Output
- Solver Pivot Warning in Beam Element Model
- Colors and Mesh Display
- How to calculate the residual stress on a coating by Vickers indentation?
- whether have the difference between using contact and target bodies
- What is the difference between bonded contact region and fixed joint
- The solver engine was unable to converge on a solution for the nonlinear problem as constrained.
- User manual
-
2616
-
2098
-
1323
-
1110
-
461
© 2023 Copyright ANSYS, Inc. All rights reserved.