Looping over Rooms and executing script for each room

I’ve written a script to calculate the maximum room width and length based on room boundaries and created project parameters to host these outputs as room instance parameters.

Script works if there is only one room in the file yet fails to iterate over each room.

Script Starts by creating the parameters.

Proceed to select all rooms and using a loopwhile to loop over them.

Then using vectors to extract boundaries and group with same direction.

Finally it assigns values to each parameter in given room.

Any insights on why it fails to loop over?

Hi @osos9696 ,

You almost never have to use a Loop in normal Dynamo (disregarding Python for now).
Could you show what doesn’t work for you when you are not using the LoopWhile node?

PS: Please open all data flowing through the nodes in that screenshot.

Hi @Daan

Here is a brief description, The process starts with selecting a room with the element room select node from the Generative design.

From there we extract the Finish Boundary Lines and Normalize their vectors to find their direction and if they are parallel.

Afterwards simply grouping each group of lines by their direction and using a python for loop to sum all lengths in the same group thus giving us a maximum length and maximum width in a given room.

Followed by assigning those values to a created instance parameters for each room and that’s it.

The issue arises when trying to do this for all rooms in a given project where I use the All elements of category node to get all rooms then follow that with a get item at index to proceed with the rest of the script for each room. Yet for some reason dynamo only executes everything for the last room in that list ignoring the previous ones.

EDIT:

# Load the Python Standard and DesignScript Libraries
import sys
import clr
import math
clr.AddReference('ProtoGeometry')
from Autodesk.DesignScript.Geometry import *

# The inputs to this node will be stored as a list in the IN variables.
dataEnteringNode = IN

# Place your code below this line
def float_round(num, places = 1, direction = math.ceil):
    return direction(num * (10**places)) / float(10**places)
ls= []
for i in IN[0]:
	for x in i:
		r = 0
		for n in x:
			r = r + n.Length
		ls.append(r)
# Assign your output to the OUT variable.
OUT = [float_round(max(ls)),float_round(min(ls))]

Here is the Python node.

PS. This Script works as intended for a single room yet I can’t manage to make it work for all rooms in the project.

Thank you.

Hi @osos9696 ,

Could you upload your script and a sample Revit model?
Also, could you reupload your Dynamo screenshot using the camera tool when zoomed in? Your nodes are now unreadable.

Hi @Daan
Here is the screenshot

As for the script and a sample file, unfortunately dynamobim doesn’t allow fresh users to upload files thus here is a Gdrive link for both the project sample and the script.
https://drive.google.com/drive/folders/1Li72bg2iAkG4b_dl5r6cnrKFWNGC0iJu?usp=share_link

Thanks, I think I know what is going on.
That said, I think there is an easier, and perhaps more robust, method using BoundingBoxes.
I’m on my phone now and dont have dynamo on hand, i’ll get back to you in an hour or so.

Hi @osos9696 ,

I found it hard to follow what you were trying to do in your vector multiplications, additions / subtractions so I overhauled your script using the “BoundingBox Method” as I described earlier.

The attached script consists of mainly two parts:

  1. All Room Boundary curves, for each room, are used to determine which direction is the most dominant per room. This isn’t really refined but could be if needed. Using this information the room curves are rotated using this direction along a curve, doesn’t really matter which one.
  2. From here a BoundingBox is created for each room. (This is also why we have to rotate the curves in the first place, since (World)AxisUnaligned BoundingBoxes are a little bit complicated, and since now our rooms are all aligned to the world this can be done with normal ones.) From these BoundingBoxes the Length and Width is easily retrievable by converting it into a Cuboid.



2022-12-27 Retrieve Room Length and Width using BoundingBoxes.dyn (54.1 KB)

PS: If you are having trouble using the script or understanding what I did please don’t hesitate to continue the Topic. Also, I really recommend checking out the Dynamo Primer, and especially List Levels and Lacing, if you are not too familiar with the ins and out of Dynamo.

3 Likes

Hi @Daan,
Thank you for your support on this project.

I would like to further ask if there is a way to eliminate the null empty rooms from the list, although it does not affect the calculation yet affects the efficiency of the script.

Here is the final layout with a few additions to simplify parsing and parameter generation.

Thank you.