MagicDraw or other modeling tools run as a simple Java program.

In order to launch the program from the command line, the launcher is started using a java command line. The classpath has to include jar files from the lib folder and its subfolders (additional requirements exist for different command line implementations).

There is one mandatory property that has to be specified as well:

  • -Desi.system.config=data/application.conf

The property is specified as a relative path to <modeling tool installation directory>, therefore, you either have to make your current directory before launching your program or specify absolute paths for the above-listed properties.

There are two types of command lines.

  1. Core related batch program:
    A program that does not call/depend on any functionality from any plugins. Should only depend/call core tool functionality.
    • Must extend com.nomagic.magicdraw.commandline.CommandLine

    • Must contain the Java main method and implement com.nomagic.magicdraw.commandline.CommandLine#execute

  2. Plugin related batch program:
    A program that can call/depend on any running modeling tool plugin
    • com.nomagic.magicdraw.commandline.action - specifies the batch mode action (implementation of com.nomagic.magicdraw.commandline.CommandLineAction) you want to execute, for example, -Dcom.nomagic.magicdraw.commandline.action=com.nomagic.magicdraw.examples.commandlineplugin.CommandLineActionExample 

    • Must launch using com.nomagic.magicdraw.commandline.CommandLineActionLauncher 

    • The CommandLineAction must be registered in CommandLineActionManager.getInstance().addAction(new CommandLineActionExample()); e.g. in your plugin init() method

    • The plugin where CommandLineAction is registered must load and run, in order for the command line program to launch it. (this means plugin.xml and plugin .jar files must be in the /plugins directory)


Also, it is possible to set up the command line to use the floating license server or license file - see "Providing licensing information" at Licensing information.

The implemented examples can be found in :

  • Core batch program: <modeling tool installation directory>\openapi\examples\imagegenerator
  • Plugin batch program: <modeling tool installation directory>\openapi\examples\commandlineplugin

The examples of complete command lines that launch the batch mode programs:

