To get or modify models using Astah API, you need to access the project first.

section divider

How to access a project

Every time you access a project, you need to use ProjectAccessor.

You can access only one project at a time. So when you modify more than one project, make sure you open only one project at a time and close before you move to another. Here’re the sample code.

Open/Close a project

ProjectAccessor prjAccessor = AstahAPI.getAstahAPI().getProjectAccessor();"C:\test.asml");

Create/Save a project

ProjectAccessor prjAccessor = AstahAPI.getAstahAPI().getProjectAccessor();

Create a project and save as

ProjectAccessor prjAccessor = AstahAPI.getAstahAPI().getProjectAccessor();
section divider

Get project models

How to get the root of Astah SysML model tree

All model information in Astah SysML project is stored in a tree structure. The root of the tree is the project model. To get the project model, get the ProjectAccessor object, open the Astah SysML project file, then get Project Model (IModel object).

    ProjectAccessor prjAccessor = AstahAPI.getAstahAPI().getProjectAccessor();
    // Open project file;
    // Get project model
    IModel iModel = prjAccessor.getProject();

How to access Astah SysML model tree – Get all blocks recursively

Packages include Subsystems and Models.
Get all model elements directly under the package (IPackage) in an array by calling getOwnedElements() and get only packages abstracted from it.

   * Get blocks under packages recursively.
   * @param iPackage
   *     Selected Package
   * @param iBlocks
   *     The list of all stored blocks
   * @return The list of all stored packages
 private List getBlocks(IPackage iPackage) {
     List iBlocks = new ArrayList();
     INamedElement[] iNamedElements = iPackage.getOwnedElements();
     for (int i = 0; i < iNamedElements.length; i++) {
         INamedElement iNamedElement = iNamedElements[i];
         if (iNamedElement instanceof IPackage) {
         if (iNamedElement instanceof IBlock) {
     return iBlocks;