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.
Thks
Manel
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.
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?
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
Also, try doing the same thing in Revit…
If it can’t be done in Revit, it probably can’t be done in Dynamo
Duplicate Plan is fine :
Duplicate Sheet, computer says no:
Hopefully that’s useful,
Mark
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)
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.
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).
You have to use the ViewSheet.Create() method, not Duplicate. This is how I use it coming in from Excel.
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
Try except
Why???
For a quick and dirty way to avoid the node crashing if sheets already exist in the model.
Thanks to all of you.
I’m gonna work on it and show my results asap.
I really apreciate your help.
Thks
Manel