Model access

Model access includes the capabilities to access and modify model from the client extension script.

SysML element

SysmlElement is a structure used to interact with model related services and it identifies a model element by its elementId.

type SysMLElement = { 
	elementId: string;
}

ApiStatus

Model access APIs return the status of the API call. The status might include any value of the ApiStatus enumeration. When status is not ApiStatus.OK, a message is provided in the err return field.

const ApiStatus = Object.freeze({
  ERROR: 0,
  OK: 1,
  INFO: 2,
  WARNING: 3,
});

Model access APIs

You can create, read, update, or delete model elements by using a set of model access APIs. All changes are collected as part of changed content, which you require to save. You can access the model APIs by using the following:

/**
     * Adds a new member element to the owner element.
     * @param ownerElement The owner element to add the member element to.
     * @param elementType The type of the member element to add.
     * @param properties An optional array of properties to set on the member element.
     * @returns A promise that resolves with the added member element data, status, and error message.
     */
    addNewMemberElement(
      ownerElement: SysMLElement,
      elementType: string,
      properties?: Record<string, any>[]
    ): Promise<{ data: SysMLElement; status: API_STATUS; err: string }>;
    /**
     * Deletes an element from the repository.
     * @param element The element to delete.
     * @returns A promise that resolves with the status of the deletion and any error message.
     */
    deleteElement(
      element: SysMLElement | SysMLElement[]
    ): Promise<{ status: API_STATUS; err: string }>;
    /**
     * Gets the value of a property from an element.
     * @param element The element to get the property value from.
     * @param propertyName The name of the property to get the value of.
     * @returns A promise that resolves with the property value data, status, and error message.
     */
    getPropertyValue(
      element: SysMLElement,
      propertyName: string
    ): Promise<{
      data: string | SysMLElement | SysMLElement[];
      status: API_STATUS;
      err: string;
    }>;
    /**
     * Sets the value of a property on an element.
     * @param element The element to set the property value on.
     * @param propertyName The name of the property to set the value of.
     * @param value The value to set the property to.
     * @returns A promise that resolves with the status of the property value setting and any error message.
     */
    setPropertyValue(
      element: SysMLElement,
      propertyName: string,
      value: any
    ): Promise<{ status: API_STATUS; err: string }>;
    /**
     * Gets the root namespace of the project.
     * @returns SysMLElement of the root namespace.
     */
    getRootNamespace(): Promise<{
      data: SysMLElement;
      status: API_STATUS;
      err: string;
    }>;

    
  /**
     * Return true if the provided element is of the provided type. Otherwise return false
     * @param element The element to set the property value on.
     * @param type The type to check
     * @param strict Optional. Indicates whether to check that the type is the exact type, or to extend the test for super types as well
     * @returns A promise that resolves with the test result
     */
  isDerivedFromType(
      element: SysMLElement,
      type: string,
      strict?: boolean
    ): Promise<{ data: boolean; status: API_STATUS; err: string }>;
  

Consider the following example of a usage:

async function functionOfAnAction(payload) {
	// Get the root namespace
	const root = (await rseAPI.model.getRootNamespace()).data;

	// Add a package under the root namespace
	const sysPackage = (await rseAPI.model.addNewMemberElement(root, "Package", 
		[{ key: "declaredName", value: `System Package1` }])).data;

	// Get the declared name of the first element on which this action was invoked
	var selectedEl = { elementId: payload.data.elementIds[0] };
	const elName = (await modelAPI.getPropertyValue(selectedEl, "declaredName")).data;
}