Take the 2-minute tour ×
Geographic Information Systems Stack Exchange is a question and answer site for cartographers, geographers and GIS professionals. It's 100% free, no registration required.

The script that I'm writing repositions two data frames and sets their extents. When doing this, it redraws the entire Active View 4 times, slowing the script substantially. Pressing F9 or clicking the 'Pause Drawing' button before running the script disables the drawing and makes the script run much faster, but I want the script to do this automatically. I want to disable drawing at the beginning of the script, and enable it at the end. How do I do this?

share|improve this question

1 Answer 1

up vote 5 down vote accepted

I didn't see anything native in ArcPy. The easiest thing to do is probably send the F9 keystroke to the ArcMap window using the SendKeys module: http://www.rutherfurd.net/python/sendkeys/#dowloads

I tested with this syntax and it worked fine:

import SendKeys
# Send the keystroke for F9
SendKeys.SendKeys("{F9}")

The only caveat is that you may need to uncheck "Always run in foreground" on the General tab of the script properties. Otherwise the keystroke may get caught by the script progress window.

share|improve this answer
    
Thanks! I have one question though. Any computer on our network will need to be able to use this script. Is it possible to host the SendKeys module on our server so that we don't have to install it on every computer? I'm not familiar with adding new modules –  Tanner Sep 1 '10 at 23:37
1  
You can use PYTHONPATH to add to the default directories that Python looks in when importing modules. I've never used this so I can't offer any guidance. More info here: docs.python.org/tutorial/modules.html#the-module-search-path –  Evan Sep 3 '10 at 16:41
    
Thanks. SendKeys works when I turn off 'Always run in foreground' but the problem is, a script tool has to run in the foreground if you're using arcpy.mapping.MapDocument('Current') I wonder if there's a way to do it in ArcObjects? Then again, I have never used ArcObjects –  Tanner Sep 17 '10 at 15:42
    
You can change the tool itself to always run in foreground from the Script Tool properties dialog. –  Jason Scheirer Sep 17 '10 at 17:53

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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