Sunday, May 9, 2010

REVIT API - Bottom face edges of a wall


public IExternalCommand.Result Execute(ExternalCommandData Revit, ref string message, ElementSet elementsSet)
{
///To get Active Document
Document document = Revit.Application.ActiveDocument;
//To get the Selected Elements
Selection selection = document.Selection;
foreach (Autodesk.Revit.Element ele in selection.Elements.OfType())
{
Wall wall = (Wall)ele;
wallBottom.GetFacesAndEdges(wall);
wallBottom.writeXml();
}
return IExternalCommand.Result.Succeeded;
}

public class FetchWallBottom
{
//Create Face object
private Face _bottomFace = new Face();

List array = new List();
///
/// To get and set Face Values
///

public Face bottomFace
{
get
{
return _bottomFace;
}
set
{
_bottomFace = value;
}
}
///
/// To Get the Faces and Edges of the Wall
///

/// WAll
public void GetFacesAndEdges(Wall wall)
{
Autodesk.Revit.Geometry.Options opt = new Options();
Autodesk.Revit.Geometry.Element geomElem = wall.get_Geometry(opt);
foreach (GeometryObject geomObj in geomElem.Objects)
{
Solid geomSolid = geomObj as Solid;
if (null != geomSolid)
{
foreach (Face geomFace in geomSolid.Faces)
{
getPlanarFaceInfo(geomFace,geomSolid);
}
}
}
}
///
/// To get the palner Surface of the Selected WAll
///

///
///
public void getPlanarFaceInfo(Face geomFace, Solid solid)
{
PlanarFace planarFace = geomFace as PlanarFace;
XYZ normal = planarFace.Normal;
if (normal.Z == -1)
{
this._bottomFace= geomFace;
array.Add(geomFace.EdgeLoops);
}
}
}
}

No comments:

Post a Comment