POST
|
I'm trying to create a button that runs a python script. I've been following the help and have reached the point where I test an add-in: http://resources.arcgis.com/en/help/main/10.1/index.html#/Testing_an_add_in/014p00000026000000/ I run the script makeaddin.py as stated in step 1 and get this error: Traceback (most recent call last): File "C:\E1B8\ScriptTesting\MISC\Tool\makeaddin.py", line 5, in <module> current_path = os.path.dirname(os.path.abspath(__file__)) NameError: name '__file__' is not defined Should __file__ been replaced with a path, and somehow that didn't happen for me? If so, can I add it manually just to make things easy on myself? makeaddin.py: import os import re import zipfile current_path = os.path.dirname(os.path.abspath(__file__)) out_zip_name = os.path.join(current_path, os.path.basename(current_path) + ".esriaddin") BACKUP_FILE_PATTERN = re.compile(".*_addin_[0-9]+[.]py$", re.IGNORECASE) def looks_like_a_backup(filename): return bool(BACKUP_FILE_PATTERN.match(filename)) with zipfile.ZipFile(out_zip_name, 'w', zipfile.ZIP_DEFLATED) as zip_file: for filename in ('config.xml', 'README.txt', 'makeaddin.py'): zip_file.write(os.path.join(current_path, filename), filename) dirs_to_add = ['Images', 'Install'] for directory in dirs_to_add: for (path, dirs, files) in os.walk(os.path.join(current_path, directory)): archive_path = os.path.relpath(path, current_path) found_file = False for file in (f for f in files if not looks_like_a_backup(f)): archive_file = os.path.join(archive_path, file) print archive_file zip_file.write(os.path.join(path, file), archive_file) found_file = True if not found_file: zip_file.writestr(os.path.join(archive_path, 'placeholder.txt'), "(Empty directory)") The script I'm trying to turn into a button (at this stage, Tool_addin.py): import arcpy import pythonaddins def selecttoDQ(): #do things## #################### class ListLayers(object): """Implementation for Tool_addin.btn1 (Button)""" def __init__(self): self.enabled = True self.checked = False def onClick(self): selecttoDQ() Thanks!
... View more
03-03-2014
10:09 AM
|
0
|
3
|
593
|
POST
|
Update: I found a work-around for this. I'm lucky in that the field that is automatically chosen as the display field (in my case, "Name") does not actually contain any useful data. Thus I can calculate this field with what I want for the KMZ. Worth noting is that I initially tried deleting the "Name" field and adding a new field that ArcMap would select as the display field. My desired field is called "P6_NBR", so I instead went with it "NAMEP6_NBR". ArcMap looks for a field with the word "Name" in it to use as its default display field. This did not work however for the KMZ creation. Even though when I check the layer's display field post-script running it shows "NAMEP6_NBR", for whatever reason the KMZ created by my script does not use this field and instead shows [no name] or something like that.
... View more
02-25-2014
09:44 AM
|
0
|
0
|
283
|
IDEA
|
-->
I would like to see the ability to set a layer's display expression using arcpy. A big part of my job is creating KMZs, and setting a layer's display expression before converting to KMZ is vital. I have to do this manually since it is not currently supported with arcpy. This means producing KMZs is not scaleable to the degree that would suit my work best. Please consider this for future arcpy releases. Thanks!
... View more
02-20-2014
04:17 PM
|
16
|
3
|
1396
|
POST
|
I'm working on a script that creates KMLs. It would be nice if it could set the display expression. After a little digging I came across a post that stated setting a layer's display expression is not yet supported by arcpy. Does anyone know if this is (still) true? Thanks!
... View more
01-22-2014
11:18 AM
|
0
|
2
|
825
|
POST
|
I'm trying to remove a layer from my map. this code: arcpy.AddMessage(str(arcpy.mapping.ListLayers (mxd, "", df)))
arcpy.AddMessage(addstru)
arcpy.mapping.RemoveLayer (df, addstru)
arcpy.AddMessage(str(arcpy.mapping.ListLayers (mxd, "", df))) gets me this result: [<map layer u'StruxPts_v04'>, <map layer u'Land_Projects_Parcels_P6'>] StruxPts_v04 [<map layer u'StruxPts_v04'>, <map layer u'Land_Projects_Parcels_P6'>] As you can see, the layer 'StruxPts_v04' was not removed. When does this sort of thing occur? Thanks! EDIT: I'm thinking it has something to do with my searchcursor. addstru is searched, but I delete the cursor's variables prior to the code above.
... View more
01-18-2014
01:25 PM
|
0
|
1
|
2768
|
POST
|
Thanks for the tips guys. I fumbled through it and got it to work with this: fms = arcpy.FieldMappings() POINTGUIDt = arcpy.FieldMap () POINTGUIDt.addInputField(thePoint, "POINTGUIDt") fms.addFieldMap(POINTGUIDt) S_FILE = arcpy.FieldMap () S_FILE.addInputField(thePoint, "S_FILE") fms.addFieldMap(S_FILE) LINE_NBR = arcpy.FieldMap () LINE_NBR.addInputField(thePoint, "LINE_NBR") fms.addFieldMap(LINE_NBR) arcpy.FeatureClassToFeatureClass_conversion (thePoint, outDatabase, "PPMD_04V1i_" + envelopePolyTrim,"",fms) I'm not sure if it's the prettiest way to do it but it worked! Thanks again.
... View more
12-16-2013
08:57 AM
|
0
|
0
|
973
|
POST
|
Greetings, I am using FeatureClassToFeatureClass_conversion to export a new feature based on a selection. I would only like to carry over certain fields. Is this something that can be done? It looks like it is done through the FieldMap parameter but I have never worked with FieldMap objects... EDIT: I've written this... fieldmappings = arcpy.FieldMap () fieldmappings.addInputField(thePoint, "POINTGUIDt") fieldmappings.addInputField(thePoint, "S_FILE") fieldmappings.addInputField(thePoint, "LINE_NBR") then try to use it here: arcpy.FeatureClassToFeatureClass_conversion (thePoint, outDatabase, "PPMD_04V1i_" + envelopePolyTrim,"",fieldmappings) and get this: Traceback (most recent call last): File "C:\E1B8\ScriptTesting\SelectbyAttributeAndExport\Actual\ActualSelectbyAttributeAndExport.py", line 61, in <module> arcpy.FeatureClassToFeatureClass_conversion (thePoint, outDatabase, "PPMD_04V1i_" + envelopePolyTrim,"",fieldmappings) File "c:\program files (x86)\arcgis\desktop10.1\arcpy\arcpy\conversion.py", line 1547, in FeatureClassToFeatureClass raise e RuntimeError: Object: Error in executing tool Am I close? Thanks 🙂
... View more
12-13-2013
01:05 PM
|
0
|
3
|
3087
|
POST
|
I am trying to select features that have duplicate values in an attribute. I found this: http://forums.arcgis.com/threads/82221-Identical-values-in-a-field?highlight=select+duplicate But when I run the python tool I get: File "C:\E1B8\IM_Reconciliation\Toolbox.tbx#SelectDuplicates.py", line 31, in <module> NameError: name 'SelectPoly' is not defined Any help? Much thanks!
... View more
12-05-2013
01:23 PM
|
0
|
3
|
557
|
POST
|
Ah, I knew it would be something obvious. Thanks for the help guys!
... View more
11-25-2013
06:05 AM
|
0
|
0
|
523
|
POST
|
I am simply trying to create a list of all the features within a geodatabase. It seems easy enough, but here is what happens with my script: >>> import arcpy
>>> from arcpy import env
>>> arcpy.env.workspace = "C:\E1B8\Grid_Create_Update_11-2013\CalcMiles.gdb"
>>> datasetList = arcpy.ListDatasets("*", "Feature")
>>> len(datasetList)
0
My geodatabase contains various features, but as you can see my code creates an empty list. What am I missing? Thanks!
... View more
11-25-2013
05:51 AM
|
0
|
4
|
1955
|
POST
|
Greetings, I would like to incorperate some dynamic text into a defintion query. I am working with data driven pages based off of a cities layer. I would only like to display the boundary of the main city for each page. Inserting dynamic text into the layout is easy enough, but can I also insert the same dynamic text into a definition query? How do I need to change the syntax? For example, dynamic text used for map text: <dyn type="page" property="name"/> Can this be translated into SQL for the definition query? Thanks! EDIT: Solved with this page: http://help.arcgis.com/en/arcgisdesktop/10.0/help/index.html#//00sr00000004000000
... View more
11-22-2013
09:25 AM
|
1
|
1
|
3650
|
POST
|
Greetings, I would like to incorperate some dynamic text into a defintion query. I am working with data driven pages based off a cities layer. I would only like to display the boundary of the main city for each page. Inserting dynamic text into the layout is easy enough, but can I also insert the same dynamic text into a definition query? How do I need to change the syntax? For example, dynamic text used for map text: <dyn type="page" property="name"/> Can this be translated into SQL for the definition query? Thanks!
... View more
11-22-2013
06:37 AM
|
0
|
0
|
644
|
POST
|
How about something like this: Note that if you want the "first" city to trump subsequent ones (in the case of overlap), you would want to sort the cityFC search cursor by OID in decending order (by default the sort order is by OID in ascending order). Thanks CS, I shall study this code to see if I get it, if I can't get my current code working. I am getting the current error: ExecuteError: ERROR 999999: Error executing function. An invalid SQL statement was used. An invalid SQL statement was used. Apparently for this line: arcpy.SelectLayerByLocation_management("cityGridsLyr", "INTERSECT", "thecity", "", "NEW_SELECTION") Which doesn't make much sense to me since that line does not contain SQL. Am I missing something? import arcpy
from arcpy import env
arcpy.env.workspace = "C:\E1B8\Grid_Create_Update_11-2013"
# Create the search cursor
#
tablecur = arcpy.SearchCursor("SampleCityTable.dbf")
for row in tablecur:
cityname = row.City
clause = "\"'NAME10' = " + cityname + '"'
arcpy.AddMessage (clause)
arcpy.AddMessage (cityname)
# Make new feature for current city
arcpy.MakeFeatureLayer_management("state_places.shp","thecity",clause)
# Create layer for selection
arcpy.MakeFeatureLayer_management("CityGrids.shp", "cityGridsLyr")
# Select grid that intersect with new feature
arcpy.SelectLayerByLocation_management("cityGridsLyr", "INTERSECT", "thecity", "", "NEW_SELECTION")
# Update field in grid layer with city name
arcpy.CalculateField_management("cityGridsLyr", "CITY_GRID", cityname, "PYTHON", "")
# Remove selection from grid
arcpy.SelectLayerByAttribute_management("cityGridsLyr", "CLEAR_SELECTION", "")
# Delete newly made city layer
arcpy.Delete_management("thecity", "")
arcpy.Delete_management("cityGridsLyr", "")
... View more
11-19-2013
01:58 PM
|
0
|
0
|
961
|
POST
|
What if one of your grid cells has multiple cities within it? Then the first city in the list takes precedent. I was going to incorperate this aspect into my code (with an if statement) once I got everything else working.
... View more
11-19-2013
09:36 AM
|
0
|
0
|
961
|
Title | Kudos | Posted |
---|---|---|
16 | 02-20-2014 04:17 PM | |
1 | 11-22-2013 09:25 AM | |
2 | 11-25-2014 10:58 AM | |
1 | 08-08-2014 01:24 PM | |
1 | 08-08-2014 09:42 AM |
Online Status |
Offline
|
Date Last Visited |
11-11-2020
02:24 AM
|