POST
|
1. I'll look into it, but I suspect this is by design. 2. __file__ will work with script tools and validation scripts in ArcGIS 10.0 final. 3. Cleanup after running script tools can give unexpected results -- the Python interpreter caches imported modules in each process, so per-module locals can hang around (yielding your timeit issue). We've taken pains to minimize the effect and clean up where possible, but for all intents and purposes do not rely on any behavior that makes assumptions on the state of a local variable in a module, and make sure you always instantiate brand new objects per script tool (use timeit.Timer() instead, or use the starttime = time.time(); dostuff(); elapsed_time = time.time() - starttime idiom). 4. dir() will work with most objects now. A majority of arcpy is written in Python so that standard documentation tools like the help() builtin and pydoc will also correctly inspect and report on the objects. 5. It is a C++ Python library interfacing with COM natively, with coarse-grained Python objects built on top of it. It is indeed built on top of arcgisscripting. 6. Yes. There is even a degree of intelligence added so that GP messages will go to stdout/stderr when run out of process in a Python script. Running Python scripts with prints in the Python window will behave as expected. I recommend the Python logging API for anything particularly sophisticated. 7. They should, like any other exception.
... View more
04-07-2010
11:15 PM
|
0
|
0
|
116
|
POST
|
you might want to look into excluding the arcgisscripting.pyd module in your exe project, so it will find the correct one via PYTHONPATH: http://www.py2exe.org/index.cgi/ExcludingDlls
... View more
04-07-2010
04:56 PM
|
0
|
0
|
382
|
POST
|
Looks like it's giving you a list of tuples of unicodes instead of a list of unicodes. Try x = statusMsgList[0][0] instead, and if you REALLY need a Windows/Western European encoded string and not the unicode (ie you know you're only going to be dealing with American and/or Western European characters in your text), use x = statusMsgList[0][0].encode("cp1252", "replace")
... View more
04-04-2010
11:22 PM
|
0
|
0
|
410
|
POST
|
You can always use the templates in the system as a starting point as well. starting_point = arcpy.mapping.MapDocument(os.path.join(arcpy.GetInstallInfo()['InstallDir'], 'bin', 'Templates', 'LetterLandscape.mxt'))
... View more
03-31-2010
08:56 AM
|
1
|
0
|
2216
|
POST
|
Not so much a workaround as much as a conscious decision: the default legal-sized page layout with full-page map frames makes sense in a Desktop environment, but it is not the most appropriate layout or page size to be used across the board. The onus is on the author of the map scripts of the decision of map layout template to be used -- this may seem like an inconvenience on the surface, but we anticipate it will result in much higher quality maps in automation than if a default were forced on users as it integrates the design of the map document's layout into the thought process of providing map automation services to end users of the services.
... View more
03-30-2010
11:07 PM
|
0
|
0
|
2216
|
POST
|
The workflow for this is to use an already saved blank MXD on the filesystem, open it, and use MapDoc.saveAs to have a new, blank map document to work with.
... View more
03-27-2010
11:44 AM
|
0
|
0
|
2215
|
POST
|
Have you tried benchmarking your Python scripts against Python with psyco enabled? I wonder how much it would help, if the bottlenecks on the Python side can be significantly optimized away.
... View more
03-15-2010
03:26 PM
|
0
|
0
|
713
|
POST
|
The ArcGIS installer should have created a file called C:\Python26\Lib\site-packages\Desktop10.pth that adds the ArcGIS install to Python's path. You can manually recreate it. It's a text file with a list of paths on each line. You just need to open up notepad and enter the following: C:\Program Files (x86)\ArcGIS\Desktop9.4\bin C:\Program Files (x86)\ArcGIS\Desktop9.4\arcpy and save it as C:\Python26\Lib\site-packages\Desktop10.pth. Then you should be good to go.
... View more
03-04-2010
12:32 PM
|
0
|
0
|
541
|
POST
|
Are you sure you're running the IDLE from Python 2.6 and not Python 2.5? Try this in the interactive prompt in IDLE: >>> import sys >>> sys.version '2.6.2 (r262:71605, Apr 14 2009, 22:40:02) [MSC v.1500 32 bit (Intel)]' You should get something that looks like "2.6.~~~~~~~" Further troubleshooting (after issuing the first commands): >>> sys.path You should get back a list of directories. The directory for the arcgis desktop install should be there (something like C:\~~~~\ArcGIS\bin) -- if it's missing then Python's import path for ArcGIS has somehow been configured wrong.
... View more
03-03-2010
04:15 PM
|
0
|
0
|
541
|
POST
|
It's a private internal function used as an arcgisscripting/arcpy bridge. It is not recommended you use it.
... View more
02-17-2010
11:00 AM
|
0
|
0
|
796
|
POST
|
Looks like a double free on the COM object when ArcMap/Catalog closes down the Python interpreter for that process. Are there any known issues in COMTypes itself? Is there an explicit addref call you need to execute on the object when you start using it? We don't link against a debug build of Python in the ArcObjects stack, so I can't dig too much further into the Python to see what's going on here. Sorry.
... View more
02-12-2010
02:36 PM
|
0
|
0
|
311
|
POST
|
You'll want to put your import statements at the top level of your validator script and not in the __init__.
... View more
02-07-2010
08:04 AM
|
0
|
0
|
113
|
POST
|
I'm working on a longer-form version of this for a blog post, but here's the gist: The Map Document object lives in the arcpy.mapping module. To create a new Map Document object is easy, simply call arcpy.mapping.MapDocument with the path to the MXD you wish to use: mxd = arcpy.mapping.MapDocument('d:\\path\\to\\map.mxd') Something to note about python strings: backslashes need to be either escaped like 'd:\\path\\to\\map.mxd' or the string can be flagged as a raw string with the r flag like r'd:\\path\\to\\map.mxd'. In these examples Iâ??ll be using the Python window in ArcGIS Desktop. The Map document object also accepts the special path string â??currentâ?? in desktop only that lets you manipulate the current document in the window: mxd = arcpy.mapping.MapDocument('current') From here the interactive window is a great resource to learn and experiment. I can get an idea of what type of properties a map document has by typing in the name of my variable, hitting dot, and see what I have access to. This makes prototyping and exploring Python code easy, because of the immediate nature of the feedback given in the interactive window. I get a result as soon second I press enter, without needing to save or compile any code. Layers can be accessed from .lyr files or from the TOC in a Map document. To load from a layer file: lyr = arcpy.mapping.MapDocument('d:\\path\\to\\layer.lyr') Layers can be retrieved from a map document by using the arcpy.mapping.ListLayers function as well. In my interatice session I have a simple MXD with some OpenStreetMap data in it, and from the Python window I issue the ListLayers function and get: >>> arcpy.mapping.ListLayers(mxd) [<map group layer u'OpenStreetMap data'>, <map layer u'california_poi'>, <map layer u'california_highway'>, <map layer u'california_natural'>, <map layer u'states'>] Note this is different than the list of strings in functions such as ListDatasets, it is actual layer objects. If I just want a list of the names from these objects, I can employ a list comprehension: >>> [lyr.longName for lyr in arcpy.mapping.ListLayers(mxd)] [u'OpenStreetMap data', u'OpenStreetMap data\\california_poi', u'OpenStreetMap data\\california_highway', u'OpenStreetMap data\\california_natural', u'states'] List comprehensions are a shortcut built into Python for a common type of for loop where one loops over a list of values to produce a new list of values. In this case, weâ??re grabbing the longName attribute from each value in the list returned from ListLayers. The general formula for a list comprehension is: Simple: [expression for value in list] With conditional: [expression for value in list if condition] The if condition form allows one to not only map values, but also apply a conditional filter and only include certain values in the new list. For examples, I only want all the layer names that are feature layers: >>> [lyr.longName for lyr in arcpy.mapping.ListLayers(mxd) if lyr.isFeatureLayer] [u'OpenStreetMap data\\california_poi', u'OpenStreetMap data\\california_highway', u'OpenStreetMap data\\california_natural', u'states'] Note the group layer named OpenStreetMap data is no longer included in the results. This also makes it possible to fetch a layer by a specific name and only work with it: >>> lyrlist = [lyr for lyr in arcpy.mapping.ListLayers(mxd) if lyr.name == "california_highway"] >>> lyrlist [<map layer u'california_highway'>] >>> if lyrlist: ... lyr = lyrlist.pop() # pop takes one element out of end of the list and returns it ... >>> lyr <map layer u'california_highway'> >>> lyr.name u'california_highway' >>> lyr.dataSource u'C:\\DATA\\openstreetmap.gdb\\california_highway' >>> lyr.transparency 0 >>> lyr.transparency = 10 Many common scenarios for finding and manipulating layers can be accomplished using the built-in functions in arcpy.mapping and a little bit of manipulation with a list comprehension.
... View more
01-16-2010
01:54 PM
|
0
|
0
|
259
|
Title | Kudos | Posted |
---|---|---|
1 | 09-26-2012 02:46 AM | |
1 | 08-13-2014 11:55 AM | |
1 | 10-29-2014 09:40 AM | |
1 | 03-25-2014 12:18 PM | |
1 | 06-08-2012 01:38 PM |
Online Status |
Offline
|
Date Last Visited |
11-11-2020
02:22 AM
|