Simcenter STAR-CCM+ Get Started with Visual Studio Code and Simcenter STAR-CCM+

Simcenter STAR-CCM+ Simcenter STAR-CCM+ Virtual Reality Teamcenter Share Simcenter Cloud HPC Simcenter STAR-CCM+ Viewer Simcenter STAR-CCM+ Application Specific Solutions


This articles demonstrates how to setup Visual Studio Code for scripting with Java. This includes creating a new Java project, followed by importing the Simcenter STAR-CCM+ java libraries necessary to begin scripting. For scripting with Simcenter STAR-CCM+, any Integrated Development Environment (IDE) program can be used. The user guide contains examples of how to do this using NetBeans, however for those that wish to use Visual Studio Code, please refer to this article on how to get started!


Step 1: Download the Java Extension Pack

An easy one to start with, lets open up Visual Studio Code. Once open, head to the extensions tab and search for "Extension Pack for Java".


Go ahead and install the extension pack. 
Once this is installed, you will be prompted to install a JDK. Install any JDK (I elected for one in the list within "Others").



Step 2: Create a new Java project

In a file directory of your choice, create a folder where the Java project will be created. This location will feature the Java directory setup, where your new/existing Java script will live. Alternatively, if you have a directory in mind already, skip this step and go to Visual Studio Code.

In Visual Studio Code, choose the explorer tab and "Create Java Project".


In the search bar that appears, choose "No Build Tools". Browse to the location where you created your project folder at the start of Step 2 (or an existing folder of your choice) and select this folder as the project location. You will then be prompted to give the project a name.

A warning may appear asking if you trust the authors of the folder, this choice is up to you! Naturally accepting this will allow the project to be created.

Finally, you should see the following directory in the explorer. Under "src", an example Java script is created. Please click on this example script to enable "JAVA PROJECTS" to appear on the bottom left of the screen.


Alternatively, if you have a script already, please copy the script from its existing file directory and paste it into the src folder within the directory you created for this new project.


Step 3: Import the Simcenter STAR-CCM+ java libraries

Click the JAVA PROJECTS button on the bottom left of the screen and scroll to Referenced Libraries. Click on the plus button for Add Jar Libraries to Project Classpath…


Once you press the plus button, please find your Simcenter STAR-CCM+ install directory and access the following location:

C:\Program Files\Siemens\17.04.008\STAR-CCM+17.04.008\star\lib\java\platform\modules\ext

The above is an example for Windows, for Linux the directory will be similar, the import location is:


Select all the .jar files present in this folder and choose Select Jar Libraries. These libraries should now appear within the Referenced Libraries section of the JAVA PROJECTS dropdown.

Alternative Method

A short trick to add all the referenced libraries without choosing every single one is as follows. Once you've found the directory with all the .jar files, instead of choosing all of them, simply choose one. In Visual Studio Code, in the folder you've just created, you should see a .vscode dropdown. In here is a settings.json file, click this. You should see something like below (it doesn't matter what jar file you select):

In the settings.json file, replace the name of the library with a "*" like below and this will now import all libraries at once!
Don't forget to save the settings.json file with File -> Save or CTRL-S.

Step 4: Importing an existing Java script

If you have an existing java script, you'll need to copy and paste this script into the src folder that exists in the project directory you have just made within the file directory (not within Visual Studio Code). You may get an error regarding an incorrect package, as the directory the script existed in is different to the current one.

This "package" line, is compulsory for STAR-CCM+. Within Visual Studio Code, click on your imported script and then hover over the underlined input next to "package". Choose "Quick Fix…" from the two options that appear.


In the following window that appears, choose "Move '' to package 'MacroPackage'. The macro name and package name can vary. Once the new package is created, the Simcenter STAR-CCM+ libraries will now function with the new macro.


Step 5: Bringing the Simcenter STAR-CCM+ libraries into a new project

Once the libraries have been imported, within the file explorer under .vscode, you should see a settings.json file.


This file contains the link to the libraries you have referenced. Let's say we create a new java project. To do this, we can use File -> New Window. In this new window, open up the explorer again and create a new java project as before. We see the same as before, with an example java present in the src folder. The settings.json file is here, but does not contain any of our libraries.
In order to ensure our new project can access the Simcenter STAR-CCM+ libraries, we need to go to our initial Visual Studio Code workspace and right-click on the settings.json file. Choose "Reveal in File Explorer".


In the file explorer, copy this file from the current directory and paste it into the .vscode folder in your new java project directory. The .vscode folder may be hidden, so you may need to turn on the view for hidden folders. When pasting, replace the file in that destination.
Back in Visual Studio Code, but this time in the new workspace/window created for the new project, you will see the settings.json file has been updated. Bring in or create a new script and the Simcenter STAR-CCM+ libraries will function as before.


Step 6: Changing the Simcenter STAR-CCM+ library version (only when upgrading Simcenter STAR-CCM+)

Back into any project you've created within the Visual Studio Code explorer, you'll see a .vscode dropdown with a settings.json file. Click this file and you should see an output as follows:


This will show you the location of all the libraries that you have just imported into Visual Studio Code. When the time comes for you to upgrade the version of Simcenter STAR-CCM+, provided you keep the install directory the same, you can simply use CTRL-SHIFT-F or choose the search function and search for the version number present in the settings.json file. You can also highlight the version number within the settings.json file, which will highlight all instances of the version number, then use CTRL-SHIFT-F.
This will automatically populate the search field with the number. Once you've done this, choose the arrow to the left of the search field to expose the replace functionality. Type in the new version, choose replace all and all the libraries will be updated. No need to go through the entire process again for subsequent projects, just update this number!


Once this is done, this should now be the settings.json file that you copy into future projects for scripting with Simcenter STAR-CCM+.

If you have used the Alternative Method described in Step 3, this step because much easier as you will only need to replace the version number for one line!


Optional: Setting a default location for Simcenter STAR-CCM+ libraries

The above methods show how to import libraries every time you create a new java project. What if you would rather have a default set of libraries to work with and have this set for every project? To achieve this, do the following:

Go to File -> Preferences -> Settings:

Make sure the tab on this page is set to user, you may have a tab for workspace available but user needs to be the active one. Choose to open the settings.json file. This is a settings.json for the user rather than the workspace:
Here, you'll see a settings.json file again. Copy the contents of a previous settings.json file here, such that the output looks like below:
This will now be Simcenter STAR-CCM+ version used as default for all new projects you open. You will no longer need to load any further libraries into any projects after this step, unless you wish to use libraries from a different version of STAR-CCM+.



Simcenter STAR-CCM+ Documentation

User Interface > Scripting the Application

User Interface > Scripting the Application > Using the Java API

User Interface > Scripting the Application > Debugging a Macro Using an IDE

KB Article ID# KB000073661_EN_US



Associated Components

Design Manager Electronics Cooling In-Cylinder (STAR-ICE) Job Manager Simcenter STAR-CCM+