2

I am having trouble retrieving the correct path to the current map layer dataSource path. I am using ArcGIS Desktop 10.2 (10.2.0.3348)

The workspace path that gets returned is correct apart from the current users name is not used but replaced by the owner of the Geodatabase Server. Which does not exist on the users machine and so returns empty dictionary on commands like arcpy.da.ListSubtypes(lyr.dataSource).

e.g.

mxd = arcpy.mapping.MapDocument('CURRENT')
df = arcpy.mapping.ListDataFrames(mxd)[0]
for lyr in arcpy.mapping.ListLayers(mxd, '*.Couplings'):
    print lyr.dataSource

Which returns;

C:\Users\<owner>\AppData\Roaming\ESRI\Desktop10.2\ArcCatalog\GWMAP_SQLEXPRESS.gds

What I expected would be;

C:\Users\<user>\AppData\Roaming\ESRI\Desktop10.2\ArcCatalog\GWMAP_SQLEXPRESS.gds

The user owner is the owner of the Geodatabase Server as listed in the Properties->Administration tab.

I have tried setting the default environment settings in ArcMap & ArcCatalog. Plus setting the arcpy.env.workspace to the correct path.

What am I doing wrong? Obviously I could easily use string replace to correct this but would prefer if there is a better approach.

1 Answer 1

1

If you want to get the current user you may use the getpass module as:

import getpass

userName = getpass.getuser()

This should return the current logged-in user domain name. You could then construct your path string as:

r'C:\Users\' + username + '\AppData\Roaming\ESRI\Desktop10.2\ArcCatalog\GWMAP_SQLEXPRESS.gds'

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.