如何获取房间中心的XYZ数据?
我试图将一个元素放置在几个房间的中心。到目前为止,我已经通过使用位置点实现了类似的目标,该位置点将元素放置在靠近中心的位置,但并不精确。
我尝试使用两种我认为有助于完成此任务的方法来解决此问题:GetElementCenter 和 GetRoomCenter,但当我运行该插件时,没有任何反应。
class Class2
{
public Result Execute(ExternalCommandData commandData, ref string message, ElementSet elements)
{
//Get access to Revit command data, user interface and document
UIApplication uiapp = commandData.Application;
UIDocument uidoc = uiapp.ActiveUIDocument;
Document doc = uidoc.Document;
//Collect all rooms
FilteredElementCollector roomCollector = new FilteredElementCollector(doc).OfClass(typeof(SpatialElement));
// Collect element
FilteredElementCollector element = new FilteredElementCollector(doc).OfClass(typeof(FamilySymbol)).OfCategory(BuiltInCategory.OST_Cameras);
//Get symbol
FamilySymbol elementSym = element.FirstElement() as FamilySymbol;
using (Transaction tx = new Transaction(doc))
{
try
{
tx.Start("Start");
//For loop for every room in the roomCollector
foreach (SpatialElement oneRoom in roomCollector)
{
//Get area of each room
Room room = oneRoom as Room;
double area = room.Area;
//Location point version
Location loc = room.Location;
LocationPoint location = loc as LocationPoint;
XYZ point = (null == location) ? XYZ.Zero : location.Point;
//New version
XYZ source = GetRoomCenter(room);
double smallRoom = 301;
if (area <= smallRoom)
{
doc.Create.NewFamilyInstance(source, elementSym, Autodesk.Revit.DB.Structure.StructuralType.NonStructural);
}
}
tx.Commit();
}
catch (Exception e)
{
Debug.Print(e.Message);
tx.RollBack();
}
}
TaskDialog.Show("Message", "Task completed successfully");
return Result.Succeeded;
}
public XYZ GetElementCenter(Room room)
{
BoundingBoxXYZ bounding = room.get_BoundingBox(null);
XYZ center = (bounding.Max + bounding.Min) * 0.5;
return center;
}
public XYZ GetRoomCenter(Room room)
{
XYZ boundCenter = GetElementCenter(room);
LocationPoint locPt = (LocationPoint)room.Location;
XYZ roomCenter = new XYZ(boundCenter.X, boundCenter.Y, locPt.Point.Z);
return roomCenter;
}
}
任何
关于获取房间中心的 XYZ 数据的帮助将不胜感激。
I am trying to place an element into the center of several rooms. So far I have achieved something similar by using the Location Point which has placed the element close to the center but not exact.
I attempted to fix this by using two methods that I believed would help accomplish this task, GetElementCenter and GetRoomCenter but when I run the plugin, nothing happens.
class Class2
{
public Result Execute(ExternalCommandData commandData, ref string message, ElementSet elements)
{
//Get access to Revit command data, user interface and document
UIApplication uiapp = commandData.Application;
UIDocument uidoc = uiapp.ActiveUIDocument;
Document doc = uidoc.Document;
//Collect all rooms
FilteredElementCollector roomCollector = new FilteredElementCollector(doc).OfClass(typeof(SpatialElement));
// Collect element
FilteredElementCollector element = new FilteredElementCollector(doc).OfClass(typeof(FamilySymbol)).OfCategory(BuiltInCategory.OST_Cameras);
//Get symbol
FamilySymbol elementSym = element.FirstElement() as FamilySymbol;
using (Transaction tx = new Transaction(doc))
{
try
{
tx.Start("Start");
//For loop for every room in the roomCollector
foreach (SpatialElement oneRoom in roomCollector)
{
//Get area of each room
Room room = oneRoom as Room;
double area = room.Area;
//Location point version
Location loc = room.Location;
LocationPoint location = loc as LocationPoint;
XYZ point = (null == location) ? XYZ.Zero : location.Point;
//New version
XYZ source = GetRoomCenter(room);
double smallRoom = 301;
if (area <= smallRoom)
{
doc.Create.NewFamilyInstance(source, elementSym, Autodesk.Revit.DB.Structure.StructuralType.NonStructural);
}
}
tx.Commit();
}
catch (Exception e)
{
Debug.Print(e.Message);
tx.RollBack();
}
}
TaskDialog.Show("Message", "Task completed successfully");
return Result.Succeeded;
}
public XYZ GetElementCenter(Room room)
{
BoundingBoxXYZ bounding = room.get_BoundingBox(null);
XYZ center = (bounding.Max + bounding.Min) * 0.5;
return center;
}
public XYZ GetRoomCenter(Room room)
{
XYZ boundCenter = GetElementCenter(room);
LocationPoint locPt = (LocationPoint)room.Location;
XYZ roomCenter = new XYZ(boundCenter.X, boundCenter.Y, locPt.Point.Z);
return roomCenter;
}
}
}
Any help on getting the XYZ data of the center of a room would be greatly appreciated.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
假设您的房间有直墙,我建议您看一下数学和几何算法来确定 多边形的中心点。像这样的新寻找多边形视觉中心的算法可能最适合您的需求,即使您既没有陈述这个事实也可能还没有意识到它:-)
Assuming that you have straight walls bounding the room, I would suggest that you take a look at mathematical and geometrical algorithms for determining the center point of a polygon. Something like this new algorithm for finding a visual center of a polygon is probably best suited to your needs, even though you neither state this fact nor probably are yet aware of it :-)