# Renumber Rooms W/Spline Changes More Room Numbers Than Selected

**URL:** <https://forum.dynamobim.com/t/renumber-rooms-w-spline-changes-more-room-numbers-than-selected/104071>\
**Category:** Revit\
**Tags:** revit, dynamo\
**Created:** [September 2, 2024, 10:31pm UTC](https://forum.dynamobim.com/t/renumber-rooms-w-spline-changes-more-room-numbers-than-selected/104071 "2024-09-02T22:31:54Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![Zachary.Owen\_7F5JSYJ](https://avatars.discourse-cdn.com/v4/letter/z/85e7bf/32.png) [@Zachary.Owen\_7F5JSYJ](https://forum.dynamobim.com/u/Zachary.Owen_7F5JSYJ)\
**Post date:** [September 2, 2024, 10:31pm UTC](https://forum.dynamobim.com/t/renumber-rooms-w-spline-changes-more-room-numbers-than-selected/104071/1 "2024-09-02T22:31:54Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![Zachary.Owen\_7F5JSYJ](https://avatars.discourse-cdn.com/v4/letter/z/85e7bf/32.png) [@Zachary.Owen\_7F5JSYJ](https://forum.dynamobim.com/u/Zachary.Owen_7F5JSYJ)\
**Post date:** [September 2, 2024, 10:56pm UTC](https://forum.dynamobim.com/t/renumber-rooms-w-spline-changes-more-room-numbers-than-selected/104071/2 "2024-09-02T22:56:24Z")

</div>

![Intersection set room number_2024-09-02_03-56-02](https://us1.discourse-cdn.com/flex022/uploads/dynamobim/original/3X/f/4/f440496ca3ccc2a228b8550fffc878edc1be7810.png)

---

<div class="post-metadata">

**Author:** ![jmark](https://avatars.discourse-cdn.com/v4/letter/j/e0b2c6/32.png) [@jmark](https://forum.dynamobim.com/u/jmark)\
**Post date:** [September 3, 2024, 4:17am UTC](https://forum.dynamobim.com/t/renumber-rooms-w-spline-changes-more-room-numbers-than-selected/104071/3 "2024-09-03T04:17:46Z")

</div>

it was solved previously

> [@Renumber rooms by spline - Not working consistently](https://forum.dynamobim.com/t/renumber-rooms-by-spline-not-working-consistently/56413):
>
> Dear all. I have made at script for renumbering rooms by a spline. I have testet this numerous time and it have been working. Now one of my colleagues had to use it for renumbering rooms on a residential project, but It don’t work cosistently. I haved testet it my self a drawed to different splines located besides each other. When using spline 02 (magenta) it works as intended, but if i use spline 03 (blue) it dosent, it only renumbers the last room. Se pictures below Working Not…

---

<div class="post-metadata">

**Author:** ![Zachary.Owen\_7F5JSYJ](https://avatars.discourse-cdn.com/v4/letter/z/85e7bf/32.png) [@Zachary.Owen\_7F5JSYJ](https://forum.dynamobim.com/u/Zachary.Owen_7F5JSYJ)\
**Post date:** [September 6, 2024, 6:02am UTC](https://forum.dynamobim.com/t/renumber-rooms-w-spline-changes-more-room-numbers-than-selected/104071/4 "2024-09-06T06:02:26Z")

</div>

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](https://forum.dynamobim.com/uploads/short-url/mLj1KOQ4bjgjhrmoBcBTBelBhmN.dyn) (58.7 KB)

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

 ![image](https://us1.discourse-cdn.com/flex022/uploads/dynamobim/original/3X/4/2/4259949d05921996ce3e006b281fb6395951a587.png)

---

<div class="post-metadata">

**Author:** ![jmark](https://avatars.discourse-cdn.com/v4/letter/j/e0b2c6/32.png) [@jmark](https://forum.dynamobim.com/u/jmark)\
**Post date:** [September 6, 2024, 9:47am UTC](https://forum.dynamobim.com/t/renumber-rooms-w-spline-changes-more-room-numbers-than-selected/104071/5 "2024-09-06T09:47:58Z")

</div>

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

 ![splineroomrenumber_2024-09-06_05-42-40](https://us1.discourse-cdn.com/flex022/uploads/dynamobim/original/3X/9/2/9282c7a376b70184a9b1014242fb23b556f2d79b.png)

```py
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()

```

---

<div class="post-metadata">

**Author:** ![bvs1982](https://avatars.discourse-cdn.com/v4/letter/b/43a26b/32.png) [@bvs1982](https://forum.dynamobim.com/u/bvs1982)\
**Post date:** [September 6, 2024, 11:11am UTC](https://forum.dynamobim.com/t/renumber-rooms-w-spline-changes-more-room-numbers-than-selected/104071/6 "2024-09-06T11:11:54Z")

</div>

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 👇.

[RoomNumberBySpline.dyn](https://forum.dynamobim.com/uploads/short-url/7mDKXFXHiYvkl5THaHNax52VHid.dyn) (58.8 KB)

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

![image](https://us1.discourse-cdn.com/flex022/uploads/dynamobim/original/3X/c/9/c93407d7c56f8b9ce2775734af49f5b2e72bdc64.png)

And lastly there is also this add-in 👇.

![image](https://us1.discourse-cdn.com/flex022/uploads/dynamobim/original/3X/f/1/f15d4799a35ba155f67bb580d8d4b5043f3f5e5e.png)
