CFD Online Discussion Forums

CFD Online Discussion Forums (https://www.cfd-online.com/Forums/)
-   STAR-CCM+ (https://www.cfd-online.com/Forums/star-ccm/)
-   -   Macro to loop over derived parts (https://www.cfd-online.com/Forums/star-ccm/141199-macro-loop-over-derived-parts.html)

solsidan September 2, 2014 04:22

Macro to loop over derived parts
 
Hi,

Does anyone know how to loop over a specific type of derived parts (e.g. plane sections, line probes, etc) using a Java macro?

kguntur September 2, 2014 05:38

you could loop over all the parts and then use an if statement to check the class of each part. Use only the ones you want.

solsidan September 2, 2014 08:04

Thanks kguntur, this works fine. :)

For reference, here is my understanding of your suggestion:

Code:

      Simulation simulation_0 = getActiveSimulation();   
      Collection<Part> myParts = simulation_0.getPartManager().getObjects();
     
      for (Part part : myParts) {
        String partName = part.getPresentationName();
        simulation_0.println(" %%% Part " + partName + " .");
        // Use if statement to segregate types of parts and perform further operations on part
        }


kguntur September 2, 2014 08:14

You are right. the if statement would look something like this.

String compare = "PlaneSection";
if (part.getClass().toString().contains(compare)){
//do something with the part
}

you can just print the class for all the parts to get your "compare" variable.


All times are GMT -4. The time now is 03:53.