Blank PNG export

4701
10
Jump to solution
05-04-2015 05:41 PM
KendrickSchuett
New Contributor II

I had a successful script that was working great. I did some rearranging and polish on the map now I get no layers on my PNG except PNG. The Base Layer is there the text boxes update just fine. So I stopped the loop and the export and just ran it to the save and the map is updated just fine and when I open it in Arcmap everything is updated correctly. its only when i got to export via Python I get just a base layer, text boxes and pictures no layers. Has anyone ran into something similar or have any insight.

for step in hourdriver:
    for lyr2 in arcpy.mapping.ListLayers(mxd,"CR"):
        lyr2.definitionQuery = coronerquery+"".join(str(step))
        print lyr2.definitionQuery # added for diag
    for lyr in arcpy.mapping.ListLayers(mxd,"TA"):
        lyr.definitionQuery = trafficquery+"".join(str(step))
        print lyr.definitionQuery # added for diag
    for elm in arcpy.mapping.ListLayoutElements(mxd, "TEXT_ELEMENT"):
        if elm.name == "TIME_DESC":
            print "Found it"
            elm.text = timelist[step]
            print elm.text
    filename = outputfolder+"".join(str(step))+""".png""" 
    print filename
    mxd.save()
    arcpy.mapping.ExportToPNG(mxd,filename)

Lyr and Lyr2 both update on the map and save but but do not show up in the PNG....

As i write this i was thinking that both layers are coming from the same SQL server could there be a hang up there?

Thank you in advance for your time.

0 Kudos
1 Solution

Accepted Solutions
DanPatterson_Retired
MVP Emeritus

did, or can you try it local?

View solution in original post

0 Kudos
10 Replies
DanPatterson_Retired
MVP Emeritus

did, or can you try it local?

0 Kudos
KendrickSchuett
New Contributor II

I ran the Py in Arcmap and it worked like a charm. Is my Arcpy module corrupted?

0 Kudos
DanPatterson_Retired
MVP Emeritus

outside of arcmap... you have to import arcpy explicitly ie

import arcpy

# more script

0 Kudos
KendrickSchuett
New Contributor II

Sorry, I should have included my entire PY, I had arcpy in there and

Sorry i Don't know how to to add code brackets in replies like in the original question.

<python>

# This Project was developed as a tool to create 24 traffic accident maps for the lights for lives video completed Weekly

#Import Modules

from datetime import *; from dateutil.relativedelta import*

import arcpy, os, moviepy.editor as mpy

import numpy

# Set Variables

mxdpath = r'MXD Location' # This is the path of the map that is the base for this Script

outputfolder = r"Output folder"+"".join(str(date.today()))+"\\" # This is the Output folder

hourdriver = range(1) # This Project creates 24 maps

trafficquery = "nature LIKE 'TA%' AND CallDate > GETDATE() - 90 AND Datepart(hh, CallDate) = "  #This sets the Query for the Traffic Accident(TA) Layer in the map

coronerquery = "nature = 'ZZ - CORACCIDEN ' AND factor = 'CLASS OF DEATH  ' AND method = 'MOTOR VEH CRASH      ' AND Year (Occured ) = 2015 AND Datepart(hh, Occured ) = " #This Sets the Query for the Coroner Map(CR) layer in the map

timelist = ["12:00am - 01:00am","01:00am - 02:00am","02:00am - 03:00am","03:00am - 04:00am","04:00am - 05:00am",\

            "05:00am - 06:00am","06:00am - 07:00am","07:00am - 08:00am","08:00am - 09:00am","09:00am - 10:00am",\

            "10:00am - 11:00am","11:00am - 12:00pm","12:00pm - 01:00pm","01:00pm - 02:00pm","02:00pm - 03:00pm",\

            "03:00pm - 04:00pm","04:00pm - 05:00pm","05:00pm - 06:00pm","06:00pm - 07:00pm","07:00pm - 08:00pm",\

            "08:00pm - 09:00pm","09:00pm - 10:00pm","10:00pm - 11:00pm","11:00pm - 12:00am"]

# Check for an output folder and complete

if not os.path.exists(outputfolder):

    os.makedirs(outputfolder)

else:

    exit("Folder already exists")

   

mxd = arcpy.mapping.MapDocument(mxdpath)

# loop through hours for each layer and export to .png

for step in hourdriver:

    for lyr2 in arcpy.mapping.ListLayers(mxd,"CR"):

        lyr2.definitionQuery = coronerquery+"".join(str(step))

        print lyr2.definitionQuery # added for diag

    for lyr in arcpy.mapping.ListLayers(mxd,"TA"):

        lyr.definitionQuery = trafficquery+"".join(str(step))

        print lyr.definitionQuery # added for diag

    for elm in arcpy.mapping.ListLayoutElements(mxd, "TEXT_ELEMENT"):

        if elm.name == "TIME_DESC":

            print "Found it"

            elm.text = timelist[step]

            print elm.text

    filename = outputfolder+"".join(str(step))+""".png"""

    print filename

    mxd.save()

    arcpy.mapping.ExportToPNG(mxd,filename)

print "Done with Maps"

</python>

Thank you for your help

0 Kudos
DanPatterson_Retired
MVP Emeritus

yes...to edit code blocks and format them, you have to do so within the actual original post not from within the 'mailbox' which I think you did.  There is a request to add the advanced editor in both places

I can't figure out specifically, but I did notice your export to png is...to say... a bit minimalist.  Perhaps you need to be more specific as to whether you want to export just the default page layout or the dataframe, which you need to specify explicitly.

In any event, you can edit your code by going to the original post, simply by clicking on its title in your inbox and edit from there.

KendrickSchuett
New Contributor II

Ah ok thanks for the insight.

OK i will try that thanks for the time and linking the resources for me, i appreciate the help very much.

0 Kudos
KendrickSchuett
New Contributor II

Ok I figured out it has to do with the SDE I am using for the data connection. If i run Layer.isBroken outside of arc-map or arc-catalog it returns that my layers are broken. If i run it in arc-map or arc-catalog it runs fine. after doing some searching i couldn't find a way to repair an SDE. I found ways to replace, even build one, neither worked however. I even tried some different log in credentials. What kills me was it worked great last week but now it won't... I am waiting on my GIS department but I think i am going to try uninstalling and re installing arcmap to see if something can be fixed.

This guy had the same question I think How to refresh SDE connection from arcpy? and no one knew so I think its worth the re install since i have spent two days on this and am falling behind on other projects.

Please let me know if anyone has any insight or maybe a way to refresh/repair an SDE from outside Arcmap.

0 Kudos
KendrickSchuett
New Contributor II

I had my IT do a clean uninstall and a re-install and my pythons are back online. I think what happened is that I was playing with Anaconda and noticed my Numpy in arcpy was 1.6.1 and so I removed it and added Numpy 1.9.2. This is the only change i can think of I made to the Arcpy LIB. I just didn't notice because i was working on a different script. I think I will still be able to play with anaconda but i am not planning to touch the Arcpy LIB again. three days down the tube but still worth it to save the time with the scripts.

Thanks again Dan for your time and help on this. Hopefully it will help the next guy touching things they shouldn't.

0 Kudos
DanPatterson_Retired
MVP Emeritus

Thanks for the tip...I have been looking Anaconda for some other work...maybe on a different machine until I can investigate this more.

0 Kudos