Room to Space Script

I’m working on a script to transform all room existing in a linked file to spaces for MEP use.
It will be helpfull, if somebody can point me to a such script or something like already done.

If not can someone help me by telling me the easiest way to achieve this script?
Thank you in advance


This sounds like a great script idea! Have you tried asking ChatGPT about it? If you do, just be sure to say “in python using the Revit API” to clue ChatGPT into what you’re working with. It usually has really good suggestions.

Thank you for the reply and Happy new year.
I tried some AI like GPT, Bard and Codeium. Thes answers are more or less the same, but they point me to wrong classes or methodes. here an example from Bard:

import clr
from Autodesk.Revit.DB import *

# Get the current document and active view
doc = __revit__.ActiveUIDocument.Document
view = doc.ActiveView

# Get the linked model
linked_models = FilteredElementCollector(doc).OfClass(RevitLinkInstance).ToElements()
linked_model = linked_models[0]  # Assuming you want to work with the first linked model

# Access elements in the linked model
link_doc = linked_model.GetLinkDocument()

# Get rooms from the linked model
rooms = FilteredElementCollector(link_doc).OfCategory(BuiltInCategory.OST_Rooms).WhereElementIsNotElementType().ToElements()

# Create corresponding spaces in the current document
for room in rooms:
    # Map room properties to space properties as needed
    space = Space.Create(doc, room.Location.Point, room.LevelId)
    space.Name = room.Name
    # ... Add more property mappings as needed ...

    # Place the space in the same location as the room
    space.Location = room.Location

    # Add the space to the active view

But to be honest, it help me, in some way, to structure the workflow to realise the script.