-1

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

Heretic Monkey
  • 11,687
  • 7
  • 53
  • 122
Anderson
  • 5
  • 3

3 Answers3

0

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.

Jeremy Tammik
  • 7,333
  • 2
  • 12
  • 17
  • Can you explain "If you get four boundary segments with right angles between them"? I looked at the documentation for GetBoundarySegments but it's not clear on how to implement it or achieve what you have said – Anderson Apr 07 '22 at 12:01
  • If and only if the room is rectangular, it will have four boundary segments with pairwise equal length and at right angles to each other. Otherwise, the room is not rectangular. Some of the boundary edges may be split into parts due to difference adjoining walls; in that case, combine the collinear fragments. – Jeremy Tammik Apr 08 '22 at 13:28
0

Given the values for area and perimeter, your length and width can't be integers. Calulating them,

var length = (perimeter - Math.Sqrt(Math.Pow(perimeter, 2) - 16 * area)) / 4;
var width = area / length;

My derivation:

A = l*w
P = 2l + 2w = 2(l+w)

l = A/w

P = 2(A/w+w)
P = 2A/w + 2w
wP = 2A + 2w^2
-2w^2+wP = 2A
-2W^2 + wP - 2A = 0

a = -2
b = P
c = -2A

x = (-b +/- Sqrt(b^2 - 4ac)) / 2a
w = (-P +/- Sqrt(P^2 - 4*(-2)*(-2A)) / 2(-2)
w = (-P +/- Sqrt(P^2 - 16A)) / -4
  = (-P - Sqrt(P^2 - 16A)) / -4
  = (P + Sqrt(P^2 - 16A)) / 4
w = (-P + Sqrt(P^2 - 16A)) / -4
  = (P - Sqrt(P^2 - 16A)) / 4
NetMage
  • 26,163
  • 3
  • 34
  • 55
0

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

IList<IList<BoundarySegment>> boundaryList = room.GetBoundarySegments(new SpatialElementBoundaryOptions());

You can get the lenght, orientation and more with

Curve curve = boundarySegment.GetCurve();

For exemple:

double nativeLenght = boundarySegment.GetCurve().Length;
F. Robb
  • 46
  • 5