Libraries of IronPython functions are installed with ACT to help you to customize Ansys products. In C:\Program Files\ANSYS Inc\v242\Addins\ACT\libraries), libraries exist in the following folders:
AppLauncher
DesignModeler
ElectonicsDesktop
Fluent
Mechanical
Project
SpaceClaim
Study
You can use the IronPython functions within these libraries to develop extensions more efficiently. If desired, you can interactively test them in the ACT Console.
Description
This library allows you to access to all material properties defined in Engineering Data. The material is defined for each body and can be retrieved using the geometry API.
Location
libraries/Mechanical/materials.py
libraries/Project/materials.py
libraries/Study/materials.py
Usage
import materials
Functions
GetListMaterialProperties(mat)
This function returns a list of property names for the material
mat
given in argument.
GetMaterialPropertyByName(mat, name)
This function returns the material property name
for the
material mat
.
InterpolateData(vx, vy, vin)
This function computes a linear interpolation vout = f(vin)
with f defined by vy = f(vx)
.
vx
represents a list of values for the input variable.vy
represents a list of values for the property that depends on the input variable defined byvx
.vin
is the value on which the function has to evaluate the property.
Examples
Assume that you enter these commands:
import materials
mat = ExtAPI.DataModel.GeoData.Assemblies[0].Parts[0].Bodies[0].Material
materials.GetListMaterialProperties(mat)
Results like these are returned:
['Compressive Ultimate Strength', 'Compressive Yield Strength', 'Density', 'Tensile Yield Strength', 'Tensile Ultimate Strength', 'Coefficient of Thermal Expansion', 'Specific Heat', 'Thermal Conductivity', 'Alternating Stress', 'Strain-Life Parameters', 'Resistivity', 'Elasticity', 'Relative Permeability']
Assume that you enter these commands:
prop = materials.GetMaterialPropertyByName(mat,"Elasticity")
prop
Results like these are returned:
{"Poisson's Ratio": ['', 0.29999999999999999, 0.29999999999999999, 0.29999999999999999], 'Bulk Modulus': ['Pa', 166666666666.667, 175000000000.0, 183333333333.333], 'Temperature': ['C', 10.0, 100.0, 1000.0], "Young's Modulus": ['Pa', 200000000000.0, 210000000000.0, 220000000000.0], 'Shear Modulus': ['Pa', 76923076923.0769, 80769230769.2308, 84615384615.3846]}
Assume that you enter these commands:
val = materials.InterpolateData(prop["Temperature"][1:],prop["Young's Modulus"][1:],10.)
val
val = materials.InterpolateData(prop["Temperature"][1:],prop["Young's Modulus"][1:],20.)
val
Results like these are returned:
200000000000.0
201111111111.0
Description
This library implements a set of functions to manipulate the unit-dependent quantities within an extension. This library is of particular interest each time quantities have to remain consistent with the current unit system activated in the Ansys product.
Location
libraries/DesignModeler/units.py
libraries/ElectonicsDesktop/units.py
libraries/Fluent/units.py
libraries/Mechanical/units.py
libraries/Project/units.py
libraries/SpaceClaim/units.py
libraries/Study/units.py
Usage
import units
Function
ConvertUnit(value,fromUnit,toUnit[,quantityName])
This function converts the value
from the unit
fromUnit
to the unit toUnit
. A quantity
name can be specified to avoid conflict during conversion. However, a quantity name is not
mandatory.
Example
Assume that you enter these commands:
import units units.ConvertUnit(1,"m","mm")
A result like this is returned:
1000.0
Function
ConvertUserAngleUnitToDegrees(api, value)
This function converts the angle value
to the unit degrees. If
the current activated unit is already degrees, then the value remains unchanged.
Example
Assume that you enter these commands:
import units units.ConvertUserAngleUnitToDegrees(api,3.14)
A result like this is returned if the angle unit is set to radians when the command is called:
180
A result like this is returned if the angle unit is set to degrees when the command is called:
3.14
Function
ConvertToSolverConsistentUnit(api, value, quantityName, analysis)
This function converts the value
of the quantity
quantityName
from the currently activated unit in the Ansys
product to the corresponding consistent unit used by the solver for the resolution of the
analysis analysis
.
Example
Assume that you enter these commands:
import units units.ConvertToSolverConsistentUnit(api,1.,”pressure”,”Static Structural”)
A result like this is returned if the unit system is set to Metric(mm,dat,N,s,mV,mA) when the command is called:
10
Function
ConvertToUserUnit(api, value, fromUnit, quantityName)
This function converts the value
of the quantity
quantityName
from the unit fromUnit
to the
currently activated unit system in the Ansys product.
Example
Assume that you enter these commands:
import units units.ConvertToUserUnit(api,1.,”m”,”Length”)
A result like this is returned if the current activated unit is millimeter when the command is called:
1000
Function
ConvertUnitToSolverConsistentUnit(api, value, fromUnit, quantityName, analysis)
This function converts the value
of the quantity
quantityName
from the unit fromUnit
to the
consistent unit that is used by the solver for the resolution of the analysis
analysis
.
Example
Assume that you enter these commands:
import units units.ConvertUnitToSolverConsistentUnit(api,1.,”m”,”Length”,”Static Structural”)
A result like this is returned if the consistent unit is millimeter when the command is called:
1000
Function
GetMeshToUserConversionFactor(api)
This function returns the scale factor to be applied to convert a length from the unit associated with the mesh and the currently activated unit in the Ansys product.
Example
Assume that you enter these commands:
import units units.GetMeshToUserConversionFactor(api)
A result like this is returned if the unit associated with the mesh is meter and if the current activated unit in the application is millimeter:
1000
Quantity Types
Here is the exact text to use for the available quantity types:
Angle
Chemical Amount
Current
Length
Luminance
Mass
Solid Angle
Temperature
Time
Electric Charge
Energy
Force
Power
Pressure
Voltage
Description
This library implements some helpers to write APDL command blocks or to execute Mechanical APDL programs.
Location
libraries/ElectronicsDesktop/ansys.py
libraries/Fluent/ansys.py
libraries/Mechanical/ansys.py
libraries/Project/ansys.py
libraries/Study/ansys.py
Usage
import ansys
Functions
createNodeComponent(refIds,groupName,mesh,stream,fromGeoIds=True)
This function writes the APDL command block (CMBLOCK) for the creation of a node
component related to the geometry entities identified by refIds
into the stream stream
. “refIds” refer to geometric
IDs if “fromGeoIds” is true and the node IDs are retrieved from geometric
entities using the associativity between the geometry and mesh. If
“fromGeoIds” is false, then “refIds” refer directly to the
node IDs to be written in the component.
createElementComponent(refIds,groupName,mesh,stream,fromGeoIds=True)
This function writes the APDL command block (CMBLOCK) for the creation of an element component related to the geometry entities identified by “refIds” into the stream “stream”. “refIds” refer to geometric IDs if “fromGeoIds” is true and the element IDs are retrieved from geometric entities using the associativity between the geometry and the mesh. If “fromGeoIds” is false, the “refIds” refer directly to the element IDs to be written in the component.
RunANSYS(api,args,[runDir[,exelocation]])
This function calls the Mechanical APDL program with the command line initialized by
args
. The folder from which to execute the program can be
specified with runDir
. The location of the executable is also
managed with exelocation
.
The parameter api
must be ExtAPI
.
Example
import ansys ansys.createNodeComponent([refId],"myGroup",mesh,stream) ansys.RunANSYS(ExtAPI,"")
Description
This library implements a helper that can be used to transfer data between Mechanical and the Workbench Project tab.
Location
libraries/Mechanical/ansys.py
libraries/Project/ansys.py
libraries/Study/ansys.py
Usage
import wbjn
Functions
ExecuteCommand(api,cmd,**args)
This function executes a journal command specified by cmd
You
can get a result object by using the function returnValue(obj)
in
your journal command. All arguments must implement the serialization interface provided
by .Net. The object sent to the function returnValue(obj)
must also
implement the serialization interface. This interface is already implemented for many
standard types of data (integer, double, list…). Note that the standard Python
dictionary does not implement this interface by default. If a dictionary is required,
use the class SerializableDictionary
provided by ACT.
The parameter api
must be
ExtAPI
.
ExecuteFile(api,file,**args)
The same as above but executes a journal file specified by
file
.
Examples
The following commands return 5
as the result:
import wbjn wbjn.ExecuteCommand(ExtAPI,"returnValue(a+b)",a=2,b=3)
The following commands return My first system is: Static Structural
!
:
import wbjn wbjn.ExecuteCommand(ExtAPI,"returnValue(a+GetAllSystems()[0].DisplayText+b)", a="My first system is: ",b=" !")
The following commands return 3
as the result:
import wbjn dict = SerializableDictionary[str,int]() dict.Add("e1",1) dict.Add("e2",2) wbjn.ExecuteCommand(ExtAPI,'returnValue(d["e1"]+d["e2"])', d=dict)