modelx.get_object#

get_object(name: str, as_proxy=False)[source]#

Get a modelx object by its full dotted name.

Retrieves a modelx object (model, space, cells, or reference) using its complete dotted name path. This is useful for accessing objects programmatically when you have their string representation.

Parameters:
  • name (str) –

    Full dotted name of the object, such as:

    • 'Model1' for a model

    • 'Model1.Space1' for a space

    • 'Model1.Space1.foo' for cells or reference

  • as_proxy (bool, optional) – If True, return references as proxy objects instead of their actual values. Defaults to False.

Returns:

The requested modelx object.

Raises:

AttributeError – If the object doesn’t exist.

Example

>>> import modelx as mx
>>>
>>> m = mx.new_model('MyModel')
>>> s = m.new_space('MySpace')
>>> c = s.new_cells('foo', lambda x: x * 2)
>>>
>>> # Get objects by name
>>> mx.get_object('MyModel')
<Model MyModel>
>>>
>>> mx.get_object('MyModel.MySpace')
<UserSpace MyModel.MySpace>
>>>
>>> mx.get_object('MyModel.MySpace.foo')
<Cells MyModel.MySpace.foo(x)>

See also