Creating and Populating View Sheets
View sheets can be created and managed automatically using the Revit API.
Creating a Sheet
To start, we'll keep things simple and discuss adding a sheet to a file. To do that, we'll use the ViewSheet.Create() method, which takes two arguments:- The document we want to add our sheet to.
- The ID of the title block we want the view sheet to use.
doc = DocumentManager.Instance.CurrentDBDocument
#Get the ID of the TitleBlock we want to create
titleblocks = Fec(doc).OfCategory(Bic.OST_TitleBlocks).WhereElementIsElementType()
for titleblock in titleblocks:
name = titleblock.get_Parameter(BuiltInParameter.SYMBOL_NAME_PARAM).AsString()
if name == "lorem_ipsum":
target_titleblock_id = titleblock.Id
break
#Create a ViewSheet of the established target type
TransactionManager.Instance.EnsureInTransaction(doc)
new_sheet = ViewSheet.Create(doc, target_titleblock_id)
TransactionManager.Instance.TransactionTaskDone()
Setting up a Sheet
Once we've created a sheet, we need to set up its parameters. As we discussed here, this involves getting the parameter, then using Set() to overwrite its parameter. (Make sure to pass the parameter a value of the expected type. "SHEET_NUMBER", for instance, despite its name, takes a string rather than an integer.) plannummer_para = new_sheet.get_Parameter(BuiltInParameter.SHEET_NUMBER)
planname_para = new_sheet.get_Parameter(BuiltInParameter.SHEET_NAME)
TransactionManager.Instance.EnsureInTransaction(doc)
plannummer_para.Set("000")
planname_para.Set("lorem_ipsum")
TransactionManager.Instance.TransactionTaskDone()
Populating a Sheet
Our sheet should now be set up, though it's looking a little empty. That's because we need to add a view. We'll use Viewport.Create(), which takes four arguments:- The document we want to add our sheet to.
- The ID of the sheet we want to populate.
- The ID of the view we want to add.
- The desired position of the view on the sheet.
target_sheet_id = new_sheet.Id
#Get View ID
views = Fec(doc).OfCategory(Bic.OST_Views).WhereElementIsNotElementType().ToElements()
for view in views:
name = view.Name
if name == "lorem_ipsum":
target_view = view
target_view_id = view.Id
break
sheet_midpoint = XYZ(-0.487, 0.344, 0)
TransactionManager.Instance.EnsureInTransaction(doc)
add_viewport = Viewport.Create(doc, target_sheet_id, target_view_id, sheet_midpoint)
TransactionManager.Instance.TransactionTaskDone()
You should now see the desired view in the centre of your sheet.
Comments
Post a Comment