Core batch program command line for Windows
C:\Program Files\MagicDraw>java -Xmx1200M -Xss1024K ^
-cp lib/patch.jar;lib/brand.jar;lib/brand_api.jar;lib/*;lib/graphics/*;openapi/examples/imagegenerator/imagegenerator.jar ^
-Desi.system.config=data/application.conf ^
com.nomagic.magicdraw.examples.imagegenerator.ExportDiagramImages project=project.mdzip destination_dir=out
Plugin batch program command line for Windows
C:\Program Files\MagicDraw>java -Xmx1200M -Xss1024K ^
-cp lib/patch.jar;lib/brand.jar;lib/brand_api.jar;lib/*;lib/graphics/* ^
-Desi.system.config=data/application.conf ^
-Dcom.nomagic.magicdraw.commandline.action=com.nomagic.magicdraw.examples.commandlineplugin.CommandLineActionExample ^
com.nomagic.magicdraw.commandline.CommandLineActionLauncher argument1 argument2
Core batch program command line for Mac OS-X and Linux
> cd MagicDraw_dir
> java -Xmx1200M -Xss1024K \
 -Desi.system.config=data/application.conf \
 -cp lib/patch.jar\:lib/brand.jar\:lib/brand_api.jar\:lib/*\:lib/graphics/*\:openapi/examples/imagegenerator/imagegenerator.jar \
  com.nomagic.magicdraw.examples.imagegenerator.ExportDiagramImages project=project.mdzip destination_dir=out
Plugin batch program command line for Mac OS-X and Linux
> cd MagicDraw_dir
> java -Xmx1200M -Xss1024K \
-cp lib/patch.jar\:lib/brand.jar\:lib/brand_api.jar\:lib/*\:lib/graphics/* \
-Desi.system.config=data/application.conf \
-Dcom.nomagic.magicdraw.commandline.action=com.nomagic.magicdraw.examples.commandlineplugin.CommandLineActionExample \
com.nomagic.magicdraw.commandline.CommandLineActionLauncher argument1 argument2

You can modify the previous examples and create more sophisticated batch files. For example, you can define the directory to run the tool from, or specify to use the same java, as the tool uses itself. The exemplary scripts that can be used to start the command line program are shown in the following script examples. The scripts read and use the same classpath as the modeling tool when launching it manually(this is the preferred way to define classpaths). 

These scripts can be launched from any directory. Can be modified to read other properties files (e.g. csm.properties, cea.properties)


A script that starts the Windows Core batch command line program on Windows:

Command line Core batch program Windows batch file that is able to launch program from any directory
@echo off
setlocal EnableExtensions
 
:: either local script variable or environment variable MAGICDRAW_HOME should be defined
set "MAGICDRAW_HOME=C:\Program Files\MagicDraw"

if "%MAGICDRAW_HOME%" == "" (
    echo MAGICDRAW_HOME environment variable not set, please set it to the MagicDraw installation folder
    exit /B 1
)

setlocal enableDelayedExpansion
:: change slashes if needed
set MAGICDRAW_HOME=!MAGICDRAW_HOME:\=/!
setlocal disableDelayedExpansion
  
pushd "%MAGICDRAW_HOME%" 
  
:: Reads CLASSPATH value from magicdraw.properties files (change to your properties file name)
For /F "tokens=1* delims==" %%A IN (bin\magicdraw.properties) DO (
    IF "%%A"=="CLASSPATH" set MD_CLASSPATH=%%B
)

:: Modify classpath to a valid Windows style classpath. Replace \: with ;
set MD_CLASSPATH=%MD_CLASSPATH:\:=;%
  
java -Xmx1200M -Xss1024K ^
     -cp "%MD_CLASSPATH%;openapi\examples\imagegenerator\imagegenerator.jar" ^
	 -Desi.system.config="data\application.conf" ^
     com.nomagic.magicdraw.examples.imagegenerator.ExportDiagramImages %*
	 
popd


A script that starts the Windows Plugin batch command line program on Windows:

Command line Plugin batch program Windows batch file that is able to launch program from any directory
@echo off
setlocal EnableExtensions
  
:: either local script variable or environment variable MAGICDRAW_HOME should be defined
set "MAGICDRAW_HOME=C:\Program Files\MagicDraw"
 
if "%MAGICDRAW_HOME%" == "" (
    echo MAGICDRAW_HOME environment variable not set, please set it to the MagicDraw installation folder
    exit /B 1
)
 
setlocal enableDelayedExpansion
:: change slashes if needed
set MAGICDRAW_HOME=!MAGICDRAW_HOME:\=/!
setlocal disableDelayedExpansion
   
pushd "%MAGICDRAW_HOME%"
   
:: Reads CLASSPATH value from magicdraw.properties files (change to your properties file name)
For /F "tokens=1* delims==" %%A IN (bin\magicdraw.properties) DO (
    IF "%%A"=="CLASSPATH" set MD_CLASSPATH=%%B
)
 
:: Modify classpath to a valid Windows style classpath. Replace \: with ;
set MD_CLASSPATH=%MD_CLASSPATH:\:=;%
   
java -Xmx1200M -Xss1024K ^
     -cp "%MD_CLASSPATH%" ^
     -Desi.system.config="data\application.conf" ^
	 -Dcom.nomagic.magicdraw.commandline.action=com.nomagic.magicdraw.examples.commandlineplugin.CommandLineActionExample ^
     com.nomagic.magicdraw.commandline.CommandLineActionLauncher %*
      
popd


The shell script that starts a Core batch command line program on Mac OS-X, Linux, and Windows cygwin/msys:

Command line Core batch program shell script that is able to launch program from any directory
#!/bin/bash

# either local script variable or environment variable MAGICDRAW_HOME should be defined
MAGICDRAW_HOME="/home/myuser/Desktop/MagicDraw"

if [ -z "$MAGICDRAW_HOME" ]; then
    echo "MAGICDRAW_HOME environment variable not set, please set it to the MagicDraw installation folder"
    return
fi
 
cd "$MAGICDRAW_HOME"

# Reads CLASSPATH value from magicdraw.properties files (change to your properties file name)
MD_CLASSPATH=`grep "CLASSPATH" bin/magicdraw.properties | cut -d'=' -f 2`

if [ "$OS" = Windows_NT ]; then
    MD_CLASSPATH=$(echo "$MD_CLASSPATH" | sed "s/\\\:/;/g")
    cp_delim=";"
else
    MD_CLASSPATH=$(echo "$MD_CLASSPATH" | sed "s/\\\:/:/g")
    cp_delim=":"
fi
 
java -Xmx1200M -Xss1024K \
     -cp "$MD_CLASSPATH${cp_delim}openapi/examples/imagegenerator/imagegenerator.jar" \
     -Desi.system.config="data/application.conf" \
     com.nomagic.magicdraw.examples.imagegenerator.ExportDiagramImages "$@"


The shell script that starts a Plugin batch command line program on Mac OS-X, Linux, and Windows cygwin/msys:

Command line Plugin batch program shell script that is able to launch program from any directory
#!/bin/bash

# either local script variable or environment variable MAGICDRAW_HOME should be defined
MAGICDRAW_HOME="/home/myuser/Desktop/MagicDraw"

if [ -z "$MAGICDRAW_HOME" ]; then
    echo "MAGICDRAW_HOME environment variable not set, please set it to the MagicDraw installation folder"
    return
fi
 
cd "$MAGICDRAW_HOME"

# Reads CLASSPATH value from magicdraw.properties files (change to your properties file name)
MD_CLASSPATH=`grep "CLASSPATH" bin/magicdraw.properties | cut -d'=' -f 2`

if [ "$OS" = Windows_NT ]; then
    MD_CLASSPATH=$(echo "$MD_CLASSPATH" | sed "s/\\\:/;/g")
else
    MD_CLASSPATH=$(echo "$MD_CLASSPATH" | sed "s/\\\:/:/g")
fi
 
java -Xmx1200M -Xss1024K \
     -cp "$MD_CLASSPATH" \
     -Desi.system.config="data/application.conf" \
     -Dcom.nomagic.magicdraw.commandline.action=com.nomagic.magicdraw.examples.commandlineplugin.CommandLineActionExample \
     com.nomagic.magicdraw.commandline.CommandLineActionLauncher "$@"