using Autodesk.Revit.Attributes;
using Autodesk.Revit.DB;
using Autodesk.Revit.UI;
using System.Collections.Generic;
using System.Linq;
using Autodesk.Revit.DB;
using Autodesk.Revit.UI;
using System.Collections.Generic;
using System.Linq;
namespace Volume1
{
[Transaction(TransactionMode.Manual)]
[Regeneration(RegenerationOption.Manual)]
public class Class1 : IExternalCommand
{
public Result Execute(ExternalCommandData commandData, ref string message, ElementSet elements)
{
// throw new NotImplementedException();
UIDocument uidocument = commandData.Application.ActiveUIDocument;
Document document = uidocument.Document;
ICollection<ElementId> elementIds = uidocument.Selection.GetElementIds();
Element element = uidocument.Document.GetElement(elementIds.First());
ElementType elementType = document.GetElement(element.GetTypeId()) as ElementType;
GeometryElement geometryElement = element.get_Geometry(new Options());
double volume = 0;
foreach (GeometryObject geomeObj in geometryElement)
{
if (geomeObj is Solid)
{
Solid solid = geomeObj as Solid;
volume = solid.Volume * 0.3048 * 0.3048 * 0.3048;
}
}
string str = "元素族名称:" + elementType.FamilyName + "\n" + "元素类型:" + elementType.Name + "\n" + "体积为:" + volume.ToString("0.00");
TaskDialog.Show("元素参数", str);
return Result.Succeeded;
}
}
}
{
[Transaction(TransactionMode.Manual)]
[Regeneration(RegenerationOption.Manual)]
public class Class1 : IExternalCommand
{
public Result Execute(ExternalCommandData commandData, ref string message, ElementSet elements)
{
// throw new NotImplementedException();
UIDocument uidocument = commandData.Application.ActiveUIDocument;
Document document = uidocument.Document;
ICollection<ElementId> elementIds = uidocument.Selection.GetElementIds();
Element element = uidocument.Document.GetElement(elementIds.First());
ElementType elementType = document.GetElement(element.GetTypeId()) as ElementType;
GeometryElement geometryElement = element.get_Geometry(new Options());
double volume = 0;
foreach (GeometryObject geomeObj in geometryElement)
{
if (geomeObj is Solid)
{
Solid solid = geomeObj as Solid;
volume = solid.Volume * 0.3048 * 0.3048 * 0.3048;
}
}
string str = "元素族名称:" + elementType.FamilyName + "\n" + "元素类型:" + elementType.Name + "\n" + "体积为:" + volume.ToString("0.00");
TaskDialog.Show("元素参数", str);
return Result.Succeeded;
}
}
}