bluebase |
December 2, 2019 17:36 |
Hi Jack,
yes you can, but it is likely less convenient.
are you creating the box manually by sketch, or are you using a box primitive?
If you use the latter you get methods to get the top and buttom surfaces easily. See the example below. But i assume you need settings for the sides as well?
Anyways, you also can iterate through the list of faces. If you create just a box, the order and orientation will always be the same, and you might just sequentially set the names.
For arbitrary sketch-based bodies, this should work quite similar.
Inspect the example below where the collection of faces is created. You do not need to know the names or ids to get the collection. (you can use similar methods to get a collection of bodies).
For more complex geometries, you might need to compare some additional properties. The loop has some additional lines
Or, you pick faces by location - inspect the end of the script.
This approach might be most versatile, if you can compute coordinates where your surfaces are, and when they are not too small and close to each other.
best regards,
Sebastian
Code:
import java.util.*;
import star.cadmodeler.*;
import star.common.*;
import star.base.neo.*;
import star.vis.*;
public class box extends StarMacro {
public void execute() {
Simulation simulation_0 = getActiveSimulation();
// Start making CAD
Scene scene_0 = simulation_0.getSceneManager().createScene("3D-CAD View");
scene_0.initializeAndWait();
CadModel cadModel_0 = simulation_0.get(SolidModelManager.class).createSolidModel(scene_0);
scene_0.open();
scene_0.setAdvancedRenderingEnabled(false);
// SceneUpdate sceneUpdate_0 = scene_0.getSceneUpdate();
Units units_0 =
simulation_0.getUnitsManager().getPreferredUnits(new IntVector(new int[] {0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}));
LabCoordinateSystem labCoordinateSystem_0 =
simulation_0.getCoordinateSystemManager().getLabCoordinateSystem();
// Prepare box feature
BlockPrimitiveFeature blockPrimitiveFeature_0 = cadModel_0.getFeatureManager().createBlockPrimitiveFeature();
// Set the box center location
blockPrimitiveFeature_0.setCoordinateSystem(labCoordinateSystem_0);
CadModelCoordinate cadModelCoordinate_0 = blockPrimitiveFeature_0.getCenter();
cadModelCoordinate_0.setCoordinateSystem(labCoordinateSystem_0);
cadModelCoordinate_0.setCoordinate(units_0, units_0, units_0, new DoubleVector(new double[] {0.0, 0.0, 0.0}));
blockPrimitiveFeature_0.markFeatureForEdit();
// Set the dimensions of the block
blockPrimitiveFeature_0.getLength().setValue(0.1);
blockPrimitiveFeature_0.getWidth().setValue(0.2);
blockPrimitiveFeature_0.getHeight().setValue(0.3);
// Create the box
cadModel_0.getFeatureManager().execute(blockPrimitiveFeature_0);
// rename patches
Face face_0 =
((Face) blockPrimitiveFeature_0.getTopFace());
cadModel_0.setFaceNameAttributes(new NeoObjectVector(new Object[] {face_0}), "inlet");
Face face_1 =
((Face) blockPrimitiveFeature_0.getBottomFace());
cadModel_0.setFaceNameAttributes(new NeoObjectVector(new Object[] {face_1}), "outlet");
// Probably what you mentioned, faces by id
Face face_4 =
((Face) blockPrimitiveFeature_0.getSideFace("1"));
cadModel_0.setFaceNameAttributes(new NeoObjectVector(new Object[] {face_4}), "wall");
// get all faces
star.cadmodeler.Body cadmodelerBody_1 =
((star.cadmodeler.Body) blockPrimitiveFeature_0.getBody());
Collection<Face> faces = cadmodelerBody_1.getFaceManager().getFaces();
for(Face face : faces) {
// face names
simulation_0.println(face.getPresentationName());
// extracting properties from face
NeoProperty properties = cadmodelerBody_1.getFaceManager().getFaceProperties(new Vector<Face>(Arrays.asList(face)));
simulation_0.println(properties);
//get Face normal
Vector<Double> normalVector =properties.getNeoProperty(String.valueOf(face.getEntityId())).getDoubleVector("Normal");
simulation_0.println(normalVector);
}
// Get Face by Location
double[] picLocation = new double[]{-0.05, 0.0, 0.2};
Face faceByLoc = cadModel_0.getFaceByLocation(cadmodelerBody_1,new DoubleVector(picLocation));
simulation_0.println("Near " + Arrays.toString(picLocation) + " found Face: " + faceByLoc.getPresentationName());
// Renaming found surface
cadModel_0.setFaceNameAttributes(new NeoObjectVector(new Object[] {faceByLoc }), "FaceByLocation");
// Finish CAD
simulation_0.get(SolidModelManager.class).endEditCadModel(cadModel_0);
simulation_0.getSceneManager().deleteScenes(new NeoObjectVector(new Object[] {scene_0}));
}
}
|