Simcenter STAR-CCM+ Using gradle in NetBeans for Simcenter STAR-CCM+ scripting

2024-08-13T15:22:01.000-0400
Simcenter STAR-CCM+ CAD Clients Simcenter STAR-CCM+ Simcenter STAR-CCM+ Virtual Reality Teamcenter Share Simcenter STAR-CCM+ Viewer Simcenter STAR-CCM+ Application Specific Solutions

Summary

For STAR-CCM+ 2019.3 and beyond making the API available with NetBeans IDE has changed. This article provide a streamlined approach to linking the API again and also shows how to simplify moving from one version of the API to another one using Gradle build scripts.


Details

Intro

Netbeans version 22 has been released and Simcenter STAR-CCM+ v2406 requires JDK 21. This has a few technical implications. With upgrading the way, the STAR-CCM+ API documentation is released Ant build system's approach to link libraries and their documentation aren’t sufficient to have the API at your fingertips when coding scripts in NetBeans. This article provides a new and more streamlined process of integrating the API when developing Macro projects.

Preparing NetBeans

The build system Gradle is so far incompatible with JDK 21, hence one needs to install also an older version of JDK below version JDK 18 to get to a running Gradle build system that also fully supports the STAR-CCM+ Java API documentation and for which it is easy to move from one STAR-CCM+ version to the next. For the moment we recommend therefore to install NetBeans with a JDK 18 version that fits your licensing.

Once installed the JDK version that is coming with STAR-CCM+ needs to be added to NetBeans as a further Java Platform. Go to Menu Tools > Java Platform and star the Add Platform dialogue within the platform manager.
Java Platform Manager Dialogue. With mouse pointer on Add Platform button to add the JDK that comes with STAR-CCM+.

In the add Platform dialogue you choose to add a Java Standard Edition and hit Next. In the following page you navigate to the STAR-CCM+ installation for which you want to do scripting.

Copy the path into the Clipboard as we will use it again shortly.
Choosing the jdk\win64\jdk21.0.1 subfolder of the 2406 Version of STAR-CCM+ installed on Windows under the typical location

On the subsequent page the platform will be automatically configured and you should be able to hit Finish to complete this process.

With this NetBeans now knows of two JDK version and we want to make the more recent the default version so that you can enjoy the latest Java language features in NetBeans. For this we must change the file netbeans.conf that sits within the NetBeans installation directory (C:\Program Files\Netbeans-22\netbeans\etc\netbeans.conf). Before making any changes to this file, please close NetBeans first.

Near the end of the file you find the variable specification for netbeans_jdkhome, where you place the copied location in as shown.

A close-up of a computer screenDescription automatically generated

You can now restart NetBeans and in the next steps we make the preparations to connect to the STAR-CCM+ Api and introduce the Gradle build system briefly.

Linking NetBeans with the STAR-CCM+ API using Gradle

First step is to enable NetBeans Platform development under Tools Plugins. It is installed by default but needs activation. So, open the Plugins dialogue under Tools Plugins, navigate to the Installed tab and right click on Developing NetBeans.
A screenshot of a computerDescription automatically generated

Follow the remaining steps of that dialogue to then find a new entry in the Tools menu: A screenshot of a computerDescription automatically generated

Where we now link in the STAR-CCM+ API of the version we want to script in. After starting the dialogue hit the Add Platform button and navigate to the STAR-CCM+ Installation of your choice. Within there dive deeper into the folder structure to find star\lib\java. Once you select this folder it will be recognised as a platform folder and you can click onto the Next button
A screenshot of a computerDescription automatically generated

Accept the name of the platform and click finish once. You return to the main NetBeans Platform Manager dialogue, where you select the new platform to then add the Javadoc from the respective tab by clicking on the Add ZIP/Folder button.
A screenshot of a computerDescription automatically generated

You find yourself again in the STAR-CCM+ installation directory tree. Where we now navigate to a different folder, e.g. C:\Program Files\Siemens\19.04.007-R8\STAR-CCM+19.04.007-R8\doc\client\html for the 2406 release. It is recognized as a Javadoc folder, and you click on Open to confirm your choice.

Next step is to link to this specific platform when you code within a Gradle project. Gradle as a build system is meant for much larger projects and brings a bit extra file structure with it that might be annoying at first. But it suits us fine as linking to a STAR-CCM+ API and moving from version to version is getting much simpler.

For STAR-CCM+ macros as they come not as Java Applications the most fitting Project type is to use Java with Grade entry of a Java Class Library when you create a new project.
A screenshot of a computer programDescription automatically generated

You find a name and location for your project. Choose Java Version 21 to be in line with current STAR-CCM+ API code and accept the rest of the settings and hit the finish button:
A screenshot of a computerDescription automatically generated
Gradle projects come in two layers. The actual development for Java Class Library projects happens in the “…:lib” subproject. Which we open now to add the link to STAR-CCM+ for compile time libraries.

In the Projects tree you navigate to the Build Scripts subfolder of the :lib subproject and open the build.Gradle file. Where we augment the dependencies section.

def SCPLUSBase = 'C:/Program Files/Siemens/19.04.007-R8/STAR-CCM+19.04.007-R8/star/lib/java/platform'
dependencies {
    compileOnly fileTree(dir: SCPLUSBase + '/lib', include: '*.jar')
    compileOnly fileTree(dir: SCPLUSBase + '/core', include: '*.jar')
    compileOnly fileTree(dir: SCPLUSBase + '/modules', include: '*.jar')
    compileOnly fileTree(dir: SCPLUSBase + '/modules/ext', include: '*.jar')

 

The remainder of the file can remain unchanged. When you move to a new version of STAR-CCM+ you only need to change the definition of the SCPLUSBase variable and ensure that you use the same directory in the NetBeans Platform dialogue to ensure that API documentation is available to which augmenting your recorded macros.

To keep reduce the folder navigation needs you might want to change the project’s package name to something that doesn’t involve dots as those each add a subfolder layer.

A screenshot of a computer programDescription automatically generated

When recording a macro that should directly appear in your project you need to navigate to the right folder within the Gradle project. Luckily STAR-CCM+ remembers that folder for the next recording.

A screenshot of a computerDescription automatically generated

Sometimes after launching NetBeans it doesn’t directly recognize the STAR-CCM+ NetBeans Platform and the Javadoc isn’t found when using CTRL-SPACE somewhere within the code. If that happens you just open the NetBeans Platform Manager once more navigate to the STAR-CCM+ Platform and wait for it to be properly populated.

A screenshot of a computerDescription automatically generated

Enjoy Scripting!

 

 

KB Article ID# KB000134382_EN_US

Contents

SummaryDetails

Associated Components

Simcenter STAR-CCM+ Clients