Skip to content

Instantly share code, notes, and snippets.

Last active June 23, 2021 23:47
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save ENGworks-DEV/6a679cd9e59c58206d2c14034407857c to your computer and use it in GitHub Desktop.
Save ENGworks-DEV/6a679cd9e59c58206d2c14034407857c to your computer and use it in GitHub Desktop.
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
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()
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")
for r in getRooms(link.GetLinkDocument(), doc):
room = RoomsBoundaries(r)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment