Last active
September 11, 2024 04:44
-
-
Save ENGworks-DEV/6a679cd9e59c58206d2c14034407857c to your computer and use it in GitHub Desktop.
Copy rooms from a link to host document
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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
This Code don't work - Please add
uidoc = revit.ActiveUIDocument # Active Revit document in the UI
doc = uidoc.Document # The actual Revit model document
after "import Autodesk.Revit.Creation"