Renumber Rooms W/Spline Changes More Room Numbers Than Selected

Hello - I am new to Dynamo and I am running into difficulties with my first script. I am trying to renumber rooms that were place out of order using a spline and I’ve found many different YouTube and written tutorials, all of which don’t quite seem to work for me.

When I select the spline and run the script the room number sequence for the whole view updates, not just the spline selected rooms, and I think they’re following the order of the element ID rather than starting at the spline start point and counting up each room to the last control point.

I’m also encountering an error that may or may not be related to the issue that occurs when I pull the room poly curves onto a flat plane. The error says the poly curves are self-intersecting and I think this may be related to the use of room separation lines and columns which run through rooms, but I haven’t found a way around this.

it was solved previously

I’ve tried all of the recommendations on that thread previously and nothing has changed. When I run the script the room numbers do change, but they change out of order. For example, instead of the room number sequence starting from 1 and then increasing in count to 2,3,4,5 etc., it starts at 9 and increases in count to 10, 11, 14, 22, 21 etc.

Here’s my dynamo script:

Intersection set room number.dyn (58.7 KB)

And here’s what my model ends up looking like:

if you don’t mind using a python script, you can use this

import clr

import sys
sys.path.append('C:\Program Files (x86)\IronPython 2.7\Lib')

import System
from System import Array
from System.Collections.Generic import *

clr.AddReference('ProtoGeometry')
from Autodesk.DesignScript.Geometry import *

clr.AddReference("RevitNodes")
import Revit
clr.ImportExtensions(Revit.Elements)
clr.ImportExtensions(Revit.GeometryConversion)

clr.AddReference("RevitServices")
import RevitServices
from RevitServices.Persistence import DocumentManager 
from RevitServices.Transactions import TransactionManager 

clr.AddReference("RevitAPI")
clr.AddReference("RevitAPIUI")

import Autodesk 
from Autodesk.Revit.DB import *
from Autodesk.Revit.UI import *

# Current doc/app/ui
doc = DocumentManager.Instance.CurrentDBDocument
uiapp = DocumentManager.Instance.CurrentUIApplication 
app = uiapp.Application 
uidoc = uiapp.ActiveUIDocument

# Define list/unwrap list functions
def tolist(input):
    result = input if isinstance(input, list) else [input]
    return result

def uwlist(input):
    result = input if isinstance(input, list) else [input]
    return UnwrapElement(result)

# Preparing input from dynamo to revit
spl = UnwrapElement(IN[0])
elements = tolist(IN[0])
rooms_on_level = uwlist(IN[1])
prefix_str = IN[2]
start_num = IN[3]
selected_spline = spl.GeometryCurve

# Do some action in a Transaction
TransactionManager.Instance.EnsureInTransaction(doc)


pt_at_spline = []
rm_list = []
rm_mid_lst = []

for rm in rooms_on_level:
    rm_geo = rm.ClosedShell
    rm_bb = rm_geo.GetBoundingBox()
    rm_bb_mid = XYZ((rm_bb.Min.X + rm_bb.Max.X) / 2, (rm_bb.Min.Y + rm_bb.Max.Y) / 2, (rm_bb.Min.Z + rm_bb.Max.Z) / 2)
    rm_mid_lst.append(rm_bb_mid)
    spl_pt = selected_spline.Project(rm_bb_mid)
    intersection_pt = spl_pt.Parameter  
    pt_at_spline.append(intersection_pt)
    rm_list.append(rm)

combined_lst = list(zip(pt_at_spline, rm_list))
combined_lst.sort(key=lambda x: x[0])


for index, (i, rm) in enumerate(combined_lst, start=int(start_num)):
    if rm:
        room_name = rm.get_Parameter(BuiltInParameter.ROOM_NAME).AsString()
        room_number = rm.get_Parameter(BuiltInParameter.ROOM_NUMBER)
        room_number.Set('{}.{}'.format(prefix_str, str(index).zfill(3)))
   

TransactionManager.Instance.TransactionTaskDone()

By the looks of it your List structure / filtering isn’t right.
When i test it in a project with 9 Rooms and the Spline goes through
only 4 of them i still get 9 Rooms. Also i think you don’t need List.Reverse.

This is what i have / use :point_down:.

RoomNumberBySpline.dyn (58.8 KB)

If you only need to do a few Rooms there is also this handy node :point_down:.

image

And lastly there is also this add-in :point_down:.

image