Starting with python- doubt about duplicate view

Hi there,

I’m trying to learn python and I’m trying to duplicate a simple sheet, but I get an error and don’t know how to fix it.
imagen

imagen

Thks

Manel

What views are you trying to duplicate? You might put a try statement in there to see where it’s failing.

A sheet. a ViewSheet.

I’m trying to duplicate a sheet.

Thks Nick

Manel

Is there a view already on the Sheet?

2 Likes

use CanViewBeDuplicated Method before the duplicate Method
https://www.revitapidocs.com/2018.2/91a3b412-b96a-a754-45c7-0864e7c75c06.htm

Note:
some views can’t be duplicated

2 Likes

Also, try doing the same thing in Revit…

If it can’t be done in Revit, it probably can’t be done in Dynamo :slight_smile:

Duplicate Plan is fine :

image

Duplicate Sheet, computer says no:

image

Hopefully that’s useful,

Mark

3 Likes

Just like many other people are suggesting, your Python is probably fine, but a Revit view can only be on 1 single sheet, so if there are any views on a sheet, it can’t be duplicated. (No exceptions)

2 Likes

Sheets are considered Views in the API, which means they have access to the same methods but that doesn’t mean all those methods work. Sheets cannot be duplicated. As @c.poupin mentioned, that’s why we have the CanViewBeDuplicated method. You will have to create new sheets with the same properties in this situation.

1 Like

Yep, Revit API is a total basketcase! You cannot duplicate sheets and a good technique to find out is whether you can perform the action manually as @Mark.Ackerley showed.

Needless to say, if you do want to ‘duplicate’ a sheet for want of better word, you instead have to instantiate a new one, then match all the relevant properties (TitleBlock, parameters, name, number but you’ll need an affix or prefix to make it unique).

2 Likes

You have to use the ViewSheet.Create() method, not Duplicate. This is how I use it coming in from Excel.

image

Example Python:

import clr

clr.AddReference('RevitAPI')
from Autodesk.Revit.DB import *
from Autodesk.Revit.DB.Structure import *

clr.AddReference('RevitAPIUI')
from Autodesk.Revit.UI import *

clr.AddReference('System')
from System.Collections.Generic import List

clr.AddReference('RevitNodes')
import Revit
clr.ImportExtensions(Revit.GeometryConversion)
clr.ImportExtensions(Revit.Elements)

clr.AddReference('RevitServices')
import RevitServices
from RevitServices.Persistence import DocumentManager
from RevitServices.Transactions import TransactionManager

doc = DocumentManager.Instance.CurrentDBDocument
uidoc=DocumentManager.Instance.CurrentUIApplication.ActiveUIDocument

#Preparing input from dynamo to revit
numbers = IN[0]
names = IN[1]
tblock = UnwrapElement(IN[2])
sheets = []
#Do some action in a Transaction
TransactionManager.Instance.EnsureInTransaction(doc)
for number,name in zip(numbers,names):
	try:
		sheet = ViewSheet.Create(doc,tblock.Id)
		sheet.Name = name
		sheet.SheetNumber = number
		sheets.Add(sheet)
	except:
		sheets.Add([])
		
TransactionManager.Instance.TransactionTaskDone()

OUT = sheets
1 Like

Try except :man_facepalming:
Why??? :joy:

3 Likes

For a quick and dirty way to avoid the node crashing if sheets already exist in the model.

4 Likes

Thanks to all of you.

I’m gonna work on it and show my results asap.

I really apreciate your help.

Thks

Manel