|
POST
|
You could do it based on the directory the script is being run from using os.getcwd(), then just build the rest of your directory from there. The requirement would be that you have to run the script from the same starting folder location on each computer.
... View more
11-12-2015
08:55 AM
|
0
|
1
|
6373
|
|
POST
|
For our scheduled task python scripts, we have it send an email with all the printed debug information, including arcpy.GetMessages(). The script also creates an entry in a scheduled task log table we have in SDE (which is just a fancy way of using a file like Darren mentioned). This is kind of how we set up our scripts (minus the email part). # -*- coding: utf-8 -*-
# ---------------------------------------------------------------------------
# Reg_MView2.py
# Created on: 2015-11-02 17:30:22.00000
# (generated by ArcGIS/ModelBuilder)
# Description:
# ---------------------------------------------------------------------------
def main():
import arceditor # Set the necessary product code
import arcpy # Import arcpy module
import os
try:
# Local variables:
sdeConn = "Database Connections\\Connection to GISREF.sde"
Var1 = os.path.join(sdeConn, "GIS.MVIEW1")
Var2 = os.path.join(sdeConn, "GIS.MVIEW2")
Var3 = os.path.join(sdeConn, "GIS.MVIEW3")
# ....etc
# Process: Register with Geodatabase
for var in [Var1, Var2, Var3]:
print "Registering {}".format(var)
arcpy.RegisterWithGeodatabase_management(var)
print "Done\n"
print "Script completed"
except Exception as err:
# Write error message information
if err.message in arcpy.GetMessages(2):
## Write all of the messages returned by the last ArcPy tool
print arcpy.GetMessages()
else:
## Write non-ArcPy error message
print unicode(err).encode("utf-8")
finally:
# Cleanup
arcpy.ClearWorkspaceCache_management()
if __name__ == '__main__':
main()
... View more
11-06-2015
09:33 AM
|
0
|
0
|
2448
|
|
POST
|
Both suggestions from Rebecca and Luke are reasonable. I'm partial to Python because it is more customizable, but it also requires more coding knowledge. If you're not as comfortable coding Python, it might be easier for you to set everything up in Model Builder. If you want to dive head-first into a purely Python solution, you can start by looking up the arcpy documentation for each tool you plan to use. For example, the Float tool to convert each cell value of a raster into a floating-point representation. At the bottom of the page, they even give you examples of how to use the code.
... View more
11-06-2015
09:04 AM
|
0
|
0
|
2111
|
|
POST
|
Here's what I use for exporting to CSV. import arcpy
import csv
import os
# Environment variables
workingDir = r"C:\temp"
workingGDB = os.path.join(workingDir, "MyGeodatabase.gdb")
inputTable = os.path.join(workingGDB, "MyInputTable")
outputCSV = os.path.join(workingDir, "MyOutput.csv")
# Create CSV
with open(outputCSV, "w") as csvfile:
csvwriter = csv.writer(csvfile, delimiter=',', lineterminator='\n')
## Write field name header line
fields = ['FirstField','NextField','AndThirdExample']
csvwriter.writerow(fields)
## Write data rows
with arcpy.da.SearchCursor(inputTable, fields) as s_cursor:
for row in s_cursor:
csvwriter.writerow(row)
... View more
10-27-2015
04:50 PM
|
1
|
0
|
5243
|
|
POST
|
Here is the basic way I'm using the Editor for now until I find a better way. try:
edit = arcpy.da.Editor(sdeconnection)
print "edit created"
edit.startEditing()
print "edit started"
edit.startOperation()
print "operation started"
# Perform edits
with arcpy.da.InsertCursor(fc, fields) as fc_icursor:
fc_icursor.insertRow(someNewRow)
edit.stopOperation()
print "operation stopped"
edit.stopEditing(True) ## Stop the edit session with True to save the changes
print "edit stopped"
except Exception as err:
print err
if 'edit' in locals():
if edit.isEditing:
edit.stopOperation()
print "operation stopped in except"
edit.stopEditing(False) ## Stop the edit session with False to abandon the changes
print "edit stopped in except"
finally:
# Cleanup
arcpy.ClearWorkspaceCache_management()
... View more
10-16-2015
12:17 PM
|
4
|
2
|
11776
|
|
POST
|
Using topology would be my suggestion too; it's made to enforce rules you have with how your data should interact. More generally though, you can use the Clip command from the Editor menu to accomplish what you describe. ArcGIS Help 10.2 - Clipping a polygon feature
... View more
10-06-2015
04:01 PM
|
1
|
0
|
1342
|
|
POST
|
Are all of your feature classes in the same schema?
... View more
10-05-2015
08:42 AM
|
0
|
1
|
3076
|
|
POST
|
Do you actually have a domain created in your geodatabase that is for a Long Integer field type? I was able to replicate this issue from a quick test on a file geodatabase. Once I created a domain with a Long Int field type, I was able to assign it to the Long Int field.
... View more
10-02-2015
12:42 PM
|
1
|
1
|
1592
|
|
POST
|
I've been doing [email protected] but I'd like to know what "standards" everyone else uses. Geodatabase
... View more
10-02-2015
12:37 PM
|
0
|
3
|
3271
|
|
POST
|
Side topic: I'm interested in seeing your code for the edit session. Is it arcpy.da.Editor?
... View more
09-29-2015
04:57 PM
|
0
|
0
|
2002
|
|
POST
|
When using TableToTable_conversion() from Excel to GDB, you need to specify the sheet name suffixed with a $. Something like C:/temp/MyExcelFile.xlsx/mySheetName$ Using the Esri code samples in the Excel To Table link provided by Rebecca Strauch, GISP, you can use the xlrd module for reading the sheets in an Excel file. import os
import xlrd
import arcpy
def main():
# Local variables
in_excel = r"C:\temp\MyExcelFile.xlsx"
out_gdb = r"C:\temp\MyGeodatabase.gdb"
# Read Sheets in Excel Workbook
with xlrd.open_workbook(in_excel) as workbook:
sheets = [sheet.name for sheet in workbook.sheets()]
# Export each sheet to geodatabase table
for sheet in sheets:
in_rows = os.path.join(in_excel,str(sheet)+"$")
## The out_name is based on the input excel file name
## an underscore (_) separator followed by the sheet name
baseName = os.path.basename(in_excel)
out_name = arcpy.ValidateTableName(
"{0}_{1}".format(os.path.splitext(baseName)[0], sheet),
out_gdb
)
arcpy.TableToTable_conversion(in_rows, out_gdb, out_name,)
print arcpy.GetMessages(), "\n"
if __name__ == '__main__':
main()
... View more
09-25-2015
09:33 AM
|
1
|
0
|
1256
|
|
POST
|
You may need to enable editing on the layer. If you still have trouble, maybe try using a file geodatabase instead of a Shapefile. Considerations for adding Shapefiles—ArcGIS Online Help
... View more
09-21-2015
12:06 PM
|
0
|
0
|
2793
|
|
POST
|
Couldn't you just create the layer in ArcGIS online and have them edit it in ArcGIS Online? They could even use the Collector app on their mobile device to make edits. What's the need to automate uploading the Shapefile? EDIT: You could also look into ArcREST.
... View more
09-21-2015
08:43 AM
|
0
|
5
|
2793
|
| Title | Kudos | Posted |
|---|---|---|
| 1 | a week ago | |
| 1 | 10-23-2025 03:53 PM | |
| 1 | 04-28-2026 07:25 AM | |
| 1 | 03-19-2026 08:59 AM | |
| 1 | 02-12-2026 01:37 PM |