Hi All,
Trying to collect all levels from a project and using to create sectioned rooms by floor plan. I have managed to make it work in Dynamo (python) however, I am trying to convert it to a button.
import clr
clr.AddReference('RevitAPI')
from Autodesk.Revit.DB import *
clr.AddReference("RevitNodes")
import Revit
clr.ImportExtensions(Revit.Elements)
doc = __revit__.ActiveUIDocument.Document
uidoc = __revit__.ActiveUIDocument
t = Transaction(doc, "Floor Plan by Room")
level = FilteredElementCollector(doc).OfCategory(BuiltInCategory.OST_Levels)\
.WhereElementIsNotElementType()\
.ToElements()
for l in level:
if l.Name == "Level 1":
level = doc.ActiveView.Document.GetElement(l.Id)
break
filter = Architecture.RoomFilter()
collector = FilteredElementCollector(doc, level.Id).WherePasses(filter).ToElements()
t.Start()
for room in collector:
viewtypeid = level.GetTypeId()
levelid = room.LevelId
roomview = ViewPlan.Create(doc, viewtypeid, levelid)
roombb = room.get_BoundingBox(level)
rmax = roombb.Max
rmin = roombb.Min
newmax = XYZ(rmax.X + 1, rmax.Y + 1, rmax.Z)
newmin = XYZ(rmin.X - 1, rmin.Y - 1, rmin.Z)
newBB = BoundingBoxXYZ()
newBB.Max = newmax
newBB.Min = newmin
roomview.CropBoxActive = True
roomview.CropBox = newBB
roomview.Name = room.LookupParameter("Name").AsString()
output.append(roomview.ToDSType(True))
t.Commit()
This is the code written. And the error give in “viewId is not a view”
Any suggestions are appreciated.
Many thanks
Helmy000:
level.GetTypeId()
Hello,
level.GetTypeId()
return an ElementId of a LevelType , according to the API Revit Doc you need a viewFamilyTypeId
Online Documentation for Autodesk's Revit API: 2015, 2016, 2017, 2017.1, 2018
Note:
pyRevit has a dedicated forum
c.poupin:
viewFamilyTypeId
Thank you I was not aware of the forum
your collector should fail when you are feeding level.Id as that particular constructor requires viewId. Instead, you should use LogicalAndFilter with your RoomFilter to filter out rooms of specific levels. Same goes for the ViewPlan.Create constructor input.
I got it to work finally, using the following code, might be useful for someone.
import clr
clr.AddReference(‘RevitAPI’)
from Autodesk.Revit.DB import *
clr.AddReference(“RevitNodes”)
import Revit
clr.ImportExtensions(Revit.Elements)
doc = revit .ActiveUIDocument.Document
uidoc = revit .ActiveUIDocument
t = Transaction(doc, “Floor Plan by Room”)
plan = FilteredElementCollector(doc).OfClass(ViewFamilyType).ToElements()[0]
toggle = True
output =
if toggle:
filter = Architecture.RoomFilter()
collector = FilteredElementCollector(doc).WherePasses(filter).ToElements()
t.Start()
for room in collector:
viewtypeid = plan.Id
level = room.LevelId
roomview = ViewPlan.Create(doc, viewtypeid, level)
roomview.Name = room.LookupParameter("Name").AsString() + " - Plan " + str(room.Id)
t.Commit()
t.Start()
roombb = room.get_BoundingBox(doc.ActiveView)
rmax = roombb.Max
rmin = roombb.Min
newmax = XYZ(rmax.X + 1, rmax.Y + 1, rmax.Z)
newmin = XYZ(rmin.X - 1, rmin.Y - 1, rmin.Z)
newBB = BoundingBoxXYZ()
newBB.Max = newmax
newBB.Min = newmin
roomview.CropBoxActive = True
roomview.CropBox = newBB
roomview.Name = room.LookupParameter("Name").AsString() + " - Plan " + str(room.Id)
output.append(roomview)
t.Commit()
else:
output.append("Set to True")