Dynamo python script in create sheets

Hi every one ,
I create script in python but every time i us it
create sheets but delete old sheet don’t keep old allows

import clr
import sys
sys.path.append('C:\Program Files (x86)\IronPython 2.7\Lib')
import System
from System import Array
from System.Collections.Generic import *
clr.AddReference('ProtoGeometry')
from Autodesk.DesignScript.Geometry import *
clr.AddReference("RevitNodes")
import Revit
clr.ImportExtensions(Revit.Elements)
clr.ImportExtensions(Revit.GeometryConversion)
clr.AddReference("RevitServices")
import RevitServices
from RevitServices.Persistence import DocumentManager 
from RevitServices.Transactions import TransactionManager 

clr.AddReference("RevitAPI")
clr.AddReference("RevitAPIUI")

import Autodesk 
from Autodesk.Revit.DB import *
from Autodesk.Revit.UI import *

doc = DocumentManager.Instance.CurrentDBDocument
uiapp = DocumentManager.Instance.CurrentUIApplication 
app = uiapp.Application 
uidoc = uiapp.ActiveUIDocument

#######OK NOW YOU CAN CODE########

# The inputs to this node will be stored as a list in the IN variables.
ttb_d = IN[0]
nam_d = IN[1] if isinstance(IN[1], list) else [IN[1]]
num_d = IN[2] if isinstance(IN[2], list) else [IN[2]]
# Place your code below this line
sht_d = []
ttb_r = UnwrapElement(ttb_d).Id

TransactionManager.Instance.EnsureInTransaction(doc)

for na,nu in zip(nam_d, num_d):
    sht = ViewSheet.Create(doc, ttb_r)
    sht.Name = na
    sht.SheetNumber = nu
    sht_d.append(sht.ToDSType(False))

TransactionManager.Instance.TransactionTaskDone()
    

# Assign your output to the OUT variable.
OUT = sht_d
1 Like

@amralhmady331

import clr
import sys

sys.path.append("C:\Program Files (x86)\IronPython 2.7\Lib")

import System

from System import Array
from System.Collections.Generic import *

clr.AddReference("ProtoGeometry")
from Autodesk.DesignScript.Geometry import *

clr.AddReference("RevitNodes")

import Revit
clr.ImportExtensions(Revit.Elements)
clr.ImportExtensions(Revit.GeometryConversion)
clr.AddReference("RevitServices")

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

clr.AddReference("RevitAPIUI")

import Autodesk
from Autodesk.Revit.DB import *
from Autodesk.Revit.UI import *

doc = DocumentManager.Instance.CurrentDBDocument
uiapp = DocumentManager.Instance.CurrentUIApplication
app = uiapp.Application
uidoc = uiapp.ActiveUIDocument

#######OK NOW YOU CAN CODE########
#The inputs to this node will be stored as a list in the IN variables.

ttb_d = IN[0]

nam_d = IN[1] if isinstance(IN[1], list) else [IN[1]]
num_d = IN[2] if isinstance(IN[2], list) else [IN[2]]

#Place your code below this line

sht_d = []

ttb_r = UnwrapElement(ttb_d).Id

TransactionManager.Instance.EnsureInTransaction(doc)

for na,nu in zip(nam_d, num_d):
    sht = ViewSheet.Create(doc, ttb_r)
    sht.Name = na
    sht.SheetNumber = nu
    sht_d.append(sht.ToDSType(False))

TransactionManager.Instance.TransactionTaskDone()

#Assign your output to the OUT variable.

OUT = sht_d

post your code this way…

KR

Andreas

1 Like

Hi @amralhmady331, welcome
My understanding is that you are trying to create new sheets and your script it is overwriting existing sheets
You can add a check with the following code insert

TransactionManager.Instance.EnsureInTransaction(doc)

# Collect all current sheet numbers
collector = (
    FilteredElementCollector(doc)
    .OfClass(ViewSheet)
    .WhereElementIsNotElementType()
    .ToElements()
    )
    
sheetnumbers = set([viewsheet.SheetNumber for viewsheet in collector])

for na,nu in zip(nam_d, num_d):
    # Check if number exists
    if nu in sheetnumbers:
        continue
    sht = ViewSheet.Create(doc, ttb_r)
    sht.Name = na
    sht.SheetNumber = nu
    sht_d.append(sht.ToDSType(False))