PDF print node by Archi-Lab Ignores printer and print range

The PDF print node seems to ignore whatever printer and print range I push into the node, instead it uses the printer and print range selected in Revit. Does anyone have a solution?

Thanks in advance,
Tim

Hi @timhevel

Could you please show us your graph?

PRJ_PRINT_PDF_v1.4.dyn (67.6 KB)

btw I changed the python code inside the node after this post by @viktor_kuzev to enable multiple printsettings to be fed in.

Does anyone else have this problem?

I’m having the same issue.

Dynamo 1.2
Revit 2017
Archi-lab 2016.12.1

I actually had the problem before changing the code as well.

so you dont have the problem any more?

In other words; Is the code, aside from the ability to feed in multiple printsettings, also supposed to fix my issue?

btw. print range is a non issue, printer input is the only problem.

Well I didn’t have the problem with the printer selection, but it was always printing with whatever settings were set up in revit at the moment. I think I fixed it by setting the print settings in a different transaction.
What’s happens now when you’re using my version of the code?

The printsettings problem was solved a long time ago by using your code as stated before. I have sort off made a workaround by using a popup window to remind the users to change the printer to Bullzip, it works but it is not pretty.

also, after I tried to change the default printer in Windows, it automaticaly changed back after a reboot. I don’t know, it might have something to do with it.

I don’t have time to test it, but maybe you can try if this works:

#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
printManager.SelectNewPrintDriver(printerName)
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
6 Likes

which part did you add?

line 64

It worked!!! Thank you.

1 Like

hi all, i’m having the same problem, i’ve tried by copying the python code modified by @viktor_kuzev, but i’m not a pythonist :), so I can’t know if I did it right. Anyway, it could be a problem of my script…

Could you tell if you see something wrong at first sigth???

Thanks in advanceDYN_PRINT_PDF.dyn (29.0 KB)
PRINT_PDF_01

1 Like

From what I can see you’re using 2-dimensional lists of views and view settings which is something I haven’t done myself.
You can try using the levels of the inputs or flatten the lists before connecting them to the node.

Thanks @viktor_kuzev, I just flattened the lists and it worked !

@gregoriosaura @viktor_kuzev @timhevel

Hey All!!

@gregoriosaura I copied your dyn workflow and added the flatten nodes after the “views” and “printsettings” nodes but the pdfs are still being created at the same size (it seems to be a2 size for me - last printsetting in my list of printsetting inputs).

I have attached my .dyn file. Is there any chance one of you could take a quick look to see if there’s anything obviously wrong??

My “Print PDF” node has been updated (line 64)

I’m using Revit 2017.

I will be leaving the office now but any feedback would be very much appreciated!!

Kind Regards,
Jack.

P.s. @Alban_de_Chasteigner Have copied you in as amongst many of the threads regarding PDF workflows you also jumped out to me as someone with much more knowledge than myself so possible you’d also have an insight into this.

DYN_PRINT_PDF.dyn (23.0 KB)

Hi @luckysurfcs,

I don’t know what is the problem because you didn’t join your updated “Print PDF.dyf” node.
The solution of Viktor Kuzev should work.
I use another version of the Print PDF node. This version allows a list of printsettings and a list of filenames (filepaths).
You can find it in the package “Genius Loci” or you can copy the python script below.
The picture shows the inputs :

If I can give you an advice, you should pair the sheets, the titleblocks and the names of printsettings to find automatically the correct printsettings.

#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(filePath, list):
    s_length = len(sheets)
    fp_length = len(filePath)
    if len(sheets) == len(filePath):
        pass
    else:
        filePath = filePath * (s_length / fp_length)
        if len(filePath) == len(sheets):
            pass
        else:
            OUT = "Filepaths and Sheets weren't the same length"
            exit()

elif isinstance(filePath, str):
    filepath = [filepath] * len(sheets)

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
printManager.SelectNewPrintDriver(printerName)
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()
    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, fp in zip(viewSheets, printSetting, filePath):
                PrintView(doc, i, pRange, printerName, combined, fp, j)
        elif isinstance(viewSheets, list) and not isinstance(printSetting, list):
            for i, fp in zip(viewSheets, filePath):
                PrintView(doc, i, pRange, printerName, combined, fp, printSetting)
        elif not isinstance(viewSheets, list) and not isinstance(printSetting, list):
            PrintView(doc, viewSheets, pRange, printerName, combined, filePath[0], 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 is None:
    OUT = message
else:
    OUT = errorReport
1 Like

@Alban_de_Chasteigner

Hey, big thanks for your quick response!

Apologies, i thought the dynamo workflow file i sent contained the update from viktor to line 64 but it appears not. Either way, i’d done thorough testing using the updated node and had no luck.

However… i’ve downloaded the genius loci node and it seems to be working perfectly!!

See screenshot and attached .dyn file :blush:

I’ll use the .dyn attached as a basis to work it out how to automate the mapping process between sheets and print settings to avoid having to do it all through viewsets. I’m so glad the print pdf node works though. Have spent so much time using the archi-lab node and not much success!

Many thanks again!

Jack.

DYN_PRINT_PDF_UPDATED.dyn (24.5 KB)

Hi,

On the line “Local Printers Names” “Code Block” “PrintersName”
Code block erro:
“Warning: No item exists at the specified index address”
Capturar1