Change Material Property

Code

The following script demonstrates how to change a material property for a given body using get body commands.

Code

"""
To insert command just after material definitions in /PREP7, use solver_input_file.WriteLine("!Your command")
Global Helpers:
    this -- this python object
    solver_input_file  -- file stream that allows you to inject commands into the solver input file
    solver_data -- data stucture that allows you to access information from the model such as current step, contact pair ids, etc.
"""
# This script shows how to change a material property for a given body

# The script is working with 'Get Body Commands' 
# the Python code is place under the body you want to modify

solver_input_file.WriteLine("! Changing Young modulus for body: "+this.Parent.Name) # Just a comment in the ds.dat file

body_id=this.Parent.GetGeoBody().Id # retrieve the body in the tree with this.Parent, then get corresponding geometry body
matid=solver_data.GetMaterialSolverId(body_id) # This is the material Id for APDL

# Change Young's modulus of this body
solver_input_file.WriteLine("mp,ex,"+str(matid)+",70000")