Delete unplaced Rooms and centralized the room and the tag

I am learning python, I am trying to delete the unplaced rooms and center the room location and the tag location. help me

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

clr.AddReference("RevitAPI")
import Autodesk
from Autodesk.Revit.DB import *

# Current doc/app/ui
doc = DocumentManager.Instance.CurrentDBDocument

#Filtered element collector (all rooms)
rooms = FilteredElementCollector(doc).OfCategory(BuiltInCategory.OST_Rooms)


#Filter rooms to those with area more than 0 (Unplaced)
placed , unplaced  = [x], [x]

for rm in rooms:
	if rm.Area  0:
		placed.append(rm)		
	else:
		unplaced.append(rm.Id)

#Delete unplaced rooms

TransactionManager.Instance.EnsureInTransaction(doc)

delrooms = doc.Delete(unplaced) + "unplaced rooms deleted"

TransactionManager.Instance.TransactionTaskDone()


# Assign your output to the OUT variable.
OUT = placed, unplaced

1 Like

It deletes a single room but not delete a list of rooms.:frowning:

Just iterate through List Comprehension:

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

clr.AddReference("RevitAPI")
import Autodesk
from Autodesk.Revit.DB import *

import System
from System.Collections.Generic import List
# Current doc/app/ui
doc = DocumentManager.Instance.CurrentDBDocument

#Filtered element collector (all rooms)
rooms = FilteredElementCollector(doc).OfCategory(BuiltInCategory.OST_Rooms)


#Filter rooms to those with area more than 0 (Unplaced)
placed , unplaced  = [], []

for rm in rooms:
	if rm.Area > 0:
		placed.append(rm)		
	else:
		unplaced.append(rm.Id)

#Delete unplaced rooms

TransactionManager.Instance.EnsureInTransaction(doc)

#iterate through List Comprehension
delrooms = [doc.Delete(i) for i in unplaced]

TransactionManager.Instance.TransactionTaskDone()


# Assign your output to the OUT variable.
OUT = placed, unplaced
2 Likes

You made my day… thanks…:frowning: