我想在 Revit 中获取房间的长度和宽度值,但 Revit 似乎无法像访问房间周长、面积和体积那样访问这些值。
我决定首先通过代码查找房间的长度值,因为我可以使用长度计算宽度,但我得到的结果似乎不正确,下面是我的代码的相关部分:
Room room = oneRoom as Room;
double area = room.Area;
double perimeter = room.Perimeter;
int roomArea = (int)area;
int roomPerimeter = (int)perimeter;
int length = (int)(((roomPerimeter / 2) - Math.Sqrt((roomPerimeter / 2) ^ 2 - 4 * roomArea)) / 2);
//int width = roomArea / length;
string valueMessage = "perimeter of room is " + length;
TaskDialog.Show("Message", valueMessage);
我正在使用方程来工作求出给定面积和周长的长度。然而,我得到的值是-21,474,836,648,即使我将该值视为厘米并忽略它是一个负值,它也非常高并且不正确。
对于房间的上下文,它是一个矩形,周长为 116.141732283465,面积为 755.626511253023
感谢任何有关解决此问题的帮助
I want to get the length and width values of a room within Revit but it appears that Revit does not give access to these values like it does with room perimeter, area and volume.
I decided to start by finding the length value for a room through code as I can calculate the width using the length but I am getting results that do not seem correct, below is the relevant part of my code:
Room room = oneRoom as Room;
double area = room.Area;
double perimeter = room.Perimeter;
int roomArea = (int)area;
int roomPerimeter = (int)perimeter;
int length = (int)(((roomPerimeter / 2) - Math.Sqrt((roomPerimeter / 2) ^ 2 - 4 * roomArea)) / 2);
//int width = roomArea / length;
string valueMessage = "perimeter of room is " + length;
TaskDialog.Show("Message", valueMessage);
I am using an equation to work out the length given the area and the perimeter. The value i get back however is -21,474,836,648 which even if I treat the value as cm and ignore that it is a minus value, is insanely high and can't be correct.
For context on the room, it is a rectangle, the perimeter is 116.141732283465 and the area is 755.626511253023
Any help on fixing this issue is appreciated
发布评论
评论(3)
您可能确实想使用 room 类中的 GetBoundarySegments() 方法,它可以为您提供形成房间的段。
请注意,这是一个列表列表,因为房间可能包含内部循环
您可以获取长度、方向等信息,
例如:
you might indeed want to use the GetBoundarySegments() method from the room class, wich makes give you the segments which forms the room.
Note that this is a list of lists as the room could include inner loops
You can get the lenght, orientation and more with
For exemple:
首先,内部修订数据库单元或长度为帝国脚。如果您正在用公制单元工作,则必须将其转换。
其次,房间可以具有任何形状,因此很难定义“宽度”和“长度”的含义。
如果您只想将计算仅限于矩形房间,那么您的问题很有意义。
我建议使用方法。如果您之间的四个边界段之间具有直角,则两个边界段同样长,而其他两个同样短,则解决了您的问题。
在大多数情况下,您将不得不考虑更多。
First, the internal Revit database unit or length is imperial feet. If you are working in metric units, you will have to convert them.
Secondly, a room can have any shape, so it can be very hard to define what exactly might be meant by 'width' and 'length'.
If you wish to restrict your calculations to rectangular rooms only, your question makes perfect sense.
I would suggest querying the room for its boundary using the
GetBoundarySegments
method. If you get four boundary segments with right angles between them, two of them are equally long and the other two equally short, your problem is solved.In most cases, you will have to think a bit more.
给定
面积
和周长
的值,您的长度和宽度不能是整数。计算它们,我的推导:
Given the values for
area
andperimeter
, your length and width can't be integers. Calulating them,My derivation: