1

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)

ArcMessage

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.
enter image description here


Updated 3

When I try the newest code with the AddMessage and put my printing code below it the results say this.

enter image description here

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.
2

To loop over each value, do something like this:

for mxd in parameters[0].values:
    arcpy.AddMessage("Processing MXD: {}".format(mxd))
    # Do something interesting here
  • I have my input for the InputMXD as DEMapDocument. Would I still need to add the (".MXD")? – MjonesGEO Feb 6 '14 at 19:18
  • Misread your question. Editing answer. – Jason Scheirer Feb 6 '14 at 19:20
  • This seems to be working, but I'm having an issue with an invalid MXD file name. – MjonesGEO Feb 6 '14 at 20:09
  • Looks like when I run it now it will just give me a C inside of the loop (im guessing from the Cdrive). Do I want it to display the parameters[0].values or parameters[0].valueAsText? – MjonesGEO Feb 6 '14 at 20:27
  • If you use parameters[0].valueAsText, do for mxd in parameters[0].valueAsText.split(';'). – Jason Scheirer Feb 6 '14 at 20:32

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.