modelx.new_space#

new_space(name=None, bases=None, formula=None)[source]#

Create a new space in the current model.

Creates a new UserSpace in the current model. If no current model exists, a new model is created automatically. The newly created space becomes the current space.

Spaces are containers for cells (formulas), child spaces, and references. They can inherit from base spaces and can be parameterized to create dynamic space instances.

Parameters:
  • name (str, optional) – Name for the space. Must be a valid Python identifier. If not provided, an automatic name is assigned in the format SpaceN where N is an integer.

  • bases (optional) –

    Base space(s) for inheritance. Can be:

  • formula (callable or str, optional) – Parameter formula for creating dynamic space instances. If provided, the space becomes parameterized.

Returns:

The newly created space.

Return type:

UserSpace

Example

>>> import modelx as mx
>>>
>>> # Create space with automatic name
>>> s1 = mx.new_space()
>>> s1.name
'Space1'
>>>
>>> # Create space with specific name
>>> s2 = mx.new_space('Projection')
>>>
>>> # Create space with inheritance
>>> base = mx.new_space('Base')
>>> derived = mx.new_space('Derived', bases=base)
>>>
>>> # Create parameterized space
>>> s3 = mx.new_space('Analysis', formula=lambda product: None)
>>> s3.parameters
('product',)

See also