MagicDraw 18.2 Documentation

Skip to end of metadata
Go to start of metadata

Plugins of the modeling tool allows adding some custom action into program actions sets. This approach works fine providing custom actions for user in UI, but does not solve custom task executing in the batch mode. For example, if you want to run MagicDraw or other modeling tool, open some project, execute code generation and close MagicDraw, plugins approach will not work.

The application cannot be run on the headless device even in batch mode. The graphical environment is required.

 

Using API you can run the program in the batch mode. For this you need to extend the com.nomagic.magicdraw.commandline.CommandLine class.

The example of the code:

 

public class ExportDiagramImages extends CommandLine
{
    @Override
    protected byte execute()
    {
        File projectFile = ...;

        //open a project
        ProjectDescriptor projectDescriptor = ProjectDescriptorsFactory.createProjectDescriptor(projectFile.toURI());
        Application.getInstance().getProjectsManager().loadProject(projectDescriptor, true);

        // a project is opened and now you can work with your project
        return 0;
    }
    @Override
    protected void parseArgs(String[] args) throws Exception
    {
        for (int i = 0; i < args.length; i++)
        {
            final String argument = args[i];
            if (!checkArgument(argument, PROJECT))
            {
                checkArgument(argument, DESTINATION);
            }
        }
        ...
    }
}

For more information on the launching batch mode programs , see Specifying batch mode program classpath.

More information is available in javadoc.

 You can find the code examples in

  • <programinstallation directory>\openapi\examples\imagegenerator.  It takes a project file and destination directory as arguments and generates images for all diagrams.
  • No labels