|
[Sponsors] |
June 20, 2013, 05:01 |
Loop parts with java
|
#1 |
New Member
Christian
Join Date: Jun 2013
Posts: 4
Rep Power: 12 |
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? |
|
June 21, 2013, 09:18 |
|
#2 |
Member
Ryan Coe
Join Date: Jun 2010
Location: Albuquerque, NM
Posts: 98
Rep Power: 15 |
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()); } } }
__________________
Ryan |
|
June 21, 2013, 13:45 |
|
#3 |
New Member
Adam
Join Date: Aug 2011
Posts: 4
Rep Power: 14 |
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 } |
|
June 24, 2013, 08:03 |
Thanks
|
#4 |
New Member
Christian
Join Date: Jun 2013
Posts: 4
Rep Power: 12 |
Hi
Thank you for the suggestions. I will try them out. |
|
June 24, 2013, 08:05 |
Thanks
|
#5 |
New Member
Christian
Join Date: Jun 2013
Posts: 4
Rep Power: 12 |
Hi
Thank you for the suggestions. I will try them out and I definetely learned a few more tricks and commands. Great Cheers Christian |
|
|
|
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 |