The goal is to change the order of sheets sent into printManager.CombinedFile = true
The idea was to alter the viewSet, but is this possible?
The following code was kindly provided by @SeanP
viewSet = ViewSet()
for i in range(len(viewSheets)):
viewSet.Insert(viewSheets[i])
This is an attempt to rearrange the sheets in the ViewSet, but it returns “null” when I run it.
My question for this post, is this approach possible? If not, can we avoid the ViewSet and submit sheets to the printManager.CombinedFile (as a re-ordered group, not individual sheets)?
Thanks for you help!
Can you provide us with the whole script / graph?
But my guess would be:
Yes, it is possible but you need something to sort for.
As I see it, you are just taking a sheet and adding it to the viewSet - no sorting at all.
Here’s the code and graph. Thanks!
Not sure if sorting happens in the script, but the graph shows sorting of sheets from the Drawing Index (Schedule).
#Copyright(c) 2015, Konrad K Sobon
# @arch_laboratory, http://archi-lab.net
import clr
import msvcrt
clr.AddReference("RevitAPIUI")
from Autodesk.Revit.UI import *
clr.AddReference('ProtoGeometry')
from Autodesk.DesignScript.Geometry import *
# Import Element wrapper extension methods
clr.AddReference("RevitNodes")
import Revit
clr.ImportExtensions(Revit.Elements)
# Import geometry conversion extension methods
clr.ImportExtensions(Revit.GeometryConversion)
# Import DocumentManager and TransactionManager
clr.AddReference("RevitServices")
import RevitServices
from RevitServices.Persistence import DocumentManager
from RevitServices.Transactions import TransactionManager
doc = DocumentManager.Instance.CurrentDBDocument
uiapp = DocumentManager.Instance.CurrentUIApplication
app = uiapp.Application
# Import RevitAPI
clr.AddReference("RevitAPI")
import Autodesk
from Autodesk.Revit.DB import *
import sys
pyt_path = r'C:\Program Files (x86)\IronPython 2.7\Lib'
sys.path.append(pyt_path)
import System
#The inputs to this node will be stored as a list in the IN variable.
dataEnteringNode = IN
sheets = IN[0]
pRange = System.Enum.Parse(Autodesk.Revit.DB.PrintRange, IN[1])
combined = IN[2]
printerName = IN[3]
printSetting = IN[4]
filePath = IN[5]
runIt = IN[6]
if isinstance(sheets, list):
viewSheets = []
for i in sheets:
viewSheets.append(UnwrapElement(i))
else:
viewSheets = UnwrapElement(sheets)
def PrintView(doc, sheet, pRange, printerName, combined, filePath, printSetting):
# create view set
viewSet = ViewSet()
#viewSet.Insert(sheet)
#for i in viewSheets:
#viewSet.Insert(i)
for i in range(len(viewSheets)):
viewSet.Insert(viewSheet[i])
# determine print range
printManager = doc.PrintManager
printManager.PrintRange = pRange
printManager.Apply()
# make new view set current
viewSheetSetting = printManager.ViewSheetSetting
viewSheetSetting.CurrentViewSheetSet.Views = viewSet
# set printer
printManager.SelectNewPrintDriver(printerName)
printManager.Apply()
TransactionManager.Instance.EnsureInTransaction(doc)
printManager.CombinedFile = True
printManager.Apply()
printManager.PrintToFile = True
printManager.Apply()
TransactionManager.Instance.TransactionTaskDone()
# set combined and print to file
#if printManager.IsVirtual:
# printManager.CombinedFile = combined
# printManager.Apply()
# printManager.PrintToFile = True
# printManager.Apply()
#else:
# printManager.CombinedFile = combined
# printManager.Apply()
# printManager.PrintToFile = False
# printManager.Apply()
# set file path
printManager.PrintToFileName = filePath
printManager.Apply()
# apply print setting
TransactionManager.Instance.EnsureInTransaction(doc)
printSetup = printManager.PrintSetup
printSetup.CurrentPrintSetting = UnwrapElement(printSetting)
printManager.Apply()
TransactionManager.Instance.TransactionTaskDone()
# save settings and submit print
TransactionManager.Instance.EnsureInTransaction(doc)
viewSheetSetting.SaveAs("tempSetName")
printManager.Apply()
printManager.SubmitPrint()
viewSheetSetting.Delete()
TransactionManager.Instance.TransactionTaskDone()
return True
try:
viewSets = FilteredElementCollector(doc).OfClass(ViewSheetSet)
for i in viewSets:
if i.Name == "tempSetName":
TransactionManager.Instance.EnsureInTransaction(doc)
doc.Delete(i.Id)
TransactionManager.Instance.ForceCloseTransaction()
else:
continue
errorReport = None
message = True
if runIt:
PrintView(doc, viewSheets, pRange, printerName, combined, filePath, printSetting)
else:
message = "Set RunIt to True"
except:
# if error accurs anywhere in the process catch it
import traceback
errorReport = traceback.format_exc()
#Assign your output to the OUT variable
if errorReport == None:
OUT = message
else:
OUT = errorReport
I think you sort it in your schedules.
Try another sorting, like descending, and then run the script again and see if that gave you another result.
@CVestesen I attempted various sorting methods with Dynamo nodes, but the result is always the same. The ViewSet does not change order. (As reminder, my goal is feed a ViewSet into the printManager.CombineFile = true so that the whole set is combined at once. But, I need to change the order of sheets in the ViewSet due to non-alphanumeric order.)
I don’t know python, but I think if there’s any hope of changing the ViewSet sheet order, perhaps ForwardIterator, MoveNext might be useful?
If someone could write a few lines to prove it is possible to sort sheets within a ViewSet (ie, if a single sheet could be moved, that would suffice for me at this point).
Thanks for your help!
Here’s a possible answer to my original question…
The pyRevit “Print Ordered Sheet Index” cheats by using Unicode characters in front of sheet numbers. The script places a certain number of “invisible” characters in front of the sheet number, to be able to print in the right order. (There was one report of a bug that failed to delete the Unicode characters after it printed.)
Since the pyRevit programmer resorted to this tactic of stealthily renaming sheet numbers, I’m guessing this means it is impossible to change the order within a ViewSet?
Hello
by definition a Set is an unordered collection
1 Like