Use the com.nomagic.uml2.impl.ElementsFactory class for creating model elements. To create a model element, a session with the com.nomagic.magicdraw.openapi.uml.SessionManager must be created.

The create<model element type>Instance() method creates a new model element instance. The figure above shows only a subset of all available create<...>Instance() methods.

All changes in the UML model will be registered and, on the session closing, will be added into the command history.

    Project project =...;
    ElementsFactory f = project.getElementsFactory(); 
    SessionManager.getInstance().createSession(project, "Create a package");
    Package packageA = f.createPackageInstance();
    //add created package into a root of the project
    packageA.setOwner(project.getPrimaryModel());
    ...
    // apply changes and add a command into the command history.
    SessionManager.getInstance().closeSession(project);

 You can find the code examples in <modeling tool installation directory>\openapi\examples\accessors