CFD Online Discussion Forums

CFD Online Discussion Forums (
-   STAR-CCM+ (
-   -   Renaming surfaces in macro (

Jack B December 1, 2019 15:08

Renaming surfaces in macro
Hi all,

I tried looking around for a previous post on this issue but I couldn't find anything.

I have recorded a macro in Star-CCM+. In this macro I create a block, split it by patch and rename surfaces (ie. Inlet, Outlet, etc.). I see in the macro that each surface is given a specific ID number.

The issue arises when I run the macro again, the surfaces are given different ID numbers every time a new Star-CCM+ file is created so the Macro can not rename them as it does not find them.

Is there any way to rename surfaces without using this ID number or is there a way to make sure that the ID number is the same every time?

Thanks in advance,


cwl December 1, 2019 19:39


Originally Posted by Jack B (Post 751187)
Is there any way to rename surfaces without using this ID number

To be honest - I doubt that.
I remember some macros from macrohut that could do similar things - but that was long ago and lots of those capabilities are now implemented into Star.


or is there a way to make sure that the ID number is the same every time?
Again - I do not thing so nsice generation of IDs is done according to Star's internal algorithms.

I'm pretty sure that your problem can be solved in much easier way.
Can you please descibe it more detailed?

bluebase December 2, 2019 17:36

Hi Jack,

yes you can, but it is likely less convenient.

are you creating the box manually by sketch, or are you using a box primitive?
If you use the latter you get methods to get the top and buttom surfaces easily. See the example below. But i assume you need settings for the sides as well?

Anyways, you also can iterate through the list of faces. If you create just a box, the order and orientation will always be the same, and you might just sequentially set the names.
For arbitrary sketch-based bodies, this should work quite similar.
Inspect the example below where the collection of faces is created. You do not need to know the names or ids to get the collection. (you can use similar methods to get a collection of bodies).

For more complex geometries, you might need to compare some additional properties. The loop has some additional lines

Or, you pick faces by location - inspect the end of the script.
This approach might be most versatile, if you can compute coordinates where your surfaces are, and when they are not too small and close to each other.

best regards,


import java.util.*;

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

public class box extends StarMacro {

  public void execute() {
    Simulation simulation_0 = getActiveSimulation();

    // Start making CAD
    Scene scene_0 = simulation_0.getSceneManager().createScene("3D-CAD View");

    CadModel cadModel_0 = simulation_0.get(SolidModelManager.class).createSolidModel(scene_0);;

  // SceneUpdate sceneUpdate_0 = scene_0.getSceneUpdate();

    Units units_0 =
      simulation_0.getUnitsManager().getPreferredUnits(new IntVector(new int[] {0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}));
    LabCoordinateSystem labCoordinateSystem_0 =

    // Prepare box feature
    BlockPrimitiveFeature blockPrimitiveFeature_0 = cadModel_0.getFeatureManager().createBlockPrimitiveFeature();

    // Set the box center location
    CadModelCoordinate cadModelCoordinate_0 = blockPrimitiveFeature_0.getCenter();
    cadModelCoordinate_0.setCoordinate(units_0, units_0, units_0, new DoubleVector(new double[] {0.0, 0.0, 0.0}));

    // Set the dimensions of the block

    // Create the box

    // rename patches
    Face face_0 =
      ((Face) blockPrimitiveFeature_0.getTopFace());
    cadModel_0.setFaceNameAttributes(new NeoObjectVector(new Object[] {face_0}), "inlet");

    Face face_1 =
      ((Face) blockPrimitiveFeature_0.getBottomFace());
    cadModel_0.setFaceNameAttributes(new NeoObjectVector(new Object[] {face_1}), "outlet");
    // Probably what you mentioned, faces by id
        Face face_4 =
      ((Face) blockPrimitiveFeature_0.getSideFace("1"));

    cadModel_0.setFaceNameAttributes(new NeoObjectVector(new Object[] {face_4}), "wall");
    // get all faces
        star.cadmodeler.Body cadmodelerBody_1 =
      ((star.cadmodeler.Body) blockPrimitiveFeature_0.getBody());   
    Collection<Face> faces = cadmodelerBody_1.getFaceManager().getFaces();
    for(Face face : faces) {
        // face names

        // extracting properties from face
        NeoProperty properties = cadmodelerBody_1.getFaceManager().getFaceProperties(new Vector<Face>(Arrays.asList(face)));
        //get Face normal
        Vector<Double> normalVector =properties.getNeoProperty(String.valueOf(face.getEntityId())).getDoubleVector("Normal");

    // Get Face by Location
    double[] picLocation = new double[]{-0.05, 0.0, 0.2};
    Face faceByLoc = cadModel_0.getFaceByLocation(cadmodelerBody_1,new DoubleVector(picLocation));
    simulation_0.println("Near " + Arrays.toString(picLocation) + " found Face: " + faceByLoc.getPresentationName());
    // Renaming found surface
    cadModel_0.setFaceNameAttributes(new NeoObjectVector(new Object[] {faceByLoc }), "FaceByLocation");

    // Finish CAD
    simulation_0.getSceneManager().deleteScenes(new NeoObjectVector(new Object[] {scene_0}));


All times are GMT -4. The time now is 05:50.