CFD Online Discussion Forums

CFD Online Discussion Forums (
-   STAR-CCM+ (
-   -   Loop parts with java (

chrfri June 20, 2013 05:01

Loop parts with java
I would like to loop over all parts, and made a small test java:

for (PlaneSection p : simulation_0.getPartManager().getObject()) {

This method has worked before for other commands.
But I get an error saying that getObject cannot use ()

I find the java API difficult to understand and use. Can anyone help me solving the error?

ryancoe June 21, 2013 09:18

I think that a Collection may be helpful for this.


package macro;

import java.util.*;
import star.common.*;
import star.meshing.*;

public class partCollection extends StarMacro {

    public void execute() {
        Simulation sim = getActiveSimulation();
        Collection<GeometryPart> myParts = sim.get(SimulationPartManager.class).getLeafParts();
        for (Iterator<GeometryPart> it = myParts.iterator(); it.hasNext();) {
            GeometryPart iPart =;

I find APIs challenging as well. My best strategy is to use an IDE (such as Netbeans or Eclipse) with auto-complete and experiment.

AdamS June 21, 2013 13:45

I think the reason you are seeing that specific error is that you are using getObject() instead of getObjects(). getObject requires that you pass in a string to retrieve a specific part; getObjects will return a Collection<Part> object of all parts.

You will also need to use an iterator like ryancoe posted above. So it will look something like this:


for (Iterator<Part> it = sim.getPartManager().getObjects().iterator(); it.hasNext();){
    PlaneSection p = (PlaneSection);
    //Do something with p

The final thing you will need to do is account for when the next part in the collection is not a PlaneSection. A try...catch statement wrapping the casting should take care of that.

chrfri June 24, 2013 08:03

Thank you for the suggestions. I will try them out.

chrfri June 24, 2013 08:05

Thank you for the suggestions. I will try them out and I definetely learned a few more tricks and commands. Great


All times are GMT -4. The time now is 08:38.