Announcements
Attention for Customers without Multi-Factor Authentication or Single Sign-On - OTP Verification rolls out April 2025. Read all about it here.

PrintDriver and PrintRange are overidden by Revit

TimHevel
Contributor

PrintDriver and PrintRange are overidden by Revit

TimHevel
Contributor
Contributor

Hello,

 

I'm currently trying to adapt @sobon.konrad PDF Print dynamo node to fit the needs of the firm I work for.

I have already managed to adapt it so that I can feed in a list of printsettings (with code provided by Viktor Kuzev of the DynamoBIM forum)

But I have ran into a problem. The code seems to ignore the printdriver and the printrange I feed in. Instead it uses the printdriver and print range secified in Revit. At least it seems like it compares the setup in the script to the printsetup in Revit, and when it doesn't match it won't run.

 

when I specify the right setup in Revit it runs fine. (in my case: "Bullzip PDF Printer" and Select) 

Since I'm trying to implement it in the firm I work for, I want it to work without having to rely on everyone in the firm remembering to change the setup before they print.

 

I hope anyone can help me,

 

Tim Hevel

 

#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()
	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):
			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

 

0 Likes
Reply
883 Views
2 Replies
Replies (2)

jeremytammik
Autodesk
Autodesk

Dear Tim,

 

Thank you for your query.

 

Have you read this thread by Konrad Sobon himself, discovering that a similar problem that arose in his use case was due to the printer driver?

 

https://forums.autodesk.com/t5/revit-api-forum/printing-api-and-printmanager-printtofilename-setting...

 

If so, and the problem persists, have you tried contacting Konrad directly to find out how he handles this?

 

After all, he has left his contact details in the code, so I would assume he might be willing to help.

 

Best regards,

 

Jeremy



Jeremy Tammik
Developer Technical Services
Autodesk Developer Network, ADN Open
The Building Coder

0 Likes

TimHevel
Contributor
Contributor

Yes is have read that post,

it is a different problem but it might have the same cause.

 

I haven't contacted him yet, but by tagging him I hoped that he would see the post.

0 Likes