PDA

View Full Version : OLE Automation with Python



rbeson
01-10-2011, 04:45 AM
Hi Steve et al.,

I want to print quite a few PDFs and am rewriting a vb script from Sanghoon Yoon (http://sac3.blogspot.com/2009/02/rhinoscript-print-layout-pages-as-pdf.html) in Python.

However, I can't seem to set the printerName property - which then throws the following error:
Exception: The PrinterName property must be set before calling the GetSettingsFilePath method.

Would anyone know how to set the printerName property? Full code below:


import System
t = System.Type.GetTypeFromProgID("Bullzip.PdfSettings")
printer = System.Activator.CreateInstance(t)

# Configure the PDF print job
printer.SetValue ("mergefile","t")
printer.SetValue ("mergeposition","bottom")
printer.SetValue ("Output", "test")
printer.SetValue ("ConfirmOverwrite", "no")
printer.SetValue ("ShowSaveAS", "never")
printer.SetValue ("ShowSettings", "never")
printer.SetValue ("ShowPDF", "no")
printer.SetValue ("RememberLastFileName", "no")
printer.SetValue ("RememberLastFolderName", "no")
printer.WriteSettings (True)

rs.Command("-_Print go", False)


Here is the vsScript if it helps:


Function BatchPrint(strFile,strM)
Const PDF_PRINTERNAME = "Bullzip PDF Printer"
Const PRINTER_PROGID = "Bullzip.PDFPrinterSettings"
Dim prtidx, obj
'Configure the PDF print job
Set obj = CreateObject(PRINTER_PROGID)
obj.SetValue "mergefile",strM
obj.SetValue "mergeposition","bottom"
obj.SetValue "Output", strFile
obj.SetValue "ConfirmOverwrite", "no"
obj.SetValue "ShowSaveAS", "never"
obj.SetValue "ShowSettings", "never"
obj.SetValue "ShowPDF", "no"
obj.SetValue "RememberLastFileName", "no"
obj.SetValue "RememberLastFolderName", "no"
obj.WriteSettings True

Rhino.Command "-print go ",False

'Wait for runonce settings file to disappear
Dim runonce, fso
runonce = obj.GetSettingsFileName(True)
Set fso = CreateObject("Scripting.FileSystemObject")
While fso.FileExists(runonce)=True
Sleep 100
Wend
End Function


Also, strangely enough - the vbscript works in V4, but not in V5 - but that's off-topic.

Thanks,
Rob

Steve Baer
01-12-2011, 04:17 PM
Hi Rob,
I don't know why bullzip is not working in V5 yet, but I just wanted to make a note that I am working on scripting of the print command and SaveAs PDF feature this week. I should be able to get you something that allows you to create a big merged pdf next week.
Thanks,
-Steve

rbeson
01-12-2011, 07:58 PM
Thanks Steve - that will be fantastic.

This seemed to work in the meantime:


t = System.Type.GetTypeFromProgID("Bullzip.PdfSettings")
printer = System.Activator.CreateInstance(t)
printer.PrinterName="Bullzip PDF Printer"
printer.Init
printer.LoadSettings

....

rs.Command("-_Print go", False)
time.sleep(1)