This section describes how to safely modify using the Open API.

All model changes must be executed within a controlled context to ensure:

  • Consistency of the model
  • Proper command tracking
  • Support for undo/redo operations

The platform provides two approaches for performing model modifications:

Model Modification Concepts

Before modifying a model, it is important to understand the core concepts:

  • Commands
    Each modification is recorded as a command for undo/redo
  • Command History
    Tracks executed changes and enables rollback
  • Sessions
    Define the scope in which model changes are applied

These mechanisms ensure that all changes are safe, traceable, and reversible.

Choosing an API

Use the Editing API (Recommended)

  • Automatically manages commands and command history
  • Simpler and safer to use
  • Best for most plugin and automation scenarios

See: (2026x Refresh1) Editing API

Use SessionManager (Advanced)

  • Provides manual control over sessions
  • Requires explicit session lifecycle management
  • Useful for legacy integrations or specialized workflows

See: (2026x Refresh1) SessionManager API

Example Comparison

import com.dassault_systemes.modeler.foundation.editing.Editing;
import com.nomagic.magicdraw.openapi.uml.SessionManager;

Editing editing = Editing.getInstance(project);

// Recommended approach (Editing API)
editing.execute("Create element", () -> {
    // model changes here
});
 
// Manual approach (SessionManager)
SessionManager.getInstance().createSession(project, "Edit");
try {
    // model changes here
} finally {
    SessionManager.getInstance().closeSession(project);
}
JAVA

Key Takeaways

  • All model changes must occur within a controlled execution context
  • Prefer the Editing API for most use cases
  • Use SessionManager only when you need explicit control