Greetings All,
I have a folder containing various Layer files, Vector and Raster. Vector layers are connecting to SDE through Application Server Connect.
I want to write a script which help me identify Vector Layers from folder and change their connection from 'Application Server' type to 'Direct Connect'
Can you please help me with the best way i can change their connection type from 'Application Server' type to 'Direct Connect'
Environment: ArcGIS 10.1/10.3 Desktop, ArcSDE 10.1, RHEL 6, Oracle 11g
With Best Regards
-AS
Dear Abdullah
you can use the serviceProperties property of your layer files ( Layer—Help | ArcGIS for Desktop ) and, once selected the layers whose datasource you want to change, use the replaceDataSource method for modifing the datasource (e.g. to a new direct connect .sde file).
That makes sense?
Regards
Jesús de Diego
Alarcon,
Thanks for your input.
(Below code for mxd) serviceProperties is working fine with layers(not with broken data source) within .mxd. But as i have multiple layer files stored on disk. I would like to check the properties of .lyr files in folder and repair their data sources. Any suggestion is highly appreciated.
Thanks
import arcpy, os
mxd = arcpy.mapping.MapDocument(r"Path to mxd")
for lyr in arcpy.mapping.ListLayers(mxd):
if lyr.supports("SERVICEPROPERTIES"):
servProp = lyr.serviceProperties
print "Layer name:" + lyr.name
print "-----------------------------------------------------"
if lyr.serviceProperties["ServiceType"] != "SDE":
print "Service Type: " + servProp.get('ServiceType', 'N/A')
print " URL: " + servProp.get('URL', 'N/A')
print " Connection: " + servProp.get('Connection', 'N/A')
print " Server: " + servProp.get('Server', 'N/A')
print " Cache: " + str(servProp.get('Cache', 'N/A'))
print " User Name: " + servProp.get('UserName', 'N/A')
print " Password: " + servProp.get('Password', 'N/A')
print ""
else:
print "Service Type: " + servProp.get('ServiceType', 'N/A')
print " Database: " + servProp.get('Database', 'N/A')
print " Server: " + servProp.get('Server', 'N/A')
print " Service: " + servProp.get('Service', 'N/A')
print " Version: " + servProp.get('Version', 'N/A')
print " User name: " + servProp.get('UserName', 'N/A')
print " Authentication: " + servProp.get('AuthenticationMode', 'N/A')
print ""
del mxd
You an try using ListFiles. Take a look at the below example.
Regards
Jesus de Diego Alarcón
import os
import arcpy
arcpy.env.workspace = "c:/temp"
# Copy each file with a .csv extension to a dBASE file
for lyr_file in arcpy.ListFiles("*.lyr"😞
if lyr_file.supports("SERVICEPROPERTIES"):
......
......
Can you please share any working script, if any?
Thanks