添加项目文件。
This commit is contained in:
101
Szmedi.RvKits/Civil/Room3D.cs
Normal file
101
Szmedi.RvKits/Civil/Room3D.cs
Normal file
@@ -0,0 +1,101 @@
|
||||
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Windows;
|
||||
|
||||
using ACadSharp.Entities;
|
||||
|
||||
using Autodesk.Revit.Attributes;
|
||||
using Autodesk.Revit.DB;
|
||||
using Autodesk.Revit.DB.Architecture;
|
||||
using Autodesk.Revit.UI;
|
||||
|
||||
using Nice3point.Revit.Toolkit.External;
|
||||
|
||||
namespace Szmedi.RvKits.Civil
|
||||
{
|
||||
/// <summary>
|
||||
/// Revit执行命令
|
||||
/// </summary>
|
||||
[Transaction(TransactionMode.Manual)]
|
||||
|
||||
public class Room3D : ExternalCommand
|
||||
{
|
||||
public override void Execute()
|
||||
{
|
||||
var result=MessageBox.Show("请确保已已放置房间,是否继续?", "提示", MessageBoxButton.OKCancel, MessageBoxImage.Information);
|
||||
if (result != MessageBoxResult.OK)
|
||||
{
|
||||
Result = Result.Cancelled;
|
||||
return;
|
||||
}
|
||||
var rooms = new FilteredElementCollector(Document).OfCategory(BuiltInCategory.OST_Rooms)
|
||||
.Cast<Room>()
|
||||
.ToList();
|
||||
if (!rooms.Any())
|
||||
{
|
||||
MessageBox.Show("未发现房间", "提示", MessageBoxButton.OK, MessageBoxImage.Information);
|
||||
Result = Result.Cancelled;
|
||||
return;
|
||||
}
|
||||
Document.InvokeGroup(
|
||||
tg =>
|
||||
{
|
||||
var sb = new StringBuilder();
|
||||
//Dictionary<Room, List<CurveLoop>> pairs = new();
|
||||
using Transaction trans = new(Document, "房间实体");
|
||||
foreach (var room in rooms)
|
||||
{
|
||||
try
|
||||
{
|
||||
trans.Start();
|
||||
|
||||
List<CurveLoop> curveLoops = [];
|
||||
var segments = room.GetBoundarySegments(new SpatialElementBoundaryOptions());
|
||||
foreach (var segment in segments)
|
||||
{
|
||||
CurveLoop curveLoop = new();
|
||||
foreach (var boundary in segment)
|
||||
{
|
||||
curveLoop.Append(boundary.GetCurve());
|
||||
}
|
||||
curveLoops.Add(curveLoop);
|
||||
}
|
||||
var geos = new List<GeometryObject>();
|
||||
if (curveLoops.Count > 0)
|
||||
{
|
||||
var baseElev = room.Level.Elevation;
|
||||
|
||||
var lowerOffset = room.get_Parameter(BuiltInParameter.ROOM_LOWER_OFFSET).AsDouble();
|
||||
var upperOffset = room.get_Parameter(BuiltInParameter.ROOM_UPPER_OFFSET).AsDouble();
|
||||
var extrusionDist = upperOffset - lowerOffset;
|
||||
|
||||
var solid = GeometryCreationUtilities.CreateExtrusionGeometry(
|
||||
curveLoops,
|
||||
XYZ.BasisZ,
|
||||
extrusionDist);
|
||||
geos.Add(solid);
|
||||
}
|
||||
//var directShape = DirectShape.CreateElement(
|
||||
// Document,
|
||||
// Category.GetCategory(Document, BuiltInCategory.OST_GenericModel).Id);
|
||||
//directShape.Name = room.Name;
|
||||
var category = Category.GetCategory(Document, BuiltInCategory.OST_GenericModel);
|
||||
var directShape = Document.CreateDirectShapeInstance(
|
||||
"房间实体",
|
||||
BuiltInCategory.OST_GenericModel,
|
||||
geos);
|
||||
directShape.get_Parameter(BuiltInParameter.DOOR_NUMBER).Set(room.Name);
|
||||
trans.Commit();
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
sb.AppendLine($"{ex.Message}");
|
||||
}
|
||||
}
|
||||
var x = sb.Length > 0 ? MessageBox.Show(sb.ToString(), "错误") : MessageBox.Show("创建完成", "提示");
|
||||
//doc.FamilyCreate.NewModelText()
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user