Have created a script and a batch file to run the process automatically.
Pywin opens the script does not"
Any help in getting it to open and execute would be appreciated.
Batch file as follows
C:\Python27\ArcGIS10.6\Lib\site-packages\pythonwin\Pythonwin.exe
C:\Users\jstout\Desktop\PY\MorningProcess\morningprocess.py
Timeout 15
Script as follows
import arcpy, arceditor, time, smtplib
# Set the workspace
arcpy.env.workspace = r'C:\Users\jstout\AppData\Roaming\ESRI\Desktop10.6\ArcCatalog\EED_FM@SDE.sde'
# Set a variable for the workspace
adminConn = arcpy.env.workspace
database = "Database Connections/toolboxDEFAULTVersion.sde"
versions = arcpy.ListVersions(adminConn)
# Print the versions available to the user
for version in versions:
print(version)
print "Version list complete."
# Execute the ReconcileVersions tool.
# Use a list comprehension to get a list of version names where the owner
# is the current user and make sure sde.default is not selected.
print 'Reconcile versions started.'
verList = [ver.name for ver in arcpy.da.ListVersions() if ver.isOwner
== True and ver.name.lower() != 'sde.EFAULT']
arcpy.ReconcileVersions_management(adminConn, "ALL_VERSIONS", "SDE.DEFAULT", "", "LOCK_ACQUIRED", "NO_ABORT", "BY_OBJECT", "FAVOR_TARGET_VERSION", "POST","DELETE_VERSION")
# Write messages to a Text File
txtFile = open("c:\\temp\\GPMessages.txt","w")
txtFile.write (arcpy.GetMessages())
txtFile.close()
print ('see error log at "c:\temp\GPMessages.txt"')
print'Reconciling Complete'
# Run the compress tool.
print("Running compress")
arcpy.Compress_management(adminConn)
# Use a connection file to create the connection
print "Check state ID"
egdb = r'C:\Users\jstout\AppData\Roaming\ESRI\Desktop10.6\ArcCatalog\EED_FM@SDE.sde'
egdb_conn = arcpy.ArcSDESQLExecute(egdb)
table_name = 'EED_FM.sde.sde_States'
field_name = 'state_id'
sql = '''
SELECT {0}, COUNT({0}) AS f_count FROM {1}
GROUP BY {0}
ORDER BY f_count DESC
'''.format(field_name, table_name)
egdb_return = egdb_conn.execute(sql)
for i in egdb_return:
print('{}: {}'.format(*i))
print "State count complete"
# Update statistics and indexes for the system tables
# Note: to use the "SYSTEM" option the user must be an geodatabase or database administrator.
# Rebuild indexes on the system tables
print("Rebuilding indexes on the system tables")
arcpy.RebuildIndexes_management(adminConn, "SYSTEM")
# Update statistics on the system tables
print("Updating statistics on the system tables")
arcpy.AnalyzeDatasets_management(adminConn, "SYSTEM")
print("Finished.")
Solved! Go to Solution.
Using 10.6 have none of these lines.
you still should have C:\Python27\ArcGIS10.6\Lib\site-packages
then open the Desktop10.6.pth with notepad
I am using 10.8 and got this
C:\Python27\ArcGIS10.8\Lib\site-packages\Desktop10.8.pth
Dominic:
Have this migrated this script to use ArcGIS Pro's version of python as compared to ArcMap's version of python?
Dominic:
I have tried this technique besides calling a custom bat file thru Windows Task Scheduler and the import arcpy call using python 3.x installed with Pro randomly crashes. As such this is not a reliable solution for my org.
I've never been able to get a scheduled task to execute properly from a desk top computer; only a server. These other responses sound like great suggestions.