Each time I run the a code, see below, the ArcGIS window updates the results and the process is extremely slow. Is there a way to let python know that it doesnot have to update the results each time it has calculated something?


linklayer = "NewUSConnections"
nodelayer = "NCNodes"
AllLinkIDs = []
for row in arcpy.SearchCursor(linklayer):
for LinkIDs in AllLinkIDs:
    ExtractedNodeIDs = []
    query = """ "ID" = %d"""%LinkIDs
    arcpy.SelectLayerByAttribute_management(linklayer, "NEW_SELECTION", query) 
    arcpy.SelectLayerByLocation_management( nodelayer, "BOUNDARY_TOUCHES", linklayer , "", "NEW_SELECTION", "NOT_INVERT")

    for row in arcpy.SearchCursor(nodelayer):
        with arcpy.da.UpdateCursor(linklayer, ["A_NODE","B_NODE"] ) as cursor:
            for row in cursor:
            row[0] = ExtractedNodeIDs[0]
            row[1] = ExtractedNodeIDs[1]

PS: I can see the steps followed by ArcGIS.

Updating Results...
Adding Output to map...
Drawing Background...
  • 3
    I don't know of any way to do specifically what you are asking for, but assuming you are using ArcMap have you tried running it with the map redraw manually paused before running the code (View > Pause Drawing / or F9). I don't know if this will impact your script in any way, but it could be worth a try and if it doesn't impact the script running correctly, it should speed things up for you. – John Jan 11 '18 at 21:57
  • 1
    Code optimization generally requires far more information than you have provided (exact version of software, location of referenced feature classes, numbers of rows involved, indexes created on all tables, timing of various steps, etc.), and wouldn't be accomplished as you ask it (if you don't want an update performed, you shouldn't request it), but failure to use Data Access search cursor (arcpy.da.SearchCursor) is sufficiently egregious that you need to fix that first (then review the code logic, because there's some awful stuff there). You need more documentation as well. – Vince Jan 11 '18 at 22:03
  • 1
    This might help gis.stackexchange.com/questions/1644/… @John has the right idea, by pausing the drawing only the TOC is updated... of course you could run the script in ArcCatalog (or command line) as an alternative, that wouldn't update anything but you'd have to create your layers from feature classes or saved layer files. – Michael Stimson Jan 11 '18 at 22:03
  • @John pausing the display made it almost 7 times faster. Before it took almost 35 minutes vs now it takes 5 minutes. That's a lot. – pnkjmndhl Jan 11 '18 at 22:08
  • Since it worked, I added my original comment as an answer below in case it can help others with a similar issue. – John Jan 11 '18 at 23:05

From your question, what it sounds like is you are not having an issue with the time it takes the script to run, but rather with the time it takes ArcMap to re-draw the screen between each step of the script. To take care of this, the easiest thing you could do is pause the map re-drawing before running the script. To my knowledge there is no arcpy way to do this, so you will have to do it manually via the view menu (View > Pause Drawing) or by pressing "F9".

Depending on your specific needs, if you are looking for a programmatic way to speed the re-draw up (without having to manually press pause before), then you could always look at using arcpy to list the layers in the MXD and turn them off while the script is running, or probably even faster would be to put all of the layers into a group and simply have the script turn off the group before running and then turn it back on when you're done.

Finally though, as others have mentioned in the comments above, the run-time of a script have numerous factors and can not be completely fixed by one solution generally. For example, your code uses the .da.UpdateCursor but does not take advantage of the speed of the .da.SearchCursor. Reviewing your code step by step, possibly timing different steps (https://docs.python.org/2/library/timeit.html) and seeing which is slowing you down the most can help you ask more targeted questions about optimizing specific steps of your code as well.

PS: Regarding pausing the drawing or turning off layers in the table of contents, and older but still relevant related question How to disable and enable drawing in ArcMap using Python? has some interesting answers to it you may want to check out if you're looking for ways to automate this process rather than manually pausing.

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.