Create Sheets

I’m trying to create sheets in Revit from sheet name and number data from an excel file that has been preformatted. Here’s the code I’m trying to use (after RiR boilerplate), but it is not working:

doc = RhinoInside.Revit.Revit.ActiveDBDocument
sheets = []

if RUN:
    t = Autodesk.Revit.DB.Transaction(doc, 'Add Sheets')
    t.Start()
    for i in range(len(sheetNumbers)):
        newSheet = Autodesk.Revit.DB.ViewSheet.Create(doc, titleblock.Id)
        newSheet.SheetNumber = sheetNumbers[i]
        newSheet.Name = sheetNames[i]
        sheets.append(newsheet)
    t.Commit()

a = sheets

The error that I am seeing is: "Runtime error (InternalException): A managed exception was thrown by Revit or by one of its external applications.

Traceback:
line 23, in script"

(line 23 is the line where the sheet is being initially created – newSheet = Autodesk.Revit.DB.ViewSheet.Create(doc, titleblock.Id))

I have confirmed multiple times that the family that I am giving the ViewSheet.Create is in fact a Titleblock Family.

Is this your entire code? if so you are missing some defined variables. Are you still interested in this?

Hi Marcello,

Here is the full picture of what I am doing (“sheetNames” is an input to the Python component). Yes, I am still interested in this but had to leave it alone before since I couldn’t make any more headway. I don’t know if this is something that McNeel is planning to add into RiR as a native Gh component, but that would be nice.

looks like you have to cast that sheet type when it gets placed in the python node. it may be easier to pull the type then the ID . It will enter the python node as an “int” then cast it to an element ID as shown
This code does not use list but should help you get going
I would also invite other input from Devs if they have more to add thx @ehsan

1 Like

I find grabbing the ID within the Python script to be more reliable but to each its own. “titleblock.Id” below works just fine for doing this.

If anyone is curious, here is the working code:

import clr
clr.AddReference('System.Core')
clr.AddReference('RhinoInside.Revit')
clr.AddReference('RevitAPI') 
clr.AddReference('RevitAPIUI')

import rhinoscriptsyntax as rs
import Rhino
import RhinoInside
import Grasshopper
import Autodesk

doc = RhinoInside.Revit.Revit.ActiveDBDocument
sheets = []

if RUN:
    #This is required to start a transaction in the Revit Document
    t = Autodesk.Revit.DB.Transaction(doc, 'Add Sheets')
    t.Start()
    for i in range(len(sheetNumbers)):
        newSheet = Autodesk.Revit.DB.ViewSheet.Create(doc, titleblock.Id)
        newSheet.SheetNumber = sheetNumbers[i]
        newSheet.Name = sheetNames[i]
        sheets.append(newSheet)
    t.Commit()

a = sheets

Here is the script that works. Make sure your excel document is coming in correctly and that your values are correctly formatted but it does work.

RiR_Sheet Maker.gh (13.1 KB)

2 Likes