Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Copy rooms from a link to host document
from Autodesk.Revit.DB import FilteredElementCollector, BuiltInCategory, SpatialElementBoundaryOptions, CurveArray, UV,Transaction, ViewPlan
from Autodesk.Revit.UI import Selection
import Autodesk.Revit.Creation
def selectLink():
link = uidoc.Selection.PickObject(Selection.ObjectType.Element, "Select Revit link")
return doc.GetElement(link.ElementId)
def getRooms(link, doc):
print( doc.ActiveView.Id)
linkViews = FilteredElementCollector(link).OfCategory(BuiltInCategory.OST_Views).OfClass(ViewPlan).ToElements()
lView = None
for i in linkViews:
if i.GenLevel:
if round(i.GenLevel.Elevation, 2) == round(doc.ActiveView.GenLevel.Elevation, 2):
lView = i
break
rooms = FilteredElementCollector(link, lView.Id).OfCategory(BuiltInCategory.OST_Rooms).ToElements()
return rooms
def RoomsBoundaries(room):
level = room.Level
number = room.Number
name= room.LookupParameter("Name").AsString()
opt = SpatialElementBoundaryOptions()
boundaries = room.GetBoundarySegments(opt)
curves = []
for segment in boundaries:
for b in segment:
curve = b.GetCurve()
curves.append(curve)
position = room.Location
return name, number, level, curves, position.Point
def recreateRoom(LinkRoom):
app = doc.Application
docCreation =Autodesk.Revit.Creation.Document
curveArr = CurveArray()
for c in LinkRoom[3]:
curveArr.Append(c )
doc.Create.NewRoomBoundaryLines( doc.ActiveView.SketchPlane,curveArr, doc.ActiveView )
tagPoint = UV( LinkRoom[4].X, LinkRoom[4].Y )
room = doc.Create.NewRoom( doc.ActiveView.GenLevel, tagPoint )
room.Number = LinkRoom[1]
room.Name = LinkRoom[0]
return room
if __name__ == "__main__":
link = selectLink()
t = Transaction(doc, "Create Rooms")
t.Start()
for r in getRooms(link.GetLinkDocument(), doc):
print(r)
room = RoomsBoundaries(r)
try:
recreateRoom(room)
except:
pass
t.Commit()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment