系統族,可以直接轉化為對應的類(Wall,Duct)然後取得幾何信息,普通族需要轉化為FamilyInstance
System;
System.Collections.Generic;
System.Text;
System.Windows.Forms;
Autodesk.Revit.DB;
Autodesk.Revit.UI;
Autodesk.Revit.ApplicationServices;
Autodesk.Revit.Attributes;
Autodesk.Revit.DB;
[TransactionAttribute(Autodesk.Revit.Attributes.TransactionMode.Manual)]
GetWallBFace : IExternalCommand
{
Result Execute(ExternalCommandData commandData, messages, ElementSet elements)
{
UIApplication app = commandData.Application;
Document doc = app.ActiveUIDocument.Document;
Reference ref1 = app.ActiveUIDocument.Selection.PickObject(Autodesk.Revit.UI.Selection.ObjectType.Element, );
Element elem = doc.GetElement(ref1);
Wall wall = elem Wall;
Options opt = Options();
opt.ComputeReferences = ;
opt.DetailLevel = Autodesk.Revit.DB.DetailLevels.Medium;
GeometryElement e = wall.get_Geometry(opt);
(GeometryObject obj e.Objects)
{
Solid solid = obj Solid;
(solid != && solid.Faces.Size > ) FindBottomFace(solid);
}
Result.Succeeded;
}
Face FindBottomFace(Solid solid)
{
PlanarFace pf = ;
(Face face solid.Faces)
{
pf = face PlanarFace; ( != pf)
{
(Math.Abs(pf.Normal.X) < && Math.Abs(pf.Normal.Y) < && pf.Normal.Z < )
{
TaskDialog.Show(, + pf.Area.ToString() + + pf.Origin.X.ToString() + + pf.Origin.Y.ToString() + + pf.Origin.Z.ToString() + );
;
}
}
}
pf;
}
}
[TransactionAttribute(Autodesk.Revit.Attributes.TransactionMode.Manual)]
GetColumnBottomFace : IExternalCommand
{
Result Execute(ExternalCommandData commandData, messages, ElementSet elements)
{
UIApplication app = commandData.Application;
Document doc = app.ActiveUIDocument.Document;
Reference ref1 = app.ActiveUIDocument.Selection.PickObject(Autodesk.Revit.UI.Selection.ObjectType.Element, );
Element elem = doc.GetElement(ref1);
FamilyInstance column = elem FamilyInstance;
Options opt = Options();
opt.ComputeReferences = ;
opt.DetailLevel = Autodesk.Revit.DB.DetailLevels.Medium;
GeometryElement e = column.get_Geometry(opt);
(GeometryObject obj e.Objects)
{
(obj Solid)
{
Solid solid = obj Solid;
FindBottomFace(solid);
}
(obj GeometryInstance) {
GeometryInstance geoInstance = obj GeometryInstance;
GeometryElement geoElement = geoInstance.GetInstanceGeometry();
(GeometryObject obj2 geoElement.Objects)
{
(obj2 Solid)
{
Solid solid2 = obj2 Solid;
(solid2.Faces.Size > )
FindBottomFace(solid2);
}
}
}
}
Result.Succeeded;
}
Face FindBottomFace(Solid solid)
{
PlanarFace pf = ;
(Face face solid.Faces)
{
pf = face PlanarFace;
( != pf)
{
(Math.Abs(pf.Normal.X) < && Math.Abs(pf.Normal.Y) < && pf.Normal.Z < )
{
TaskDialog.Show(, + pf.Area.ToString() + + pf.Origin.X.ToString() + +pf.Origin.Y.ToString() + + pf.Origin.Z.ToString() + );
;
}
}
}
pf;
}
}
[TransactionAttribute(Autodesk.Revit.Attributes.TransactionMode.Manual)]
GetWallBottomFace : IExternalCommand
{
Result Execute(ExternalCommandData commandData, messages, ElementSet elements)
{
UIApplication app = commandData.Application;
Document doc = app.ActiveUIDocument.Document;
Reference ref1 = app.ActiveUIDocument.Selection.PickObject(Autodesk.Revit.UI.Selection.ObjectType.Element, );
Element elem = doc.GetElement(ref1);
Wall wall = elem Wall;
Options opt = Options();
opt.ComputeReferences = ;
opt.DetailLevel = Autodesk.Revit.DB.DetailLevels.Medium;
GeometryElement e = wall.get_Geometry(opt);
(GeometryObject obj e.Objects)
{
Solid solid = obj Solid;
(solid != && solid.Faces.Size > )
{
FindBottomFaces(solid);
}
}
Result.Succeeded;
}
Face FindBottomFaces(Solid solid)
{
PlanarFace pf = ;
(Face face solid.Faces)
{
pf = face PlanarFace;
( != pf)
{
(Math.Abs(pf.Normal.X) < && Math.Abs(pf.Normal.Y) < && pf.Normal.Z < )
{
TaskDialog.Show(, pf.Area.ToString());
}
}
}
pf;
}
}end