modelx.new_model#
- new_model(name=None)[source]#
Create a new model.
Creates a new
Modelobject, which serves as the top-level container for spaces, cells, and references. The newly created model automatically becomes the current model.Models are independent namespaces that can be saved, loaded, and managed separately. Multiple models can exist simultaneously.
- Parameters:
name (str, optional) – Name for the model. Must be a valid Python identifier. If not provided, an automatic name is assigned in the format
ModelNwhereNis an integer (e.g.,Model1,Model2, etc.).- Returns:
The newly created model.
- Return type:
Example
>>> import modelx as mx >>> >>> # Create model with automatic name >>> m1 = mx.new_model() >>> m1.name 'Model1' >>> >>> # Create model with specific name >>> m2 = mx.new_model('MyModel') >>> m2.name 'MyModel' >>> >>> # The new model becomes current >>> mx.cur_model() is m2 True
See also
cur_model(): Get or set the current modelget_models(): Get all models as a dictionaryread_model(): Load a model from files