要重复多次的代码
现在,您面对的是要置于一个循环内的代码。已添加一些 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_1 =
simulation_0.getPartManager().createLinePart(new ArrayList<>(Collections.
<NamedObject>emptyList()),
new DoubleVector(new double[] {0.0, 0.0, 0.0}),
new DoubleVector(new double[] {1.0, 0.0, 0.0})
20, null);
// 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 =
simulation_0.getCoordinateSystemManager().
getLabCoordinateSystem();
// As you now have the labCoordinateSystem_0 object we
// can tell linePart_1 to use it.
linePart_1.getPoint1Coordinate()
.setCoordinateSystem(labCoordinateSystem_0);
// The next two sections set the units on each axis,
// and the position, of the first Point of linePart_0
linePart_1.getPoint1Coordinate()
.setUnits0(units_1);
linePart_1.getPoint1Coordinate()
.setUnits1(units_1);
linePart_1.getPoint1Coordinate()
.setUnits2(units_1);
linePart_1.getPoint1Coordinate()
.setDefinition("");
linePart_1.getPoint1Coordinate()
.setValue(
new DoubleVector(
new double[] {0.04, 0.0, 0.0}
)
);
linePart_1.getPoint1Coordinate
.setCoordinate(
units_1,
units_1,
units_1,
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_1.
linePart_1.getPoint2Coordinate()
.setUnits0(units_1);
linePart_1.getPoint2Coordinate()
.setUnits1(units_1);
linePart_1.getPoint2Coordinate()
.setUnits2(units_1);
linePart_1.getPoint2Coordinate()
.setDefinition("");
linePart_1.getPoint2Coordinate()
.setValue(
new DoubleVector(
new double[] {0.04, 0.0762, 0.0}
)
);
linePart_1.getPoint2Coordinate
.setCoordinate(
units_1,
units_1,
units_1,
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_0.getVisibleParts().addPart(linePart_1);
partDisplayer_0.getHiddenParts().addParts();
// Change the name of the linePart.
linePart_1.setPresentationName("X = 0.04");要移除冗余代码,删除本截面并将其置于循环内。下划线的代码位置基于相应的变量,而这些变量会在循环内有所增加。
以上显示的冗余代码是使用 scene_0 中的 PartDisplayer 处理的,实际上不会对创建零部件行产生任何影响。。这都可安全删除。