Get models and Presentations

This page shows you how to get models and presentations by using Astah SysML API.
To learn a difference between models and presentations, please read this page.

section divider

Get models

You can search for models with Astah SysML API. There are three methods to search from ProjectAccessor.

  1. Search by name and element kind
  2. Search by element type
  3. Search by using ModelFinder
section divider

Search by name and element kind

public INamedElement[] findElements(Class elementKind, String name) throws ProjectNotFoundException;)
This search does not apply for presentations such as ITopicPresentation.

Sample : findElements(Class elementKind, String name)

ProjectAccessor prjAccessor = AstahAPI.getAstahAPI().getProjectAccessor();
prjAccessor.open("C:\\test.asml");
//Search a Block Definition Diagram named dgm0
INamedElement[] iNamedElements = prjAccessor.findElements(IBlockDefinitionDiagram.class, "dgm0");
//Search a Block named A
iNamedElements = prjAccessor.findElements(IBlock.class, "A");
//Search an attribute named B
iNamedElements = prjAccessor.findElements(IAttribute.class, "B");
//Search an operation named C
iNamedElements = prjAccessor.findElements(IOperation.class, "C");
//Search an association named D
iNamedElements = prjAccessor.findElements(IAssociation.class, "D");
//Search an UseCase named E
iNamedElements = prjAccessor.findElements(IUseCase.class, "E");
//Search an Include named F
iNamedElements = prjAccessor.findElements(IInclude.class, "F");

//Search a state named G
iNamedElements = prjAccessor.findElements(IState.class, "G");
//Search a pseudostate named H
iNamedElements = prjAccessor.findElements(IPseudostate.class, "H");
//Search a transition named I
iNamedElements = prjAccessor.findElements(ITransition.class, "I");

//Search a partition named J
iNamedElements = prjAccessor.findElements(IPartition.class, "J");
//Search an action named K
iNamedElements = prjAccessor.findElements(IAction.class, "K");
//Search an objectnode named L
iNamedElements = prjAccessor.findElements(IObjectNode.class, "L");
//Search a flow named M
iNamedElements = prjAccessor.findElements(IFlow.class, "M");


//Search a lifeline named N
iNamedElements = prjAccessor.findElements(ILifeline.class, "N");
//Search a message named O
iNamedElements = prjAccessor.findElements(IMessage.class, "O");

prjAccessor.close();
section divider

Search by element type

public abstract INamedElement[] findElements(Class elementKind) throws ProjectNotFoundException;
This search does not apply for presentations such as ITopicPresentation.

Example : Search all Block Definition Diagrams by using findElements(Class elementKind)

ProjectAccessor prjAccessor = AstahAPI.getAstahAPI().getProjectAccessor();
prjAccessor.open("C:\\test.asml");
//Search a class diagram
INamedElement[] iNamedElements = prjAccessor.findElements(IBlockDefinitionDiagram.class);
prjAccessor.close();
section divider

Search by using ModelFinder

public INamedElement[] findElements(ModelFinder picker) throws ProjectNotFoundException;

Example : Search by using findElements(ModelFinder picker)

    //A class that implements ModelFinder interface. 
    //Search a Block Definition Diagram named dgm0
    class BlockDefinitionDiagramPicker implements ModelFinder {
        public boolean isTarget(INamedElement namedElement) {
            if (namedElement instanceof IBlockDefinitionDiagram) {
                if ("dgm0".equals(namedElement.getName())) {
                    return true;
                }
                return false;
            }
            return false;
        }
    }
ProjectAccessor prjAccessor = AstahAPI.getAstahAPI().getProjectAccessor();
prjAccessor.open("C:\\test.asml");
//Search a Block Definition Diagram named dgm0
INamedElement[] iNamedElements = prjAccessor.findElements(new BlockDefinitionDiagramPicker());
prjAccessor.close();
section divider

Get presentations

To learn a difference between models and presentations, please read this page.

Presentation Overview

IPresentation is a base interface of presentation. INodePresentation and ILinkPresentation are derived from IPresentation.

Name of presentation interface

Description

Presentations

INodePresentationInterface for Rectangular presentationPackage, Frame, Note, Block, Part, UseCase, State, Partition, Action, Lifeline, ConstraintProperty, Port, Requirement, TestCase, Topic, Boundary and etc.
ILinkPresentationInterface for Line presentationNest, NoteAnchor, Association, Generalization, Realization, Usage, Dependency, Connector, Extend, Include, Binding Connector, Message, Anchor, DeriveReqt, Copy, Satisfy, Verify, Refine, Trace and etc.

How to get all presentations on a diagram

Sample: Get all presentations on all diagrams in a project model.

ProjectAccessor prjAccessor = AstahAPI.getAstahAPI().getProjectAccessor();
prjAccessor.open("C:a.asml", true, false, true);
IModel project = prjAccessor.getProject();
IDiagram[] diagrams = project.getDiagrams();
for (int i = 0; i < diagrams.length; i++) {
    IPresentation[] iPresentations = diagrams[i].getPresentations();
}

How to get presentation information of a model

Use getPresentations() of IElement to get information of presentations.

  • Each model has one presentation in Statemachine Diagram, Activity Diagram, Sequence Diagram.
  • Some presentations such as Noteanchor and Frame do not have models.