Archi-lab Batch Print Node Problem **Continued**

Hi All,

Following on from this post which was closed…

https://forum.dynamobim.com/t/archi-lab-batch-print-node-problem/6575/23

I am also trying to get Konrad’s print node to work automatically with different sheet sizes.

I have amended the Print PDF node and created a setup which gives no errors, but doesn’t make any PDFs either!

Would anyone be able to point out my (likely very obvious) mistake (making RunIt and CombinedFile True doesn’t help).

Thanks,

Mark


Print range should be set to “Select”

Thanks Victor, unfortunately it didn’t fix it…

I’m not completely certain here, but is it actually sheets that you are passing into the “View” input?
I’m still new in Dynamo, but isn’t it the Title blocks you’re passing and not the actual sheets?

Other than that Viktor is also right that it needs to be set to “Select”.

I’m glad you continued this thread, because that gives me the opportunity to tell, that I actually got my problem solved, and that I fixed the “null” error.

For me the problem was that I passed strings and not printer settings into the “print settings” input. Once I corrected that, it worked perfectly.
However it meant that I had to choose every available print setting with the “Print Settings” node, like your doing.
But after looking through the Python code to Print PDF and after a lot of googling I was able to write my very first Python script which retrieves all available print settings and outputs them as a list :slight_smile:
I’ll upload the code later, when I’m on a computer again…

Thanks Thomas,

I’m sure other people will know better than me if that is the problem… I have used it previously ok - the node gets the views from the view list and plugs them into the view input, so I think it should be ok?! Maybe not :slight_smile:

It would be very interesting to see your code and how it plugs in, thanks a lot.

Cheers,

Mark

Here’s the code for my Print Settings List node.

# Import Element wrapper extension methods

    import clr
    clr.AddReference("RevitNodes")

    import Revit
    clr.ImportExtensions(Revit.Elements)

    # Import DocumentManager and TransactionManager
    clr.AddReference("RevitServices")

    import RevitServices
    from RevitServices.Persistence import DocumentManager

    from RevitServices.Transactions import TransactionManager

    doc = DocumentManager.Instance.CurrentDBDocument


    # Import RevitAPI
    clr.AddReference("RevitAPI")

    import Autodesk
    from Autodesk.Revit.DB import *

    #The inputs to this node will be stored as a list in the IN variable.
    dataEnteringNode = IN

    # first collect all of the print settings in a project
    allPrintSettings = FilteredElementCollector(doc).OfClass(PrintSetting).ToElements()

    # add them to a list
    printSettings = []
  
  for i in allPrintSettings:
        printSettings.append(i)


    OUT = printSettings
1 Like

I’ve tried to make a screenshot of my thoughts, but I might be wrong, like I said before :slight_smile:

Of course the final input to “Views” should be filtered and not passed directly into, like I’m doing in the screenshot :slight_smile:

Thanks Thomas,

I tried a different input, but no success…

Heya,

i’ve been following the previous post -very useful so far-, but saw that that topic was closed so i created a new topic to also get the combined function fixed;

unfortunately i noticed too late that this topic was opened aswell.
thank you all for working to fix this node =)

i’ve got this set up to batchprint and it covers almost all my needs. The only problem is that the Combine-function doesn’t work. This is still something i’d really need to export my sheetsets. Is there anyone that got the Combine-function to work?

Hey All,

I have got the batch plot working, though yours is more elegant than mine! Could I ask about how you made your sheets [in] node?

Unfortunately combine is still broken…

Cheers,

Mark

Hey Mark,

The Sheets [in] is just a watch node. If you have a list of sheets you can put them in there.
At the company i work we use assemblies for prefabricated concrete elements. For batch printing sets of elements i filter all sheets on assembly code so i can print a complete set at once. Though i still need to have the combine function fixed. I’ve been fiddling with the code but so far no succes.

Ok. Try this. The combined option should work. Make sure that the file path is not pointing to an existing file because you’ll get an error. Also it won’t work for different page sizes.

#Copyright(c) 2015, Konrad K Sobon
# @arch_laboratory, http://archi-lab.net

import clr
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]
printSettings = 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)

if isinstance(printSettings, list):
	printSetting = []
	for i in printSettings:
		printSetting.append(UnwrapElement(i))
else:
	printSetting = UnwrapElement(printSettings)
	
TransactionManager.Instance.EnsureInTransaction(doc)
printManager = doc.PrintManager		
printSetup = printManager.PrintSetup
if isinstance(printSettings, list):
	printSetup.CurrentPrintSetting = printSetting[0]
else:
	printSetup.CurrentPrintSetting = printSetting
printManager.Apply()
TransactionManager.Instance.TransactionTaskDone()

def PrintView(doc, sheet, pRange, printerName, combined, filePath, printSetting):
	# create view set 
	viewSet = ViewSet()
	if isinstance(sheet, list):
		for s in sheet:
			viewSet.Insert(s)
	else:
		viewSet.Insert(sheet)
	# 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()
	# 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
	try:
		printSetup = printManager.PrintSetup
		printSetup.CurrentPrintSetting = printSetting
		printManager.Apply()
		
	except:
		pass
	# 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 = "Success"
	if runIt:
		if isinstance(viewSheets, list) and isinstance(printSetting, list):
			for i, j in zip(viewSheets, printSetting):
				PrintView(doc, i, pRange, printerName, combined, filePath, j)
		elif isinstance(viewSheets, list) and not isinstance(printSetting, list) and combined == True:
			PrintView(doc, viewSheets, pRange, printerName, combined, filePath, printSetting)
		elif isinstance(viewSheets, list) and not isinstance(printSetting, list):
			for i in viewSheets:
				PrintView(doc, i, pRange, printerName, combined, filePath, printSetting)
		elif not isinstance(viewSheets, list) and not isinstance(printSetting, list):
			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

Hey Viktor,

Thanks for your help, i’ve edited the Archi-lab script with your code. I’ve executed the code twice but both times my Revit Client crashed.

One important point though, you said it doesn’t work for different page sizes, but the whole point of this script is to batch print multi-size sheets into 1 file. Isn’t there any way to do this?

Best way for me:

I don’t think there is currently a way to combine different sized pages directly from revit.
Just use acrobat or something similar.
Then I guess there is a way to automate this too, but it is out of my knowledge.

Thanks Viktor,

I’ve got it to work. Though one question followed up on this:
I’ve given the output an automaticallly generated file path and file name, yet when i execute the program i still get this pop up on where i want to save my PDF print. Is there a way that it skips this pop up and just works with the given filepath/name?

Yes :slight_smile:

this reminded me of the days I was working for xerox tech support :smiley:

Thanks again,

So what is the purpose of the filepath parameter then if it doesn’t use it?

I actually just received a new problem. I’ve changed my program to run a print node per printsetting (in order of sheet size; A3, A2, A1). The first file is printed succesfully. the next print nodes give the following error:

“The Iterator cannot proceed due to changes made to the element table in Revit’s Database.”

I’ve found the problem in the code, highlighted in the picture:

The error occurs because the script deletes the temporary viewSettings, which makes a change to Revit’s Database.
What would be a good way to fix this?

New Question:
Is it possible to set this tempPrintSetting to print in Color?
On my pc the preferences are in color, yet it still prints in grey tones.

I’ve tried to get into PrintManager.PrintSetup.CurrentPrintSetting.PrintParameter.ColorDepth but no Succes there