Finding the surface area of a model (house)

Hi there.

I’m currently trying to use the Ruby API to automatically detect

  • the surface area of my house
  • find rooms in the inside

With the easiest model I can imagine (a cube), this is straightforward. I either detect the floor and use it’s edges to find the horizontal faces, or I use a group to get the bounding box, both gives me the height, width and depth of my model. This get’s more complicated when my the walls are modeled with a depth, there are multiple rooms that don’t necessarily have a rectangle bounding box and all kind of other problems.

To solve this, I first tried generating a point cloud and construct a convex hull, which only works for special cases (rectangle models), at least it doesn’t care if the model doesn’t align to the axes. After a bit more googling, I apparently need to calculate concave hulls, but depending on the points, there are multiple solutions.

I think constructing the area like this is way overkill and even then not reliable, but I’m not sure how I can incorporate edge/face information into my calculation.

How would you solve this problem? Do you have any suggestions?

to get the surface areas:
IF all the floors have the same material and that material is only applied on the front face
AND the same for the walls and ceiling
you could generate the surface area ‘by material’.

Without Ruby its possible by right click the material in the material browser and choose Area. That gives you the area of all the faces with that material.
With Ruby I guess it can be done as well although I didn’t look into it.

Thanks for the suggestion, but I’m more interested in the geometry itself, especially faces that form the outer layer. After thinking a bit more about my problem, I started with monkey-patching `Sketchup::Face``:

def get_outer
	result = []
	queue = self.get_surrounding_walls
	while !queue.empty? do
		curr = queue.pop
		next if result.include? curr
		result << curr
		curr.get_surrounding_walls.each do |x|
			queue.push x

Which, in addition to get_surrounding_walls (returns the connected vertical faces), returns me all faces connected to each other. Using this on a face that is part of the outer layer I get the intended result. It needs to be tweaked to handle cases in which a interior wall is connected, but I already have a plan for that (using their angles to decide which face I want to add to the queue).

It kinda works, but isn’t as elegant as I want it to be… Any other ideas?

Please do not directly modify shared modules and classes.
(Either Ruby base classes or SketchUp API classes.)

Instead use a custom refinement module within your toplevel author namespace, and then have your plugin refine IT’s use of those classes, via the new Ruby 2.x method using().


1 Like

+1 - I can’t stress enough how important that is since all extensions share the same environment.
More details to why and other things to beware of:

1 Like