### Execute Element using SimulationManager API Source: https://docs.nomagic.com/DEVG/starting-execution-249573640 This snippet demonstrates how to start the execution of an element using the SimulationManager.execute() Open API provided by Cameo Simulation Toolkit. The API allows specifying whether the session should be the main session and if it should start automatically. Supported executable elements include Classes, Behaviors, and simulation configuration elements. ```Java SimulationSession session1 = SimulationManager.execute(element); SimulationSession session2 = SimulationManager.execute(element, true, true); ``` -------------------------------- ### Python Script Code Source: https://docs.nomagic.com/DEVG/creating-script-249573603 Contains the actual logic for the script. This example demonstrates how to display a message dialog using JOptionPane and access script information via the pluginDescriptor variable. The script is executed when the application starts. ```python from javax.swing import JOptionPane # Script starts here print "Starting script, descriptor", pluginDescriptor JOptionPane.showMessageDialog( None, "I am a script!!!") ``` -------------------------------- ### Application Environment Directories Source: https://docs.nomagic.com/DEVG/application-environment-249573625 Access the application environment object to get information about installation, configuration, data, and other directories. ```APIDOC ## GET /application/environment ### Description Retrieves the application's environment object, providing access to directory information such as install, configuration, data, templates, and profiles. ### Method GET ### Endpoint /application/environment ### Parameters #### Query Parameters None #### Request Body None ### Request Example (No request body for GET request) ### Response #### Success Response (200) - **environmentObject** (com.nomagic.magicdraw.core.Application.Environment) - An object containing application environment directory details. - **installDirectory** (String) - The installation directory path. - **configurationDirectory** (String) - The configuration directory path. - **dataDirectory** (String) - The data directory path. - **templatesDirectory** (String) - The templates directory path. - **profilesDirectory** (String) - The profiles directory path. #### Response Example ```json { "environmentObject": { "installDirectory": "C:\\Program Files\\MagicDraw 19.0", "configurationDirectory": "C:\\Users\\User\\AppData\\Roaming\\MagicDraw 19.0\\config", "dataDirectory": "C:\\Users\\User\\AppData\\Local\\MagicDraw 19.0\\data", "templatesDirectory": "C:\\Program Files\\MagicDraw 19.0\\templates", "profilesDirectory": "C:\\Users\\User\\AppData\\Roaming\\MagicDraw 19.0\\profiles" } } ``` ``` -------------------------------- ### SimulationManager.execute Source: https://docs.nomagic.com/DEVG/starting-execution-249573640 Starts the execution of a specified element, creating a simulation session. This API allows control over whether the session is the main session and if it should start automatically. ```APIDOC ## POST /simulation/execute ### Description Starts the execution of a specified element using Cameo Simulation Toolkit, returning a simulation session. Allows configuration of the main session and automatic startup. ### Method POST ### Endpoint /simulation/execute ### Parameters #### Request Body - **element** (Element) - Required - The executable element (e.g., Class, Behavior, SimulationConfig) to execute. - **isMainSession** (Boolean) - Optional - Defaults to false. If true, this session becomes the main session, and its termination ends all executions. - **start** (Boolean) - Optional - Defaults to false. If true, the created session will start automatically. ### Request Example ```json { "element": "com.nomagic.uml.representation.model.UMLClass:12345", "isMainSession": true, "start": true } ``` ### Response #### Success Response (200) - **simulationSession** (SimulationSession) - An object representing the created simulation session. #### Response Example ```json { "simulationSession": { "id": "session-abc-123", "status": "RUNNING" } } ``` ``` -------------------------------- ### Stereotype Application and Management Example Source: https://docs.nomagic.com/DEVG/using-stereotypeshelper-249573449 A comprehensive example demonstrating the workflow of applying a stereotype to an element, setting one of its tagged values, and then removing the stereotype. This illustrates the core functionalities provided by StereotypesHelper and TagsHelper. ```java Element element = ....; // Element for which we add stereotype Project project = ...; // Project context String tagValue = "test value"; // Find profile and stereotype Profile profile = StereotypesHelper.getProfile(project, "ProfileNameExample"); Stereotype stereotype = StereotypesHelper.getStereotype(project, "StereotypeNameExample", profile); // Apply stereotype StereotypesHelper.addStereotype(element, stereotype); // Set stereotype property (tagged value) StereotypesHelper.setStereotypePropertyValue(element, stereotype, "TagName", tagValue); // Remove stereotype StereotypesHelper.removeStereotype(element, stereotype); ``` -------------------------------- ### GET /osmc/admin/license/query/{licenseServer} Source: https://docs.nomagic.com/DEVG/rest-api-change-log-249573685 Queries license information for a given license server. New query parameters have been added to specify licensing framework and mode. ```APIDOC ## GET /osmc/admin/license/query/{licenseServer} ### Description Queries license information for a given license server. ### Method GET ### Endpoint `/osmc/admin/license/query/{licenseServer}` ### Parameters #### Path Parameters - **licenseServer** (string) - Required - The ID of the license server. #### Query Parameters - **licenseFramework** (string) - Required - The licensing framework (DSLS or FlexNet). - **licensingMode** (string) - Optional - The licensing mode (ORGANIZATION_DEFINED or CUSTOM, for DSLS only). ``` -------------------------------- ### Application Runtime Information Source: https://docs.nomagic.com/DEVG/application-environment-249573625 Retrieve the application's runtime object to get its name, version, and file format. ```APIDOC ## GET /application/runtime ### Description Retrieves the current application's runtime object, which includes application name, version, and file format information. ### Method GET ### Endpoint /application/runtime ### Parameters #### Query Parameters None #### Request Body None ### Request Example (No request body for GET request) ### Response #### Success Response (200) - **runtimeObject** (com.nomagic.magicdraw.core.Application.Runtime) - An object containing application runtime details. - **applicationName** (String) - The name of the application. - **applicationVersion** (String) - The version of the application. - **fileFormat** (String) - The file format information. #### Response Example ```json { "runtimeObject": { "applicationName": "MagicDraw", "applicationVersion": "19.0", "fileFormat": "MDGN" } } ``` ``` -------------------------------- ### Implement and Add Project Window Source: https://docs.nomagic.com/DEVG/adding-custom-project-window-249573556 This section explains how to implement the `ProjectWindowsConfigurator` interface and add a new project window to MagicDraw. ```APIDOC ## Implement and Add Project Window ### Description Implements the `ProjectWindowsConfigurator` interface to define and add custom project windows. ### Method - Implement `com.nomagic.magicdraw.ui.ProjectWindowsConfigurator` - Use `ProjectWindowsManager.addWindow(ProjectWindow)` to add the window. ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body This involves implementing methods within the `ProjectWindowsConfigurator` interface, which may include defining the window's content and behavior. The `addWindow` method takes a `ProjectWindow` object. ### Request Example ```java // Within your custom ProjectWindowsConfigurator implementation public class MyProjectWindowConfigurator implements ProjectWindowsConfigurator { @Override public void configure(ProjectWindowsManager manager) { // Create and add your custom window ProjectWindow myWindow = new MyCustomProjectWindow(); // Assume MyCustomProjectWindow implements ProjectWindow manager.addWindow(myWindow); } } ``` ### Response This section describes the expected response or outcome of adding a project window. The `addWindow` method typically modifies the UI and does not return a specific value. ``` -------------------------------- ### Custom MyExecutionEngine Implementation (Java) Source: https://docs.nomagic.com/DEVG/creating-a-new-execution-engine-249573649 An example of a concrete implementation of the ExecutionEngine abstract class. This class demonstrates how to override and implement the init, execute, and onClose methods, including adding an engine listener in the init method. ```java public class MyExecutionEngine extends ExecutionEngine { public MyExecutionEngine(ExecutionEngineDescriptor engineDescriptor) { super(engineDescriptor); } @Override public void execute(Element element) { ... } @Override public void init(Element element) { Project project = Project.getProject(element); // add engine listener if needed EngineListener listener = new MyEngineListener(project); addEngineListener(listener); } @Override public void onClose() { ... } } ``` -------------------------------- ### Generated Custom Profile Implementation Class Source: https://docs.nomagic.com/DEVG/custom-profile-implementation-249573450 An example of a generated Java class for a custom profile implementation. This class provides static constants for profile and stereotype names, methods to get stereotype instances, and wrappers for stereotype tags. ```java import com.nomagic.magicdraw.uml.BaseElement; import com.nomagic.magicdraw.uml2.Profiles; import com.nomagic.profiles.ProfileCache; import com.nomagic.profiles.ProfileImplementation; import com.nomagic.profiles.ProfilesBridge; import com.nomagic.uml2.ext.magicdraw.classes.mdkernel.Element; import com.nomagic.uml2.ext.magicdraw.classes.mdkernel.Property; import com.nomagic.uml2.ext.magicdraw.mdprofiles.Stereotype; import javax.annotation.CheckForNull; import java.util.ArrayList; import java.util.Collection; import java.util.Collections; import java.util.HashSet; @SuppressWarnings("WeakerAccess, unused") public class CustomProfile extends ProfileImplementation { public static final String PROFILE_URI = "http://custom.com/custom_profile"; public static final String PROFILE_NAME = "CustomProfile"; private final PersonStereotype personStereotype; public static CustomProfile getInstance(BaseElement baseElement) { CustomProfile profile = ProfilesBridge.getProfile(CustomProfile.class, baseElement); if (profile == null) { return ProfilesBridge.createProfile(CustomProfile.class, baseElement, CustomProfile::new, PROFILE_NAME, PROFILE_URI); } return profile; } public CustomProfile(ProfileCache cache) { super(cache); personStereotype = new PersonStereotype(this); } public PersonStereotype person() { return personStereotype; } public static class PersonStereotype extends StereotypeWrapper { //stereotype Person and its tags public static final String STEREOTYPE_NAME = "Person"; public static final String COUNTRY = "country"; public static final String FRIENDS = "friends"; private final CustomProfile _p; @CheckForNull private Property country; @CheckForNull private Property friends; protected PersonStereotype(CustomProfile profile) { super(profile); _p = profile; } @Override @SuppressWarnings("ConstantConditions") public Stereotype getStereotype() { return getElementByName(STEREOTYPE_NAME); } @CheckForNull public Property getCountryProperty() { if (country == null) { country = getTagByName(getStereotype(), COUNTRY); } return country; } @CheckForNull public Property getFriendsProperty() { ``` -------------------------------- ### Generate Resource Distribution File via Command Line Source: https://docs.nomagic.com/DEVG/building-a-resource-distribution-file-249573369 Automate the creation of resource distribution files using the command-line tool. This method requires specifying the resource directory path, the output directory path, and the desired name for the resulting distribution file. Ensure all necessary libraries are included in the classpath. ```shell java -cp "lib/*;lib/bundles/*" com.nomagic.magicdraw.resourcemanager.distribution.GenerateResourceDistributionFileTask "E:\myResources" "E:\myBundles" "myCustomResourceDistributionFile" ``` -------------------------------- ### Get Stereotype Tag String - SysML Profile API Source: https://docs.nomagic.com/DEVG/sysml-profile-249573630 Retrieves a string constant representing a property of a stereotype (tag). This is useful for accessing stereotype attributes programmatically. Usage follows the pattern SysMLProfile.Stereotype._STEREOTYPE_NAME_. For example, SysMLProfile.RequirementStereotype._ID_ yields the string 'Id'. ```Java import com.nomagic.magicdraw.sysml.util.SysMLProfile; // Example: Get the string constant for the 'Id' property of the Requirement stereotype String idTag = SysMLProfile.RequirementStereotype._ID_; System.out.println(idTag); // Output: Id ``` -------------------------------- ### Navigable Opposite References Example Source: https://docs.nomagic.com/DEVG/accessing-and-modifying-model-element-properties-249573414 Illustrates how to access opposite references, such as getting stereotyped elements from a Stereotype object or typed elements from a Type object. Nomagic exposes all opposite references, even if not strictly navigable by UML spec. ```java Primary reference Element.getAppliedStereotype(), opposite Stereotype.get_stereotypedElement() ``` ```java Primary reference TypedElement.getType(), opposite Type.get_typedElementOfType() ``` -------------------------------- ### MDP Protocol - Resource Loading Source: https://docs.nomagic.com/DEVG/mdp-protocol-249573385 This section details how to use the mdp:// protocol to load resources (like icons) directly from MagicDraw or plugin JARs and classpaths. ```APIDOC ## MDP Protocol - Resource Loading ### Description Use the `mdp://resource/` host to load resources from JARs or classpaths. This is commonly used to reference icons or other assets bundled within MagicDraw or its plugins. ### Method N/A (Custom URL Protocol) ### Endpoint `mdp://resource/` ### Parameters #### Path Parameters - **path_to_resource** (string) - Required - The relative path to the resource within the JAR or classpath (e.g., `com/nomagic/magicdraw/icons/diagrams/activitydiagram.png`). ### Request Example ``` mdp://resource/com/nomagic/magicdraw/icons/diagrams/activitydiagram.png ``` ### Response #### Success Response (200) N/A (This is a URL protocol, not a direct API response. The resource is loaded by the client application.) #### Response Example N/A ``` -------------------------------- ### Loading a Project from a File in Java Source: https://docs.nomagic.com/DEVG/project-loading-and-saving-249573398 Explains how to load a project from a specified file path. It requires creating a File object, then a ProjectDescriptor from the file's URI, and finally using the loadProject method. The boolean parameter controls silent mode during loading. ```java ProjectsManager projectsManager = Application.getInstance().getProjectsManager(); File file = new File(projectFilePath); ProjectDescriptor projectDescriptor = ProjectDescriptorsFactory.createProjectDescriptor(file.toURI()); projectsManager.loadProject(projectDescriptor, true); ``` -------------------------------- ### JUnit 5 Test Case with MagicDraw Application Extension Source: https://docs.nomagic.com/DEVG/creating-junit-test-case-249573346 Shows a JUnit 5 test case utilizing the MagicDrawApplication extension. This extension automatically starts MagicDraw before running test cases and supports JUnit 5's specific annotations for setup and teardown. ```java import com.nomagic.magicdraw.tests.MagicDrawApplication; import org.junit.jupiter.api.*; import org.junit.jupiter.api.extension.ExtendWith; @ExtendWith(MagicDrawApplication.class) public class MyTest { @BeforeEach void beforeTestBegins() { //do test case setup here, e.g. load project } @Test void testSomething() { //implement the unit test case here } @AfterEach void afterTestDone() { //do tear down here, e.g. close project } } ``` -------------------------------- ### JUnit 4 Test Case with MagicDraw Test Runner Source: https://docs.nomagic.com/DEVG/creating-junit-test-case-249573346 Illustrates a JUnit 4 test case using the MagicDrawTestRunner. This runner automatically starts MagicDraw and performs memory leak tests after each test case. It supports standard JUnit annotations for setup and teardown. ```java import com.nomagic.magicdraw.tests.MagicDrawTestRunner; import org.junit.*; import org.junit.runner.RunWith; @RunWith(MagicDrawTestRunner.class) public class MyTest { @Before public void beforeTestBegins() { //do test case setup here, e.g. load project } @Test public void testSomething() { //implement the unit test case here } @After public void afterTestDone() { //do tear down here, e.g. close project } } ``` -------------------------------- ### Importing a Project File in Java Source: https://docs.nomagic.com/DEVG/project-loading-and-saving-249573398 Details the process of importing a project from a file. Similar to loading, it involves creating a ProjectDescriptor from a file's URI, but uses the importProject method instead. This is useful for merging or including content from other project files. ```java ProjectsManager projectsManager = Application.getInstance().getProjectsManager(); File file = new File(projectFilePath); ProjectDescriptor projectDescriptor = ProjectDescriptorsFactory.createProjectDescriptor(file.toURI()); projectsManager.importProject(projectDescriptor); ``` -------------------------------- ### JUnit 3 Test Case Creation with MagicDraw Source: https://docs.nomagic.com/DEVG/creating-junit-test-case-249573346 Demonstrates creating a JUnit 3 test case by extending MagicDrawTestCase. This class automatically starts MagicDraw, runs memory leak tests, and allows for custom setup and teardown methods. It also supports creating test suites with specific test data. ```java import com.nomagic.magicdraw.tests.MagicDrawTestCase; import java.util.TestSuite; public class MyTest extends MagicDrawTestCase { public MyTest(String testMethodToRun, String testName) { super(testMethodToRun, testName); } @Override protected void setUpTest() throws Exception { super.setUpTest(); //do setup here } @Override protected void tearDownTest() throws Exception { super.tearDownTest(); //do tear down here } public void testSomething() { //implement the unit test here } public static Test suite() throws Exception { //you may create a test suite with several instances of the test. TestSuite suite = new TestSuite(); suite.addTest(new MyTest("testSomething", "MagicDraw Test Sample")); suite.addTest(new MyTest("testSomething", "Another MagicDraw Test Sample")); return suite; } } ``` -------------------------------- ### Extend ProjectCommandLine for Core Project Launchers (Java) Source: https://docs.nomagic.com/DEVG/implementing-command-line-launchers-249573599 Extend `com.nomagic.magicdraw.commandline.ProjectCommandLine` for a convenience launcher that simplifies working with projects. Override `parseArguments` to handle custom arguments and `execute` to perform actions on opened projects. ```java import com.nomagic.magicdraw.commandline.ProjectCommandLine; import com.nomagic.magicdraw.core.Project; import java.util.Properties; public class MyProjectCommandLine extends ProjectCommandLine { @Override protected void parseArguments(String[] args) { // TODO: Parse your custom arguments here super.parseArguments(args); // Call super to parse default project arguments } @Override protected int execute(Properties projectArguments, Project project) { // TODO: Implement your action logic for each opened project here return 0; // Success code } } ``` -------------------------------- ### Get Stereotype Element - SysML Profile API Source: https://docs.nomagic.com/DEVG/sysml-profile-249573630 Obtains a stereotype element instance from a project or an element within that project. This allows interaction with specific stereotypes like «Block». The method requires an instance of the SysMLProfile. Usage examples include SysMLProfile._getInstance_(project).stereotype().getStereotype() or SysMLProfile._getInstance_(element).stereotype().getStereotype(). ```Java import com.nomagic.magicdraw.sysml.util.SysMLProfile; import com.nomagic.magicdraw.core.Project; import com.nomagic.uml2.ext.magicdraw.classes.mdkernel.Element; // Assuming 'project' is an instance of com.nomagic.magicdraw.core.Project // Assuming 'element' is an instance of com.nomagic.uml2.ext.magicdraw.classes.mdkernel.Element // Get the «Block» stereotype using a project instance // Note: Actual stereotype object retrieval might differ based on API specifics. // This example illustrates the conceptual usage pattern provided. // For detailed implementation, refer to MagicDraw's API documentation. // Example placeholder: // Stereotype blockStereotype = SysMLProfile._getInstance_(project).block().getStereotype(); // Example using a specific element (conceptual): // Stereotype blockStereotypeFromElement = SysMLProfile._getInstance_(element).block().getStereotype(); ``` -------------------------------- ### Loading a Server Project in Java Source: https://docs.nomagic.com/DEVG/project-loading-and-saving-249573398 Illustrates how to load a project residing on a server. This method requires the project's qualified name to create a ProjectDescriptor using TeamworkUtils. The loadProject method is then used to fetch the project. A null check is included for safety. ```java ProjectsManager projectsManager = Application.getInstance().getProjectsManager(); ProjectDescriptor projectDescriptor = TeamworkUtils.getRemoteProjectDescriptorByQualifiedName(remoteProjectQualifiedName); if (projectDescriptor != null) { projectsManager.loadProject(projectDescriptor, true); } ``` -------------------------------- ### Get Revision Data via GET /revisions/{revisionId} Source: https://docs.nomagic.com/DEVG/model-manipulation-249573682 Fetches the first-level object in a revision, containing rootObjectIDs. This is the entry point for model traversal. ```json { "commitType": "NORMAL", "branchID": "../..", "resourceID": "../../..", "@base": "http://127.0.0.1:8111/osmc/resources/4615e8fa-81e5-40e0-a51b-8496a48caf18/revisions/5/elements", "author": "Administrator", "@type": [ "RDFSource", "kerml:Revision" ], "pickedRevision": -1, "description": "Branch \"xx\" created", "@context": "http://127.0.0.1:8111/osmc/schemas/revision", "directParent": 3, "dependencies": [], "rootObjectIDs": [ "429f969a-5c81-45f4-94af-8cf983f22950", "ec6060a3-f3d9-482b-93a3-32af9e19202c", "ca9a0235-f0f7-46b7-a142-e79a67c2d00d", "f7c3ae92-af44-4dab-8163-a199ca05c006", "ba3d0700-1062-4baf-a1df-a55a4f31ce54", "0f14cd2d-2fd0-4523-950c-627d59e1a43d", "7cd22dea-aaf8-4e08-bd67-5bd975c3f06a", "af1042fa-8b1b-4cf2-bb7d-98dd1b881da3", "6d24e5e7-cdff-4e9e-85b8-28b3088f85b6", "243020e5-da6c-4896-b32a-fcba0e93ac8d", "f7449238-5cd1-41eb-9025-040210b02d93", "4d2459a1-49dc-4eb7-aa82-9bbb4a76b038", "b242613d-957e-4aec-9333-e5938f50b2ab", "9b953064-e422-4391-b7d9-43a2d4f14a32", "fc997cfd-23c5-4d0b-9953-06667dcde0dd", "29d9416b-ead5-4a9d-b530-b23de836f1b8", "7af3f24b-2da9-4b31-94b3-a87f15747296" ], "createdDate": "1533051367", "ID": "", "artifacts": "artifacts" } ``` -------------------------------- ### Creating a New Relationship Source: https://docs.nomagic.com/DEVG/creating-new-relationship-objects-249573419 This section outlines the steps to create a new relationship object, including setting its client and supplier elements and adding it to a parent element. ```APIDOC ## Create New Relationship Object ### Description This procedure details how to programmatically create a new relationship object within the MagicDraw model. ### Method This is a procedural guide, not a direct API endpoint. ### Endpoint N/A ### Parameters N/A ### Request Example N/A ### Response N/A ## Helper Methods for Relationships ### Description Provides methods for checking if a model element is a relationship and for retrieving or setting its client and supplier elements. ### Method Java Methods (MagicDraw API) ### Endpoint N/A ### Parameters #### `isRelationship(Element element)` - **element** (Element) - Required - The model element to check. #### `getSupplierElement(Element relationship)` - **relationship** (Element) - Required - The relationship element. #### `getClientElement(Element relationship)` - **relationship** (Element) - Required - The relationship element. #### `setSupplierElement(Element relationship, Element supplier)` - **relationship** (Element) - Required - The relationship element. - **supplier** (Element) - Required - The supplier element to set. #### `setClientElement(Element relationship, Element client)` - **relationship** (Element) - Required - The relationship element. - **client** (Element) - Required - The client element to set. ### Request Example ```java // Example usage: if (CoreHelper.isRelationship(someElement)) { Element supplier = CoreHelper.getSupplierElement(relationship); CoreHelper.setClientElement(relationship, clientElement); } ``` ### Response #### Success Response Methods return the relevant Element objects or void. #### Response Example N/A ``` -------------------------------- ### Generate Encrypted Server Password (Shell) Source: https://docs.nomagic.com/DEVG/implementing-command-line-launchers-249573599 Generate an encrypted password for server authentication by running a command line launcher with the `generateServerPassword` argument. This is useful for securely connecting to servers, especially for Teamwork Cloud projects. ```shell # To generate an encrypted password interactively: java -jar YourMagicDrawLauncher.jar generateServerPassword # To generate an encrypted password with a provided password: java -jar YourMagicDrawLauncher.jar generateServerPassword=yourSecretPassword ``` -------------------------------- ### OCL2.0 Expression Example Source: https://docs.nomagic.com/DEVG/create-ocl2-0-validation-rule-249573561 This is an example of an OCL2.0 expression used to define a validation rule. It checks if the 'name' property of an element is not an empty string. This rule can be used within a validation suite. ```ocl name <> '' ``` -------------------------------- ### Load Icons using IconsFactory Source: https://docs.nomagic.com/DEVG/working-with-icons-249573384 Demonstrates how to use the `IconsFactory` utility class to load icons. This class handles caching and ensures icons are loaded efficiently, especially with HiDPI support. ```java import com.nomagic.magicdraw.icons.IconsFactory; // Example usage: // Icon icon = IconsFactory.loadIcon("/com/product/icons/myIcon.png"); // This will load the appropriate icon based on screen resolution and caching. ``` -------------------------------- ### Get Tagged Value Source: https://docs.nomagic.com/DEVG/using-stereotypeshelper-249573449 Retrieves the value of a tagged value (stereotype property) associated with an element. Values are returned as a List, even for tags with a multiplicity of 1. Provides methods to get the full list or the first value directly. ```java // Get the list of values for a tagged value List values = TagsHelper.getStereotypePropertyValue(element, property); // or List values = TagsHelper.getStereotypePropertyValue(element, stereotype, "TagName"); // Get the first value of a tagged value Object firstValue = TagsHelper.getStereotypePropertyFirst(element, property); // or Object firstValue = TagsHelper.getStereotypePropertyFirst(element, stereotype, "TagName"); // Get the tagged value (often returns the first value) Object taggedValue = TagsHelper.getTaggedValue(element, property); // or Object taggedValue = TagsHelper.getTaggedValue(element, stereotype, "TagName"); ``` -------------------------------- ### Get Element Icon using ElementIcon utility Source: https://docs.nomagic.com/DEVG/retrieving-element-icon-249573437 This Java code snippet demonstrates how to retrieve an element's icon using the `ElementIcon.getIcon(element)` method. It also shows how to get a specific UML Package icon using `ElementIcon.getIconByClassType()`. ```java Element element = ...; //get element icon ResizableIcon icon = ElementIcon.getIcon(element); //get UML Package icon ResizableIcon packageIcon = ElementIcon.getIconByClassType(com.nomagic.uml2.ext.magicdraw.classes.mdkernel.Package.class); ``` -------------------------------- ### HTTP Header Example for Token Authentication Source: https://docs.nomagic.com/DEVG/personal-access-token-authentication-sample-for-teamwork-cloud-rest-api-249573679 This example demonstrates the correct format for the Authorization header when using a personal access token for Teamwork Cloud REST API calls. The 'Token' type is specified before the token itself. ```http Authorization: Token eyJhbGciOiJSUzI1NiJ9.eyJzdWIiOiJBZG1pbmlzdHJhdG9yIiwiYXVkIjoidHdjLXJlc3QtYXBp IiwiaXNzIjoiaHR0cHM6XC9cLzEyNy4wLjAuMTo4NTU1XC9hdXRoZW50aWNhdGlvbiIsImV4cCI6M TYwNjI5OTc3NywiaWF0IjoxNjA2Mjk4ODc3fQ.bA- S5hHeSlV8AFoQVzzfIseC3qlmqQoBQREiapHN6I5CcvwetKdSVztWKkssSGjm31Y1zqoULio7_1Ma mtGBbbzvA1WWQYFRiYk0D612yNDv4uNHBbNLNEv61TYNLwdPwPh0atVRehkh- LSgjipXTvXj4mZViE0NHKIG9U7htA9Zzvxvck2JDXe_eU2- 4TCNm8II89ROaEb1tZ5nD84ieRbzJWqrcVTdqU2YfbIUeew5Nir8obkLYgixBXFKWsTHi3jNuoBx3 KcAIyZqL6cjtsCER4wbk4PEEDC57UVsOcsXWr6yvXIoVdJMOiDHo_fJMkgOjDqSyIL-2B21O-Y-GA ``` -------------------------------- ### AlfImporter Initialization Source: https://docs.nomagic.com/DEVG/importer-api-249573695 Instantiate an AlfImporter with the model directory path and an optional progress status object. ```APIDOC ## AlfImporter Initialization ### Description Instantiates an `AlfImporter` object to manage the process of importing Alf code. ### Constructor `AlfImporter(modelDirectoryPath: String, progressStatus: ProgressStatus?)` ### Parameters #### Path Parameters - **modelDirectoryPath** (String) - Required - The root directory for all files being imported. - **progressStatus** (ProgressStatus) - Optional - An object to update with the names of files being imported. Can be `null`. ### Request Example ```json { "modelDirectoryPath": "/path/to/your/model", "progressStatus": null } ``` ### Response (This is a constructor, no direct response) ### Response Example (N/A) ``` -------------------------------- ### Extend CommandLine for Core General Launchers (Java) Source: https://docs.nomagic.com/DEVG/implementing-command-line-launchers-249573599 Extend the `com.nomagic.magicdraw.commandline.CommandLine` class to create a general command line launcher for core-related batch programs. You need to override the `parseArgs` method for argument parsing and the `execute` method for action execution. ```java import com.nomagic.magicdraw.commandline.CommandLine; public class MyGeneralCommandLine extends CommandLine { @Override protected void parseArgs(String[] args) { // TODO: Parse your custom arguments here } @Override protected int execute() { // TODO: Implement your action logic here return 0; // Success code } } ``` -------------------------------- ### Recursively Add Files to Code Engineering Set (Java) Source: https://docs.nomagic.com/DEVG/code-engineering-set-249573586 This method adds all source code files recursively starting from a given directory to the CodeEngineeringSet for reverse engineering. It takes a single File object representing the starting directory. Ensure this directory contains the source code files and is within the working directory. ```java import com.nomagic.magicdraw.ce.CodeEngineeringSet; import java.io.File; // Assuming you have a CodeEngineeringSet object named 'codeEngineeringSet' // and a File object representing the directory named 'sourceDirectory' // Example: Creating a dummy CodeEngineeringSet and File object for demonstration // In a real scenario, these would be obtained from the MagicDraw API or file system // CodeEngineeringSet codeEngineeringSet = ...; // File sourceDirectory = ...; // Placeholder for actual CodeEngineeringSet object CodeEngineeringSet codeEngineeringSet = null; // Replace with actual object File sourceDirectory = new File("path/to/your/source/code/directory"); if (codeEngineeringSet != null && sourceDirectory.isDirectory()) { codeEngineeringSet.addAllFilesRecursivelyToCES(sourceDirectory); System.out.println("All source files recursively added to CodeEngineeringSet."); } else { System.out.println("CodeEngineeringSet or source directory is not valid."); } ``` -------------------------------- ### Set JVM System Properties for Test Configuration Source: https://docs.nomagic.com/DEVG/configure-test-environment-249573350 This snippet demonstrates how to set essential JVM system properties for configuring the test environment. These properties include the installation root directory and the resource directory for test cases. Ensure these paths are correctly specified when running your tests. ```bash -Dinstall.root=path_to_modeling_tool_installation_directory -Dtests.resources=path_to_resources_directory ``` -------------------------------- ### Example: Authenticate with Teamwork Cloud REST API using cURL Source: https://docs.nomagic.com/DEVG/token-based-authentication-sample-for-teamwork-cloud-rest-api-249573677 Demonstrates how to use a token to authenticate with the Teamwork Cloud REST API via cURL. It includes the necessary Authorization header with the 'Token' type. The example shows a typical request and the server's response, including authentication success and session cookies. ```shell curl -v -k -H "Authorization: Token eyJhbGciOiJSUzI1NiJ9.eyJzdWIiOiJBZG1pbmlzdHJhdG9yIiwiYXVkIjoidHdjLXJlc3QtYXBp IiwiaXNzIjoiaHR0cHM6XC9cLzEyNy4wLjAuMTo4NTU1XC9hdXRoZW50aWNhdGlvbiIsImV4cCI6M TYwNjI5OTc3NywiaWF0IjoxNjA2Mjk4ODc3fQ.bA- S5hHeSlV8AFoQVzzfIseC3qlmqQoBQREiapHN6I5CcvwetKdSVztWKkssSGjm31Y1zqoULio7_1Ma mtGBbbzvA1WWQYFRiYk0D612yNDv4uNHBbNLNEv61TYNLwdPwPh0atVRehkh- LSgjipXTvXj4mZViE0NHKIG9U7htA9Zzvxvck2JDXe_eU2- 4TCNm8II89ROaEb1tZ5nD84ieRbzJWqrcVTdqU2YfbIUeew5Nir8obkLYgixBXFKWsTHi3jNuoBx3 KcAIyZqL6cjtsCER4wbk4PEEDC57UVsOcsXWr6yvXIoVdJMOiDHo_fJMkgOjDqSyIL-2B21O-Y-GA" https://127.0.0.1:8111/osmc/login ``` ```text > GET /osmc/login HTTP/1.1 > Host: 127.0.0.1:8111 > User-Agent: curl/7.55.1 > Accept: */* > Authorization: Token eyJhbGciOiJSUzI1NiJ9.eyJzdWIiOiJBZG1pbmlzdHJhdG9yIiwiYXVkIjoidHdjLXJlc3QtYXBp IiwiaXNzIjoiaHR0cHM6XC9cLzEyNy4wLjAuMTo4NTU1XC9hdXRoZW50aWNhdGlvbiIsImV4cCI6M TYwNjI5OTc3NywiaWF0IjoxNjA2Mjk4ODc3fQ.bA- S5hHeSlV8AFoQVzzfIseC3qlmqQoBQREiapHN6I5CcvwetKdSVztWKkssSGjm31Y1zqoULio7_1Ma mtGBbbzvA1WWQYFRiYk0D612yNDv4uNHBbNLNEv61TYNLwdPwPh0atVRehkh- LSgjipXTvXj4mZViE0NHKIG9U7htA9Zzvxvck2JDXe_eU2- 4TCNm8II89ROaEb1tZ5nD84ieRbzJWqrcVTdqU2YfbIUeew5Nir8obkLYgixBXFKWsTHi3jNuoBx3 KcAIyZqL6cjtsCER4wbk4PEEDC57UVsOcsXWr6yvXIoVdJMOiDHo_fJMkgOjDqSyIL-2B21O-Y-GA > < HTTP/1.1 204 No Content < Content-Length: 0 < Content-Type: application/octet-stream < Date: Wed, 25 Nov 2020 10:08:44 GMT < Accept-Ranges: bytes < Server: Restlet-Framework/2.2.3 < Vary: Accept-Charset, Accept-Encoding, Accept-Language, Accept < Set-Cookie: twc-rest-current-user=Administrator; Path=/osmc; Expires=Wed, 25 Nov 2020 10:23:44 GMT < Set-Cookie: twc-rest-session-id=f40ef933-5461-4058-a1e7-9b8d4021aa8a; Path=/osmc; Expires=Wed, 25 Nov 2020 10:23:44 GMT < * Connection #0 to host 127.0.0.1 left intact ``` -------------------------------- ### GET /elements/{elementId} Source: https://docs.nomagic.com/DEVG/model-manipulation-249573682 Retrieves a specific element by its ID. This is used to traverse down the model hierarchy, fetching child elements. ```APIDOC ## GET /elements/{elementId} ### Description Retrieves a specific element by its unique ID. This endpoint is crucial for navigating the hierarchical structure of a MagicDraw model, allowing you to fetch individual elements and their properties. ### Method GET ### Endpoint `/elements/{elementId}` ### Parameters #### Path Parameters - **elementId** (string) - Required - The UUID of the element to retrieve. ### Response #### Success Response (200) - **kerml:ownedElement** (array) - A list of UUIDs for the child elements owned by this element. - **kerml:esiData** (object) - Contains specific data attributes of the element, such as its name, project ID, and version. #### Response Example ```json { "kerml:name": "UML Model", "namespace": "com.nomagic.magicdraw.uml_model", "project": { "@id": "429f969a-5c81-45f4-94af-8cf983f22950" }, "internalVersion": "1", "version": "17.0", "sections": [ { "@id": "b3e68e8e-2253-4726-8d05-d8f74fd0ba5a" } ] } ``` ``` -------------------------------- ### Extend ProjectCommandLineAction for Plugin Project Launchers (Java) Source: https://docs.nomagic.com/DEVG/implementing-command-line-launchers-249573599 Extend `com.nomagic.magicdraw.commandline.ProjectCommandLineAction` for a convenience launcher for plugin-related batch programs that simplifies project handling. Override the `execute` method to perform actions on opened projects, receiving original arguments and project-specific properties. ```java import com.nomagic.magicdraw.commandline.ProjectCommandLineAction; import com.nomagic.magicdraw.core.Project; import java.util.Properties; public class MyProjectCommandLineAction extends ProjectCommandLineAction { @Override public int execute(String[] originalArgs, Properties projectArguments, Project project) { // TODO: Implement your action logic for each opened project here // originalArgs: Array of all arguments originally passed to the command line. // projectArguments: Properties parsed from command line arguments specific to the project. // project: The opened project. return 0; // Success code } } ``` -------------------------------- ### MDP Protocol - Attached File Loading Source: https://docs.nomagic.com/DEVG/mdp-protocol-249573385 This section explains how to use the mdp:// protocol to load resources from files attached to the active MagicDraw project. ```APIDOC ## MDP Protocol - Attached File Loading ### Description Use the `mdp://attachedFile/` host to load resources from files that are attached to the active MagicDraw project. This allows referencing project-specific assets. ### Method N/A (Custom URL Protocol) ### Endpoint `mdp://attachedFile#` ### Parameters #### Path Parameters - **attached_file_id** (string) - Required - The unique identifier of the attached file within the project (e.g., `_18_2_8ca0285_1436339188295_24687_13288`). Note the underscore prefix and suffix are part of the ID. ### Request Example ``` mdp://attachedFile#_18_2_8ca0285_1436339188295_24687_13288 ``` ### Response #### Success Response (200) N/A (This is a URL protocol, not a direct API response. The resource is loaded by the client application.) #### Response Example N/A ```