Basic Loading and Saving of Models
You can load a model version from a Model Manager database using its model location URI. A loaded model can then, for example, be updated using the COMSOL API for the model object and subsequently be saved as a new version in the database.
Examples
Load the latest version of a model on the same branch as a fixed version using the loadModel method from the Method Editor’s built-in method library.
// The modelLocationUri variable could have been obtained via
// Copy Location in the Model Manager workspace.
ModelItemVersion version = api
  .modelVersionByLocationUri(modelLocationUri);
 
BranchModelItem branchModelItem = version.branchItem();
Model m = loadModel(branchModelItem.modelLocationUri());
Save a regular version of a model originally loaded from the database.
ModelItemVersion version = api
  .saveRegularModel(model.tag(), "Saved a regular version.");
Save a draft version of a model originally loaded from the database.
ModelItemVersion version = api
  .saveDraftModel(model.tag(), "Saved a draft version.");
 
// Calling save directly yields the same result, except that
// you cannot specify a commit comment.
model.save();
Save a previously unsaved model as a new model in the database. The first version of the model is saved to the default branch in the default repository.
ModelItemVersion version = database
  .defaultRepository()
  .defaultBranch()
  .saveRegularModel(model.tag(), "Saved a new model.");
Force the creation of a new model in the database even if the model already exists in the database.
SaveModelItemParamGenerator p = DatabaseApiUtil.param()
  .forSaveModel()
  .withSourceModel(model.tag())
  .withTargetAsNew();
 
ModelItemVersion version = database
  .defaultRepository()
  .defaultBranch()
  .saveModel(p, null);