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

Loop parts with java

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

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
Old   June 20, 2013, 05:01
Default Loop parts with java
  #1
New Member
 
Christian
Join Date: Jun 2013
Posts: 4
Rep Power: 12
chrfri is on a distinguished road
Hi
I would like to loop over all parts, and made a small test java:

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

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

Old   June 21, 2013, 09:18
Default
  #2
Member
 
Ryan Coe
Join Date: Jun 2010
Location: Albuquerque, NM
Posts: 98
Rep Power: 15
ryancoe is on a distinguished road
I think that a Collection may be helpful for this.

Code:
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 = it.next();
            sim.println(iPart.getPresentationName());
        }
    }
}
I find APIs challenging as well. My best strategy is to use an IDE (such as Netbeans or Eclipse) with auto-complete and experiment.
__________________
Ryan
ryancoe is offline   Reply With Quote

Old   June 21, 2013, 13:45
Default
  #3
New Member
 
Adam
Join Date: Aug 2011
Posts: 4
Rep Power: 14
AdamS is on a distinguished road
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:

Code:
for (Iterator<Part> it = sim.getPartManager().getObjects().iterator(); it.hasNext();){
    PlaneSection p = (PlaneSection) it.next();
    //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.
AdamS is offline   Reply With Quote

Old   June 24, 2013, 08:03
Default Thanks
  #4
New Member
 
Christian
Join Date: Jun 2013
Posts: 4
Rep Power: 12
chrfri is on a distinguished road
Hi
Thank you for the suggestions. I will try them out.
chrfri is offline   Reply With Quote

Old   June 24, 2013, 08:05
Default Thanks
  #5
New Member
 
Christian
Join Date: Jun 2013
Posts: 4
Rep Power: 12
chrfri is on a distinguished road
Hi
Thank you for the suggestions. I will try them out and I definetely learned a few more tricks and commands. Great

Cheers
Christian
chrfri 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
[Gmsh] Problem with Gmsh nishant_hull OpenFOAM Meshing & Mesh Conversion 23 August 5, 2015 02:09
Trying to make derived parts, got a java runtime exception? bjk87 Siemens 2 April 23, 2012 17:01
Possible to loop a face thread inside a cell thread loop? MarcusW FLUENT 3 March 7, 2012 06:32
[CAD formats] my stl surface is seen as just a line rcastilla OpenFOAM Meshing & Mesh Conversion 2 January 6, 2010 01:30
NACA0012 geometry/design software needed Franny Main CFD Forum 13 July 7, 2007 15:57


All times are GMT -4. The time now is 11:47.