CFD Online Logo CFD Online URL
www.cfd-online.com
[Sponsors]
Home > Forums > Software User Forums > Siemens > STAR-CCM+

Renaming surfaces in macro

Register Blogs Members List Search Today's Posts Mark Forums Read

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
Old   December 1, 2019, 16:08
Default Renaming surfaces in macro
  #1
New Member
 
Jack B
Join Date: Jul 2018
Posts: 11
Rep Power: 7
Jack B is on a distinguished road
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,

Jack
Jack B is offline   Reply With Quote

Old   December 1, 2019, 20:39
Default
  #2
cwl
Senior Member
 
Chaotic Water
Join Date: Jul 2012
Location: Elgrin Fau
Posts: 433
Rep Power: 17
cwl is on a distinguished road
Quote:
Originally Posted by Jack B View Post
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.

Quote:
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?
cwl is offline   Reply With Quote

Old   December 2, 2019, 18:36
Default
  #3
Senior Member
 
Sebastian Engel
Join Date: Jun 2011
Location: Germany
Posts: 566
Rep Power: 20
bluebase will become famous soon enough
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,
Sebastian

Code:
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");

    scene_0.initializeAndWait();
    CadModel cadModel_0 = simulation_0.get(SolidModelManager.class).createSolidModel(scene_0);
    scene_0.open();
    scene_0.setAdvancedRenderingEnabled(false);

   // 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 = 
      simulation_0.getCoordinateSystemManager().getLabCoordinateSystem();


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


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

    blockPrimitiveFeature_0.markFeatureForEdit();
    
    // Set the dimensions of the block
    blockPrimitiveFeature_0.getLength().setValue(0.1);
    blockPrimitiveFeature_0.getWidth().setValue(0.2);
    blockPrimitiveFeature_0.getHeight().setValue(0.3);

    // Create the box
    cadModel_0.getFeatureManager().execute(blockPrimitiveFeature_0);


    // 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
        simulation_0.println(face.getPresentationName());

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

    // 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.get(SolidModelManager.class).endEditCadModel(cadModel_0);
    simulation_0.getSceneManager().deleteScenes(new NeoObjectVector(new Object[] {scene_0}));

  
  }
}
bluebase is offline   Reply With Quote

Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
fvOptions npatricia OpenFOAM 6 May 23, 2018 06:21
NURBS surfaces on a wing frossi CFX 5 February 5, 2017 16:27
timestep extraction for macro manuc Tecplot 0 August 10, 2016 13:20
Modeling both radiation and convection on surfaces - Ansys Transient Thermal R13 s.mishra ANSYS 0 March 31, 2012 05:12
Macro problem cfddummy Siemens 1 April 9, 2007 13:37


All times are GMT -4. The time now is 13:20.