# 70002447 How to extract a wall object geometry from a collection of polyfaces

 Article 70002447 Type HowTo Product Engine Version 10 Date Added 11/30/2023 12:00:00 AM Fixed 10.1005.0.4 (11/30/2023 12:00:00 AM) Submitted by Dieter Hammer

## Summary

How to extract a wall object geometry from a collection of polyfaces

## Solution

```                //Example Select an Insert or a Polyface object
//Find the  the outline boundary of the selected object
//Convert it to a vdRect object that will represent a wall
vdFigure fig;
gPoint pt;
doc.Prompt("Select an Insert or a Polyface object");
doc.ActionUtility.getUserEntity(out fig, out pt);
doc.Prompt(null);
gPoints verts = new gPoints();
if (fig is vdInsert)
{
vdInsert ins = fig as vdInsert;
if (ins == null) return;

vdEntities exploded = ins.Explode();
for (int i = 0; i < exploded.Count; i++)
{
vdPolyface pf = exploded[i] as vdPolyface;
if (pf == null) continue;
}
}
else if (fig is vdPolyface)
{
}
if (verts.Count < 2) return;
Box bbox = verts.GetBox();
double thickness = bbox.Thickness;
double level = bbox.Min.z;
// get an array of points that consist the outline boundary of polyface vertxlist
gPoints pts = verts.GetOutlineBoundary();
for (int i = 0; i < pts.Count; i++) pts[i].z = level;//set all point to elevation of the minimum point of entities boundry
//find maximum segment length that will be used as a base Axis for the wall direction
double maxdist = 0.0;
int index = -1;
for (int k = 0; k < pts.Count - 1; k++)
{
double dist = pts[k].Distance2D(pts[k + 1]);
if (dist > maxdist)
{
index = k;
maxdist = dist;
}
}
if (index >= 0)
{
//get the angle of max segment that will be used axis to projection the boundary points
double angle = pts[index].GetAngle(pts[index + 1]);
Matrix m = new Matrix();
m.RotateZMatrix(-angle);
m.Transform(pts);
//create a vdrect with Width, Height and Thickness tha will define the final wall object
Box box = pts.GetBox();

vdRect rc = new vdRect(doc, box.Min, box.Width, box.Height, 0.0) { Thickness = thickness };
//rotate the rect to the real world coordinate system
//set a transparent color to comare it with the original polyfce
//and add the vdRect to the document model entities
//so finally the vdRect will represent a wall and
//the Width property is the wall length,
//the Height property is the wall thickness and
//the Thickness is the wall height.
//and the Rotation property defines  the wall direction
rc.Transformby(m.GetInvertion());
rc.HatchProperties = new vdHatchProperties(VdConstFill.VdFillModeSolid);
rc.HatchProperties.FillColor = new vdColor(vdColor.ColorType.ByBlock);
rc.PenColor = new vdColor(Color.Red, 100);