Rename a viewsheet set

Hi all,

I am trying to rename the print set though dynamo and I came across that the API allows it. Can someone please guide me how to do it?

I have 50 print sets (sheet sets) and I want to rename it without losing the filter for browser organisation.
The way I was doing it before was creating a new one and adding the existing sheets into it with a new name but I kept loosing the browser org filter.
Can some please assist.

Thank you so much

I believe you need to get the Print Manager class to focus on it first, which I’m fairly sure this code can do if doc is current document, you have dependencies available and you have your sheet set as an object:

printMan = doc.PrintManager
viewSS   = printMan.ViewSheetSetting
viewSS.CurrentViewSheetSet = yourSheetSet
viewSS.Rename("New name")

Thanks Gavin for the response,

I tried your way

Blockquote

import sys
import clr
clr.AddReference(‘ProtoGeometry’)
from Autodesk.DesignScript.Geometry import *

clr.AddReference(“RevitAPI”)
from Autodesk.Revit.DB import *

clr.AddReference(“RevitServices”)
import RevitServices
from RevitServices.Persistence import DocumentManager

doc = DocumentManager.Instance.CurrentDBDocument

view_sheet_sets = IN[0]

New_name = IN[1]

for view_sheet_set in view_sheet_sets:
print_manager = doc.PrintManager
viewSS = print_manager.ViewSheetSetting
viewSS.CurrentViewSheetSet = view_sheet_set
viewSS.Rename(“New_name”)

OUT = success

Blockquote

but it showed me an error,

Am I missing anything?

Thanks

I have a fixed a couple of things which might have caused an issue, here is the code but I got a different error this time.

Blockquote

import sys
import clr
clr.AddReference(‘ProtoGeometry’)
from Autodesk.DesignScript.Geometry import *

clr.AddReference(“RevitAPI”)
from Autodesk.Revit.DB import *

clr.AddReference(“RevitServices”)
import RevitServices
from RevitServices.Persistence import DocumentManager

doc = DocumentManager.Instance.CurrentDBDocument

viewSS = IN[0]

New_name = IN[1]

for view_set in viewSS:
print_manager = doc.PrintManager
view_sheet_setting = print_manager.ViewSheetSetting
view_sheet_setting.CurrentViewSheetSet = view_set
view_sheet_setting.Rename(New_name)

OUT = “View sheet set(s) renamed successfully.”

Blockquote

I think I fixed it, maybe if someone can share a better way to do it.
Thanks

Blockquote

import sys
import clr
clr.AddReference(‘ProtoGeometry’)
from Autodesk.DesignScript.Geometry import *

clr.AddReference(“RevitAPI”)
from Autodesk.Revit.DB import *

clr.AddReference(“RevitServices”)
import RevitServices
from RevitServices.Persistence import DocumentManager

from RevitServices.Transactions import TransactionManager

doc = DocumentManager.Instance.CurrentDBDocument

view_sheet_set_ids = IN[0]
new_name = IN[1]

Start a new transaction

TransactionManager.Instance.EnsureInTransaction(doc)

for view_sheet_set_id in view_sheet_set_ids:
view_sheet_set = doc.GetElement(ElementId(view_sheet_set_id))
print_manager = doc.PrintManager
view_sheet_setting = print_manager.ViewSheetSetting
view_sheet_setting.CurrentViewSheetSet = view_sheet_set
view_sheet_setting.Rename(new_name)

Commit the transaction

TransactionManager.Instance.TransactionTaskDone()

OUT = “View sheet set(s) renamed successfully.”

Blockquote

I’ve tidied up a slightly different take here which can handle list of sheet sets + list of new names, and also accounts for skipping duplicate names and can handle change of case scenarios:

# Boilerplate text
import clr

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")
import Autodesk 
from Autodesk.Revit.DB import *

# Current doc/app/ui
doc = DocumentManager.Instance.CurrentDBDocument

# Define list/unwrap list functions
def tolist(input):
    result = input if isinstance(input, list) else [input]
    return result

def uwlist(input):
    result = input if isinstance(input, list) else [input]
    return UnwrapElement(result)

# Preparing input from dynamo to revit
sheetSets = uwlist(IN[0])
newNames  = tolist(IN[1])

# Get names of viewsheetsets
allSheetSets = FilteredElementCollector(doc).OfClass(ViewSheetSet).ToElements()
allSetNames  = [ss.Name for ss in allSheetSets]

# Do some action in a Transaction
TransactionManager.Instance.EnsureInTransaction(doc)

# Get the print manager and sheet settings
printman = doc.PrintManager
printman.PrintRange = PrintRange.Select
settings = printman.ViewSheetSetting

results = []

# For each set and name
for ss,nn in zip(sheetSets,newNames):
	# Make sure it isn't reserved
	if nn not in allSetNames:
		settings.CurrentViewSheetSet = ss
		# Temporary rename in case it is same but different case
		tempName = "TEMP_" + nn
		settings.Rename(tempName)
		# Actual rename
		settings.Rename(nn)
		results.append(True)
	else:
		results.append(False)

TransactionManager.Instance.TransactionTaskDone()

# Preparing output to Dynamo
OUT = results
1 Like

Ah that’s great.
Thanks Gavin :slight_smile:

1 Like