Creating the Second Task: Converting the Parts to Regions

The second task takes the imported part from the first task and creates a region and boundaries for it. Every new task has its own separate Java class.

For this tutorial, you are provided with the code for Task 2. The code makes sure that a geometry part exists in the simulation and, if found, creates a region for it. If no parts are found, nothing happens.
  1. Add a new class to the Assistant package and name it Task02CreateRegionFromPart.


  2. Copy the following code into the new class:
    package Assistant;
    
    import java.util.ArrayList;
    import java.util.Collection;
    
    import star.assistant.Task;
    import star.assistant.annotation.StarAssistantTask;
    import star.assistant.ui.FunctionTaskController;
    import star.common.GeometryPart;
    import star.meshing.CadPart;
    
    @StarAssistantTask(display = "Create Region from Part",
        contentPath = "XHTML/02_CreateRegionFromPart.xhtml",
        controller = Task02CreateRegionFromPart.RegionFromPartTaskController.class)
    public class Task02CreateRegionFromPart extends Task {
    
        public Task02CreateRegionFromPart() {
        }
    
        public class RegionFromPartTaskController extends FunctionTaskController {
    
            public void createRegion() {
                CadPart cadPart_1 = lookupObject(CadPart.class);
                if (cadPart_1 != null) {
                    Collection<GeometryPart> list = new ArrayList<GeometryPart>();
                    list.add(cadPart_1);
                    getSimulation().getRegionManager().newRegionsFromParts(list, 
                        "OneRegionPerPart", null, "OneBoundaryPerPartSurface", null,
                         true);
                }
            }
        }
    }
  3. Save the file.