| Article | 70002403 |
| Type | HowTo |
| Product | Engine |
| Date Added | 9/11/2023 12:00:00 AM |
| Fixed | 10.1005.0.1 (9/11/2023 12:00:00 AM) |
| Submitted by | Alessio |
Summary
How can I create a wall with openings using boolean operations
Solution
Please check the code below where with the help of a filled polyline with hatchproperties and thickness we are able to create the required polyfaces and after 3D substractions have the result we want.
//Create a Wall with 3 openings using boolean operations
//Create the wall
double width = 10.0;
double InitialHeight = 2.0;
double EndHeight = 3.0;
double midHeight = 4.5;
double Wallthickness = 1.5;
vdPolyline wallPL = new vdPolyline(doc);
wallPL.VertexList.Add(new gPoint(0.0, 0.0, 0.0));
wallPL.VertexList.Add(new gPoint(width, 0.0, 0.0));
wallPL.VertexList.Add(new gPoint(width, EndHeight, 0.0));
wallPL.VertexList.Add(new gPoint(width/2.0, midHeight, 0.0));
wallPL.VertexList.Add(new gPoint(0.0, InitialHeight , 0.0));
wallPL.VertexList.Add(new gPoint(0.0, 0.0, 0.0));
wallPL.HatchProperties = new vdHatchProperties(VdConstFill.VdFillModeSolid);
wallPL.Thickness = Wallthickness;
vdPolyface Wall = wallPL.ToMesh(0);
doc.Model.Entities.AddItem(Wall);
//Opening 1
//The opening can be created like above with a polyline but in order to simplify the code below we will use a different method.
double openingWidth = 1.0;
double openingHeight = 1.5;
vdPolyface OpeningPolyface = new vdPolyface(doc);
OpeningPolyface.CreateBox(new gPoint(1.5, 0.0, -Wallthickness / 2.0), openingWidth, openingHeight, Wallthickness * 2, 0.0);
//Add the polyfaces before substruction just to see them , it is not necessary
doc.Model.Entities.AddItem(OpeningPolyface);
//Substruct the opening from the main wall.
vdPolyface resultPolyface = Wall.CombinePolyfacesEx2(Wall, OpeningPolyface, BooleanOperation.Substraction);
//Opening 2 similar to opening 1 but a little further
openingWidth = 1.0;
openingHeight = 1.5;
OpeningPolyface = new vdPolyface(doc);
OpeningPolyface.CreateBox(new gPoint(3.5, 0.0, -Wallthickness / 2.0), openingWidth, openingHeight, Wallthickness * 2, 0.0);
doc.Model.Entities.AddItem(OpeningPolyface);
resultPolyface = Wall.CombinePolyfacesEx2(resultPolyface, OpeningPolyface, BooleanOperation.Substraction);
//Opening 3 above opening 2
openingWidth = 2.0;
openingHeight = 0.5;
OpeningPolyface = new vdPolyface(doc);
OpeningPolyface.CreateBox(new gPoint(2.8, 2.0, -Wallthickness / 2.0), openingWidth, openingHeight, Wallthickness * 2, 0.0);
doc.Model.Entities.AddItem(OpeningPolyface);
resultPolyface = Wall.CombinePolyfacesEx2(resultPolyface, OpeningPolyface, BooleanOperation.Substraction);
//Remove edges from resultpolyface. This is optional since we will use a render setting to eliminate edges anyway.
for (int i = 0; i < resultPolyface.FaceList.Count; i += 5)
{
resultPolyface.FaceList[i] = Math.Abs(resultPolyface.FaceList[i]) * -1;
resultPolyface.FaceList[i+1] = Math.Abs(resultPolyface.FaceList[i+1]) * -1;
resultPolyface.FaceList[i+2] = Math.Abs(resultPolyface.FaceList[i+2]) * -1;
resultPolyface.FaceList[i+3] = Math.Abs(resultPolyface.FaceList[i+3]) * -1;
}
//Move the result polyface down so we can see it.
Matrix matt = new Matrix();
matt.TranslateMatrix(0.0, -10.0, 0.0);
resultPolyface.Transformby(matt);
doc.Model.Entities.AddItem(resultPolyface);
//Some fancy settings just so the wall looks good
doc.RenderMode = vdRender.Mode.RenderOn;
doc.GlobalRenderProperties.EdgeEffect = vdRenderGlobalProperties.EdgeEffectFlag.AutoDetect;
doc.EdgeColor = Color.Red;
doc.EdgePenWidth = 0.03F;
resultPolyface.PenColor.ColorIndex = 30;
doc.ZoomExtents();
doc.Redraw(true);
Preview
