I Have found the solution and I put the code here. The code returns vertices on the top surface of a floor. User selects the Floor and its upper vertices and Location of them will be shown.
Thanks to my friend @ahmedsherif9220 for his guides.
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Autodesk.Revit.DB;
using Autodesk.Revit.DB.Structure;
using Autodesk.Revit.UI;
using Autodesk.Revit.ApplicationServices;
using Autodesk.Revit.Attributes;
using Autodesk.Revit.UI.Selection;
using System.Collections;
using ElementFiltering;
//using System.Windows.Forms;
using Autodesk.Revit.DB.DirectContext3D;
namespace GetVertices
{
[Transaction(TransactionMode.Manual)]
[RegenerationAttribute(RegenerationOption.Manual)]
internal partial class GetVertices : IExternalCommand
{
// member variables
Application m_rvtApp;
Document m_rvtDoc;
public Result Execute(ExternalCommandData commandData, ref string message, ElementSet elements)
{
// Get the access to the top most objects
UIApplication rvtUIApp = commandData.Application;
UIDocument rvtUIDoc = rvtUIApp.ActiveUIDocument;
//m_rvtApp = rvtUIApp.Application;
m_rvtDoc = rvtUIDoc.Document;
Reference SelElem = rvtUIDoc.Selection.PickObject(ObjectType.Element, "Please Select a Floor!");
Element elem = m_rvtDoc.GetElement(SelElem);
// Options For Geometry
Options opt = new Options();
opt.ComputeReferences = true;
opt.DetailLevel = ViewDetailLevel.Fine;
PlanarFace planarTopface = null;
FaceArray faces = null;
Face topFace = null;
GeometryElement elemGeom = elem.get_Geometry(opt);
foreach (GeometryObject geomObj in elemGeom)
{
Solid geomSolid = geomObj as Solid;
faces = geomSolid.Faces;
//GetTopFaceOfElement(geomSolid);
foreach (Face f in faces)
{
PlanarFace pf = f as PlanarFace;
if (pf.FaceNormal.IsAlmostEqualTo(new XYZ(0, 0, 1)))
{
planarTopface = pf;
topFace = pf;
}
}
}
CurveLoop[] curves = topFace.GetEdgesAsCurveLoops().ToArray();
Array curves1 = curves;
List<XYZ> points = new List<XYZ>();
List<Line> linesAround = new List<Line>();
foreach (CurveLoop i in curves1)
{
foreach (Line l in i)
{
var curve = l as Curve;
var pointsofcurve = curve.Tessellate();
linesAround.Add(l);
//now you have the two points of the curve
foreach (XYZ point in pointsofcurve)
{
points.Add(point);
}
}
}
List<XYZ> verts = new List<XYZ>();
// Adding points to vertices list which is called verts
int z = 0;
while (z < points.Count)
{
verts.Add(points[z]);
z = z + 2;
}
string s = null;
for(int v=0; v < verts.Count; v++)
{
s+="Vertex "+(v+1).ToString()+" Location is: "+$"({verts[v].X},{verts[v].Y},{verts[v].Z})\n";
}
TaskDialog.Show("Vertices of Selected Floor Information", "Number Of Detected Lines: " + linesAround.Count.ToString() + "\nNumber Of Detected Vertices: " + verts.Count.ToString()+"\n"+s);
return Result.Succeeded;
}