TypeError: expected IPrintSetting, got UnknownElement

revit
archi-lab
dynamo

#1

I’m trying to set up fully automatic PDF Printing via dynamo and have come across the Arch-lab node set which makes this step 100x easier. However the problem I’m coming across is this extract of code around line 83.

# apply print setting
try:
	printSetup = printManager.PrintSetup
	printSetup.CurrentPrintSetting = printSetting
	printManager.Apply()
	
except:
	pass

There is a try clause around the printSetup code which takes in the Print Settings you feed in. When I remove the try clause the node no longer executes stating:

“TypeError: expected IPrintSetting, got UnknownElement”


Currently I’m feeding in either from the Archi-lab dropdown PrintSettings node or I’m feeding in ‘CurrentPrintSetting’ directly through a python node as seen below. (Output myIPS)

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

PrintSetup = doc.PrintManager.PrintSetup
IPrintSetting = PrintSetup.CurrentPrintSetting
PrintParameters = IPrintSetting.PrintParameters

myPS = doc.PrintManager.PrintSetup
myIPS = myPS.CurrentPrintSetting
myPP = myIPS.PrintParameters
myPSize = myPP.PaperSize
myPSource = myPP.PaperSource

#Assign your output to the OUT variable.
OUT = [myPS, myIPS, myPP, myPSize, myPSource]

I can’t in any way seem to find documentation or something to plug into this PDFing node which it will understand as an ‘IPrintSetting’. Which explains why the node always prints at the last used (i.e. current) print setting and will not take in a new one.


#2

Hey @callum.sykes,
I’m struggeling with the exact same issue and are wondering, did you find a workaround to this problem?

For instance, is there anyway to convert the “PrintSetting” to “IPrintSetting” or similar? Seems the printSetup.CurrentPrintSetting still won’t take a “PrintSetting” type…

Thanks a bunch!

/R


#3

Hi Rob, it was a while since I last wrote this but I have it all figured out and I’ll just throw code your way until we can get your stuff working.

I wrote/stole my own little node to just spit out ALL the printer settings and then I give users a UI Dropdown so they can choose some stuff and then it’s all gravy. The results of this are IPrintSettings and I feed them directly into the ArchiLab Printing Node.

import clr

clr.AddReference("RevitServices")
import RevitServices
from RevitServices.Persistence import DocumentManager

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

doc = DocumentManager.Instance.CurrentDBDocument

ps = FilteredElementCollector(doc).OfClass(PrintSetting)

OUT = [i for i in ps]

Please let me know how you get on with this


#4

Hello.

I am new to this forum and also relatively new to Dynamo/RevitAPI.
However I tried using the same node and had the same error and I was able to solve it, I think.

callum.sykes, the code that you posted generates the same unknown type of elements, so it does not work for me.

I basically unwrapped the printSetting in the Print PDF node (python script) the same way as the list of sheets are unwrapped) and also added the transaction to the applying of printSettings.


#5

Hello Stojan,

You are most undoubtedly right. It’s been a long time since I’ve posted this error. But it’s definitely due to the PrintSetting not being Unwrapped for use in the Revit API.

I’ve since learnt that it’s necessary to unwrap elements you pass from dynamo into a python node when performing complex actions. This is because you’re accessing the Revit API now and not Dynamo. (You don’t have to unwrap the elements for basic actions however.) Maybe time for some examples.

Python node with unwrapped (Dynamo) Elements

rms = IN[0] # a list of rooms
dln = []
for r in rms:
	dln.append(r.Name)
OUT = dln

Python node with unwrapped (Revit) Elements

rms = UnwrapElement(IN[0]) # a list of unwrapped rooms
dln = []
for r in rms:
	dln.append(r.get_Parameter(BuiltInParameter.ROOM_NAME).AsString())
OUT = dln