In this article we will learn how to use StarUML to create, delete, and modify elements. Hurry up and learn! Most importantly, you should not create or modify elements directly, var class.1=newUMLClass () or class.name =”New name “, because all changes should be made by undo and redo supported operations.

Create the element

Creating model elements

You can createModel elements with option objects by calling the createModel function app.factory.

Option objects may have the following fields:

  • Id: ID of the factory function that creates the element. To see the complete list of ids, execute app.factory.getModelids ()
  • Parent Contains the parent element of the created element.
  • Field (optional) : Field name of the parent element (default: ownedElements)
  • ModelInitializer (Optional) : The function that initializes the created model elements.

You can see the created elements in the Model Explorer, and undo and redo can be used for each creation.

Create a chart

Call the createDiagram function app.factory to create a diagram with an option object:

Option objects may have the following fields:

  • Id: ID of the factory function that creates the diagram. To see the full list of D, please perform app. Factory. GetDiagramIds ().
  • Parent: To include the parent element of the diagram being created.
  • Options: Objects that contain the following options.
  • DiagramInitializer (Optional) : Initializes the function that creates the diagram.

Create model elements and view elements at once

Call the createModelAndView function app.factory to use the option object to create model elements and view elements at once.

Option objects may have the following fields:

  • Id: indicates the ID of the factory function. To see the full list of ID, please perform Factory. GetModelAndViewIds ().
  • Parent: Contains the parent element of the model element being created.
  • Diagram: The diagram element to contain the view element created.
  • ModelInitializer (Optional) : The function that initializes the created model elements.
  • ViewInitializer (Optional) : The function that initializes the created view elements.
  • X1, y1, ×2, y2 (Optional) : Rectangular coordinates used to initialize the position and size of the created view element.
  • Tailview, HeadView (optional) : If you are trying to create a relationship (for example, UMLAssociation), the view element created connects the two view elements, tailView and HeadView.
  • TailModel, and headModel (optional) : If you are trying to create a relationship, the model element created will take these two model elements, tailModel headModel.
  • ContainerView (Optional) : The view element to contain the created view element.

The function createModelAndView returns the created view element, so you need to access the Model field to get the created model element. (e.g. Classview1.model). The following code creates the two classes and the association that connects them.

A view element that creates an existing model element

Call the createViewof function app.factory to create a view element of an existing model element using the option object.

Option objects may have the following fields:

  • Mode1: The model element referenced by the view element created.
  • Diagram: The diagram element to contain the view element created.
  • ViewInitializer (Optional) : The function that initializes the created view elements.
  • X, y (optional) : Positions of view elements to be created.
  • ContainerView (Optional) : The view element to contain the created view element.

You will see one more class view element at (500,500).

Add labels to elements

If you want to extend an element with additional tags, you can create the app.factory Tag by calling the createModel function with a Tag parameter. There are five types of tags: String, Number, Boolean, Reference, and Hidden. Hidden tags are not shown in the diagram, but other tags are shown as properties. Check format > Show Properties menu. The following code creates a string tag for the selected element.

Remove elements

Want to delete some elements, please app. Engine. DeleteElements use the called function model and view element as a parameter

Modify the element

Changing property values

You should not modify the attributes of the element directly, class. name=”New name “because all changes should be made by undo and redo supported operations.

To change the property value, use the app.engine.setProperty() function

example

The sequence diagram

This is an example of creating a sequence diagram of two lifelines and a message

That’s the StarUML tutorial, creating, deleting, and modifying elements, for more on macw.com!