#A simple Python script to operate basic calculations and assign a property in the STKO Python Scripting Interface

#import all from the PyMpc package
from PyMpc import *

#clear the terminal
App.clearTerminal()

# get the pre-processor document
doc = App.caeDocument()

#You can start by using this API as a calculator
Em = 2.e+10
n = 0.25
G = Em/(2.0*(1.0+n))

#To see your result in the Terminal
print(G)

#Or if you feel like exploring you can assign the property yourself with this function by calling the parameter from the metadata you already defined in the model
#This function assigns G to a section with a given id, after fixing a value for nu
def makeG(id,nu):
	p = doc.getPhysicalProperty(id)
	E = p.XObject.getAttribute('E').quantityScalar.value
	G = E/(2.0*(1.0+nu))
	p.XObject.getAttribute('G/3D').quantityScalar.value = G
	p.commitXObjectChanges()

nu = 0.25
makeG(1,nu)
