Python labeling sde connection properties for template mxd

1493
2
05-04-2016 09:25 AM
PeterFinch1
New Contributor II

Hello

I am setting up some labeling in a template mxd that will be used by several people in my organization. The label info comes from related tables in an sde database so I am using a python labeling expression. In the expression I need to connect to sde in order to access the related table.  I have been successful getting this to work properly on my machine but when a coworker uses it, it fails because it is referencing the wrong connection.sde file.  I am using the code below thinking that it would pull the path to the sde connection file on the users machine, but it always returns the path of my connection.sde and not the users connection.

# Get database connection

mxd = arcpy.mapping.MapDocument("CURRENT")

layer = arcpy.Describe("Hydrants")

path = layer.dataElement.catalogPath

db_connection = os.path.split(path)[0]

Does anyone have any ideas on how to make the sde connection dynamic?

0 Kudos
2 Replies
MichaelVolz
Esteemed Contributor

Try creating your template with an SDE connection somewhere on your network that is accessible to both you and your co-workers.  Then the SDE connection should work for everyone and not always look at your local SDE connection file.

PeterFinch1
New Contributor II

Thanks works like a charm

0 Kudos