【问题标题】:Save a file by appending the original file name通过附加原始文件名保存文件
【发布时间】:2021-07-04 01:23:27
【问题描述】:

我正在使用使用 Java API 的 Star-CCM+ 运行 CFD 模拟。 Star-CCM+ 用 java 编写宏,但我根本不懂语言。我想在我的模拟中操作参数值,然后使用附加名称保存文件。例如,如果我的模拟名为“External Aero”,我希望模拟以“External Aero Heave”的名称保存文件。这样做的原因是多个人将使用此宏,我不希望每个人的文件都被覆盖。所以我希望宏附加基本文件的名称。

Star-CCM+编写的保存重命名文件的代码如下:

// 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() {
  }
}

我可以看到simulation_0 是活动模拟的名称。我尝试将 Simulation_0 添加到 saveState 命令中,如下所示:

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

但这只是保存了一个名为“simulation_0_Heave.sim”的模拟,这不是我想要的。

对此的任何帮助将不胜感激。 提前谢谢你。

【问题讨论】:

  • 注意:Star-CCM+ Java API 文档可以从菜单栏 > 帮助 > Java API 访问,它将在浏览器窗口中打开。

标签: java file append savestate


【解决方案1】:

这应该可行:

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

【讨论】:

    【解决方案2】:

    simulation_0 不是实际模拟的名称 它只是一个 Simulation 类型的对象。

    您可能需要simulation_0.getName 或simulation_0.getSimulationName() 来获取“simulation_0”的名称。

    【讨论】:

      【解决方案3】:

      我能够解决我的问题并添加代码以将创建的文件添加到新目录。

            // 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| name_of_the_file@mod.sim
      

      【讨论】:

        猜你喜欢
        • 2020-02-16
        • 2015-05-27
        • 1970-01-01
        • 2018-03-24
        • 2013-03-12
        • 2015-06-09
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多