要重复多次的代码

现在,您面对的是要置于一个循环内的代码。已添加一些 Java 注释,以帮助描述所发生的操作。将通过变量重复的项目下标有下划线,并且要移除的截面也标有下划线。

// The LinePart object is the Derived Part you want to
// create. The PartManager on the simulation_0 object
// has the method that lets you do this.

LinePart linePart_0 = 
      simulation_0.getPartManager().createLinePart(new NeoObjectVector(new Object[] {}), 
new DoubleVector(new double[] {0.0, 0.0, 0.0}), 
new DoubleVector(new double[] {1.0, 0.0, 0.0}), 
20);
 
// The LinePart object must now be told
// what coordinate system it is using. You retrieve the
// LabCoordinateSystem object from the
// CoordinateSystemManager on the simulation_0 object.
 
LabCoordinateSystem labCoordinateSystem_0 =
  ((LabCoordinateSystem)
    simulation_0
    .getCoordinateSystemManager()
    .getLabCoordinateSystem();
 
// As you now have the labCoordinateSystem_0 object we
// can tell linePart_0 to use it.
 
linePart_0
.setCoordinateSystem(labCoordinateSystem_0);
 
// The next two sections set the units on each axis,
// and the position, of the first Point of linePart_0
 
Coordinate coordinate_0 =
  linePart_0.getPoint1Coordinate();
 
coordinate_0
.setCoordinate(
  units_0,
  units_0,
  units_0,
  new DoubleVector(
    new double[] {0.04, 0.0, 0.0}
  )
);
 
// The next two sections set the units on each axis,
// and the position, of the second Point of linePart_0.
 
Coordinate coordinate_1 =
  linePart_0
  .getPoint2Coordinate();
 
coordinate_1
.setCoordinate(
  units_0,
  units_0,
  units_0,
  new DoubleVector(
    new double[] {0.04, 0.0762, 0.0}
  )
);
 
// The following two sections are updating the visible
// scene and are not required for creating line parts.
// Note: The part number may differ slightly in your
// recording.

PartDisplayer partDisplayer_5 =
     scene_1.getDisplayerManager().createPartDisplayer("Probe Surface", -1, 1);
     partDisplayer_5.initialize();
 
// Change the name of the linePart.
 
linePart_0.setPresentationName("X = 0.04");

要移除冗余代码,删除本截面并将其置于循环内。下划线的代码位置基于相应的变量,而这些变量会在循环内有所增加。

以上显示的冗余代码是使用 scene_0 中的 PartDisplayer 处理的,实际上不会对创建零部件行产生任何影响。。这都可安全删除。