Ecore functionality in pyESDL

As described in Technical foundation, pyESDL and ESDL are build upon ECore. This offers some extra functionality that is usually not available in other data structure libraries.

Tips & Tricks

The ESDL ECore model describes the classes that are available in the ESDL language. Classes, such as esdl.GenericProdcuer are the specification of the objects present in the language, while objects are the instantiation of the classes at runtime (gp = esdl.GenericProducer()).

All Ecore related methods/attributes start with the letter ‘e’.

ECore functionality examples

Code

Explanation

esdl_object.eClass

Refers to the Class it belongs to (name, references, attributes). Both references and attributes are called features in Ecore terminology

esdl_object.eAllContents()

Lists all objects contained in an object in ESDL. When you use the energySystem object here, it will iterate over all objects in the ESDL. It returns an iterator.

esdl_object.eContainer()

Returns the container this object belongs to, e.g. its parent.

esdl_object.eGet('attribute_name')

Gets the value of the attribute (same as esdl_object.attribute_name)

esdl_object.eSet('attribute_name', value)

Sets the value of the attribute (same as esdl_object.attribute_name = value)

esdl_object.eIsSet('attribute_name')

Checks if the attribute is set in the model (otherwise it will return the default value)

As shown above, each runtime object has a reference to its EClass. To get the name of the class of an ESDL object you can do the following:

import esdl

gp = esdl.GenericProducer()
class_name = gp.eClass.name
print(class_name)

>> GenericProducer