'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 1:[1]
simulation_0 is not the name of the actual simulation it is just an object of type Simulation.
You will need to , maybe, simulation_0.getName or simulation_0.getSimulationName() to get the name of the "simulation_0".
Solution 2:[2]
I was able to solve my issue and added code to add created files to a new directory.
// making the file name extension string
String append1 = "_Heave.sim";
String dir1 = simulation_0.getSessionDir(); //getting the name of the sims directory
String filename1 = simulation_0.getPresentationName(); //get the name of the current sim file
String sep1 = System.getProperty("file.separator"); //get the right separator for your operative system
String folder1 = (sep1 + filename1 + "_Five_Attitude_Study"); //making the first folders name
String pathToNewDirectory1 = (dir1 + folder1); //applying it to the full path
File fileObject1 = new File(pathToNewDirectory1); //making the new file folder
Boolean yes1 = fileObject1.mkdir(); //checking that its there
simulation_0.saveState(pathToNewDirectory1 + sep1 + filename1 + append1); //save the current sim file as| [email protected]
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | code-freeze |
| Solution 2 | sanchead |
