javafileappendsavestate

Save a file by appending the original file name


I am running CFD simulation using Star-CCM+ which uses Java API. Star-CCM+ writes macros in java but I do not know the language at all. I want to manipulate parameter values in my simulations and then save the file with an appended name. For example, if my simulation is named "External Aero" I would like the simulation to save the file with the name "External Aero Heave". The reason for this is that multiple people will be using this macro and I don't want everyone's files being overwritten. So I want the macro to append the base file's name.

The code that Star-CCM+ wrote to save rename the file is as follows:

// Simcenter STAR-CCM+ macro: SaveOp.java
// Written by Simcenter STAR-CCM+ 15.06.008
package macro;

import java.util.*;

import star.common.*;
import star.base.neo.*;

public class SaveOp extends StarMacro {

  public void execute() {
    execute0();
  }

  private void execute0() {

    Simulation simulation_0 = getActiveSimulation();

    simulation_0.saveState("Y:\\CFD Simulation\\Run\\GFR21_Thesis_Base_ExportToPPT_Heave.sim");
  }

  private void execute1() {
  }
}

I can see that simulation_0 is the name of the active simulation. I have tried to add simulation_0 to the saveState command as follows:

    simulation_0.saveState("Y:\\CFD Simulation\\Run\\simulation_0_Heave.sim");

But this just saves a simulation named "simulation_0_Heave.sim", which is not what I am after.

Any help with this would be greatly appreciated. Thank you in advance.


Solution

  • This should work:

      simulation_0.saveState("Y:\\CFD Simulation\\Run\\" + simulation_0.getPresentationName() + "_Heave.sim");