Here's the code for the third parameter that list the local printers:
# Third Parameter
printer = arcpy.Parameter(
displayName="Select a Printer",
name="printer",
datatype="String",
parameterType="Required",
direction="Input")
# Set a value list for the available local printers
printer.filter.type = "ValueList"
printer.filter.list = arcpy.mapping.ListPrinterNames()
This works and lists all of my local printers. The problem is it can't print the looped MXDs. It looks like python can't find them in the loop according to my arcpy.AddMessage(). Here's the code:
# Get inputs
InputMXD = parameters[0].valueAsText
PDF_Folder = parameters[1].valueAsText
printer = parameters[2].valueAsText
# Set workspace as defined by user
#env.workspace = PDF_Folder
arcpy.env.workspace = r"c:/temp"
#List Names for Inputs
arcpy.AddMessage("PDF_Output: "+PDF_Folder)
arcpy.AddMessage("Printer Name: "+printer)
arcpy.AddMessage("MXDs before Loop: "+InputMXD)
MXDList = arcpy.ListFiles(InputMXD)
arcpy.AddMessage("After MXDList")
arcpy.AddMessage(MXDList)
for MXDPath in MXDList:
arcpy.AddMessage("MXD Path: " + MXDPath)
MXD = arcpy.mapping.MapDocument(MXDPath)
arcpy.AddMessage("MXD: " + MXD)
arcpy.mapping.PrintMap(MXD, printer)
It's showing the mxds before the loop, but it isn't printing them once the loop hits. Any ideas? It's showing "[]" when it should be showing what's in the "MXDList".
Update 2
When I use this:
MXDList = glob.glob(os.path.join(InputMXD, '*.mxd'))
I got the same result as the image above. It's still not running through the loop. Here is my parameter setup for the InputMXD.
# First parameter
InputMXD = arcpy.Parameter(
displayName="Input MXDs",
name="InputMXD",
datatype="DEMapDocument",
parameterType="Required",
direction="Input",
multiValue=True)
When I use this code with workspace set to my InputMXD:
MXDList = arcpy.ListFiles("*.mxd")
I get this result. It doesn't want to list my MXDList.
Updated 3
When I try the newest code with the AddMessage and put my printing code below it the results say this.
Traceback (most recent call last): File "", line 104, in execute File "c:\program files (x86)\arcgis\desktop10.1\arcpy\arcpy\arcobjects\mixins.py", line 609, in __init__ assert (os.path.isfile(mxd) or (mxd.lower() == "current")), gp.getIDMessage(89004, "Invalid MXD filename") AssertionError: Invalid MXD filename.