Load a model#

To load a model, you need an instance of a SysML2 Connector. For more information, (see Use a connector).

You can then create an instance of the SysML2ProjectManager class. This class helps you load a model in Python, using the SysML2 standard API.

Create a SysML2 project manager instance#
project_manager = SysML2ProjectManager(connector=ansyssysml2apiconnector)

For more information, see the SysML2ProjectManager class.

With the project manager, and the ID of the project you want, you can load two types of projects. get_sysml_project() and get_scripting_project() accept the same optional load flags:

  • resolve_standard_libraries (default False): resolve and map standard library element contents.

  • includes_derived (default True): include derived properties from the API.

  • includes_inherited (default True): include inherited memberships and features.

When includes_derived is False, PySAM rebuilds the local derived collections from ownedRelationship (and from inheritedMembership when present), for example ownedElement, ownedFeature, feature, and requirement text from each documentation.body.

SysML2 project (static approach)#

SysML2 projects use a Python-based metamodel, enabling static completion for all SysML2 properties.

project = project_manager.get_sysml_project(
    "<Computer Project ID>",
    resolve_standard_libraries=False,
    includes_derived=True,
    includes_inherited=True,
)  # You can find your project ID in the URL of the editor.

Scripting project (dynamic approach)#

Scripting projects use a dynamic class generation approach. This offers flexibility but does not provide autocompletion.

Get the project using the project ID#
project = project_manager.get_scripting_project(
    "<Computer Project ID>"
)  # You can find your project ID in the URL of the editor.

Both of the approaches give you a Python version of your model.

See Approaches dynamic and static for more information about the differences between these approaches and when to use each of them.

Create and load a new project#

You can also create a new project on the server and load it in a single step. The project manager provides create_scripting_project() and create_sysml_project() methods that create the project remotely and return a fully built Python object. They accept the same load flags as get_scripting_project() and get_sysml_project().

project = project_manager.create_scripting_project(
    name="My New Project",
    description="A project created via PySAM SysML2",
    resolve_standard_libraries=False,
    includes_derived=True,
    includes_inherited=True,
)
project = project_manager.create_sysml_project(
    name="My New Project",
    description="A project created via PySAM SysML2",
    resolve_standard_libraries=False,
    includes_derived=True,
    includes_inherited=True,
)

For more project management operations (update, delete, list), see Manage projects.

Previous step

Manage projects

Manage projects
Next step

Read a model

Read your model